关于EXCEL的问题,大侠请进来拿分!

super_paladin 2005-09-27 10:47:19
在生成WEB表格的同时(表格比较复杂,不能根据坐标输出),生成一个相同内容的excel文件,保存在服务器端,用户根据需要下载excel格式的文件。
...全文
105 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
super_paladin 2005-09-29
  • 打赏
  • 举报
回复
楼上的有具体的例子吗,我不知道怎样把要输出的table内容存入到一个变量中.如果要输出的内容太多,会造成溢出吗?
HHH3000 2005-09-27
  • 打赏
  • 举报
回复
非常简单,在生成报表的同时,把报表的html(table内容)写入一个变量,

然后用fso把它写入一个文件,后缀改成xls,记录下文件地址,

这时用户点击下载,就连接到这个文件地址就可以了。
尚和空四 2005-09-27
  • 打赏
  • 举报
回复
一个完整的例子 仔细研究 研究
尚和空四 2005-09-27
  • 打赏
  • 举报
回复
ReportFile = ReportFile & ".xls"

' Start Excel and get Application object.
Set oXL = server.createobject("excel.application")
' oXL.Visible = True

' Get a new workbook.
Set oWB = oXL.Workbooks.Add
Set oSheet = oWB.ActiveSheet

'ActiveWorkbook.Sheets("Sheet1").Select
Set oSheet = oWB.ActiveSheet
oSheet.Activate
'------------------------------------------------------
'------------- column align,font,size--
'xlHAlignLeft(-4131) xlHAlignRight(-4152) xlHAlignCenter(-4108) xlVAlignCenter(-4108)
oSheet.Columns.Font.Name = "Verdana"
oSheet.Columns(1).ColumnWidth = 15
oSheet.Columns(1).HorizontalAlignment = -4131
oSheet.Columns(1).Font.Size = 9
oSheet.Columns(2).ColumnWidth = 15
oSheet.Columns(2).HorizontalAlignment = -4131
oSheet.Columns(2).Font.Size = 9
oSheet.Columns(3).HorizontalAlignment = -4131
oSheet.Columns(3).Font.Size = 9
oSheet.Columns(4).ColumnWidth = 35
oSheet.Columns(4).HorizontalAlignment = -4131
oSheet.Columns(4).Font.Size = 9
oSheet.Columns(5).ColumnWidth = 20
oSheet.Columns(5).HorizontalAlignment = -4131
oSheet.Columns(5).Font.Size = 9
oSheet.Columns(6).ColumnWidth = 20
oSheet.Columns(6).HorizontalAlignment = -4131
oSheet.Columns(6).Font.Size = 9
'--------------------------------

oSheet.Name = "Weekly Report of " & reporter

intLine = 1
oSheet.Range("A" & intLine, "G" & intLine).Merge
oSheet.Cells(intLine, 1).HorizontalAlignment = -4108
oSheet.Cells(intLine, 1).Font.Size = 10
oSheet.Cells(intLine, 1).Font.Bold = True
oSheet.Cells(intLine, 1).Font.Underline = True
oSheet.Cells(intLine, 1).Font.Background = 1
oSheet.Cells(intLine, 1).Value = "Weekly Report of " & reporter & " (" & weekstartdate & "-" & weekenddate & ")"


intLine = 3
'----------------------------------------------------------------------------------------
oSheet.Range("A" & intLine, "F" & intLine).Merge

oSheet.Cells(intLine, 1).HorizontalAlignment = -4131
oSheet.Cells(intLine, 1).Font.Size = 10
oSheet.Cells(intLine, 1).Font.Bold = True
oSheet.Cells(intLine, 1).Font.Underline = True
oSheet.Cells(intLine, 1).Font.Background = 1
oSheet.Cells(intLine, 1).Interior.color = rgb(207,216,236)
oSheet.Cells(intLine, 1).Value = "Jobs have been done in this week"

intLine = intLine + 1
oSheet.Cells(intLine, 1).Value = "Job Name."
oSheet.Cells(intLine, 2).Value = "Progress"
oSheet.Cells(intLine, 3).Value = "Status"
oSheet.Cells(intLine, 4).Value = "Desc."
oSheet.Cells(intLine, 5).Value = "Actual Start/Finish Date"
oSheet.Cells(intLine, 6).Value = "Related Project"

With oSheet.Range("A" & intLine, "G" & intLine)
.Font.Bold = True
.VerticalAlignment = -4108
.HorizontalAlignment = -4108
.Font.Name = "Verdana"
.Font.Size = 9
.Font.Color = 4
End With

intLine = intLine + 1
'oSheet.Rows(1).Height = 100

oSheet.Columns(1).NumberFormat = "#"
While Not rs1.EOF
a7(0)=trim(rs1("itemname"))
a7(1)=trim(rs1("progress")) & "%"
a7(2)=getsysparam("jobstatus",trim(rs1("status")))
a7(3)=replace(trim(rs1("remark")),chr(13),"")
a7(4)=getdatestyle(trim(rs1("astartdate")),trim(rs1("aenddate")))
a7(5)=getproject(trim(rs1("jitemid")))

oSheet.Cells(intLine, 1).Value = a7(0)
oSheet.Cells(intLine, 2).Value = a7(1)
oSheet.Cells(intLine, 3).Value = a7(2)
oSheet.Cells(intLine, 4).Value = a7(3)
oSheet.Cells(intLine, 5).Value = a7(4)
oSheet.Cells(intLine, 6).Value = a7(5)

intLine = intLine + 1
rs1.MoveNext
Wend
rs1.Close
Set rs1 = Nothing
'-----------------------------------------------------------------

'----------------------------------------------------------------------------------------
intLine = intLine + 1
oSheet.Range("A" & intLine, "F" & intLine).Merge

oSheet.Cells(intLine, 1).HorizontalAlignment = -4131
oSheet.Cells(intLine, 1).Font.Size = 10
oSheet.Cells(intLine, 1).Font.Bold = True
oSheet.Cells(intLine, 1).Font.Underline = True
oSheet.Cells(intLine, 1).Font.Background = 1
oSheet.Cells(intLine, 1).Interior.color = rgb(207,216,236)
oSheet.Cells(intLine, 1).Value = "Jobs planned for next week"

intLine = intLine + 1
oSheet.Cells(intLine, 1).Value = "Job Name."
oSheet.Cells(intLine, 2).Value = "Progress"
oSheet.Cells(intLine, 3).Value = "Status"
oSheet.Cells(intLine, 4).Value = "Desc."
'oSheet.Cells(intLine, 5).Value = "Actual Start/Finish Date"
oSheet.Cells(intLine, 5).Value = "Related Project"

With oSheet.Range("A" & intLine, "F" & intLine)
.Font.Bold = True
.VerticalAlignment = -4108
.HorizontalAlignment = -4108
.Font.Name = "Verdana"
.Font.Size = 9
.Font.Color = 4
End With

intLine = intLine + 1
'oSheet.Rows(1).Height = 100

oSheet.Columns(1).NumberFormat = "#"
While Not rs2.EOF
a7(0)=trim(rs2("itemname"))
a7(1)=trim(rs2("progress")) & "%"
a7(2)=getsysparam("jobstatus",trim(rs2("status")))
a7(3)=replace(trim(rs2("remark")) ,chr(13),"")
a7(4)=getdatestyle(trim(rs2("astartdate")),trim(rs2("aenddate")))
a7(5)=getproject(trim(rs2("jitemid")))

oSheet.Cells(intLine, 1).Value = a7(0)
oSheet.Cells(intLine, 2).Value = a7(1)
oSheet.Cells(intLine, 3).Value = a7(2)
oSheet.Cells(intLine, 4).Value = a7(3)
'oSheet.Cells(intLine, 5).Value = a7(4)
oSheet.Cells(intLine, 5).Value = a7(5)

intLine = intLine + 1
rs2.MoveNext
Wend
rs2.Close
Set rs2 = Nothing
'-----------------------------------------------------------------

'----------------------------------------------------------------------------------------
intLine = intLine + 1
oSheet.Range("A" & intLine, "F" & intLine).Merge

oSheet.Cells(intLine, 1).HorizontalAlignment = -4131
oSheet.Cells(intLine, 1).Font.Size = 10
oSheet.Cells(intLine, 1).Font.Bold = True
oSheet.Cells(intLine, 1).Font.Underline = True
oSheet.Cells(intLine, 1).Font.Background = 1
oSheet.Cells(intLine, 1).Interior.color = rgb(207,216,236)
oSheet.Cells(intLine, 1).Value = "Issues"

intLine = intLine + 1
oSheet.Cells(intLine, 1).Value = "Issue Name."
oSheet.Cells(intLine, 2).Value = "Report Date"
oSheet.Cells(intLine, 3).Value = "Status"
oSheet.Cells(intLine, 4).Value = "Desc."
oSheet.Cells(intLine, 5).Value = "Owerner"
oSheet.Cells(intLine, 6).Value = "Assign to"

With oSheet.Range("A" & intLine, "G" & intLine)
.Font.Bold = True
.VerticalAlignment = -4108
.HorizontalAlignment = -4108
.Font.Name = "Verdana"
.Font.Size = 9
.Font.Color = 4
End With

intLine = intLine + 1
'oSheet.Rows(1).Height = 100

oSheet.Columns(1).NumberFormat = "#"
While Not rs3.EOF
a7(0)=trim(rs3("issuename"))
a7(1)=trim(rs3("reportdate"))
a7(2)=getsysparam("issuestatus",trim(rs3("complete")))
a7(3)=replace(trim(rs3("issuedesc")) ,chr(13),"")
a7(4)=trim(rs3("empname"))
a7(5)=getassign(trim(rs3("issueid")))

oSheet.Cells(intLine, 1).Value = a7(0)
oSheet.Cells(intLine, 2).Value = a7(1)
oSheet.Cells(intLine, 3).Value = a7(2)
oSheet.Cells(intLine, 4).Value = a7(3)
oSheet.Cells(intLine, 5).Value = a7(4)
oSheet.Cells(intLine, 6).Value = a7(5)

intLine = intLine + 1
rs3.MoveNext
Wend
rs3.Close
Set rs3 = Nothing
'-----------------------------------------------------------------

oWB.SaveAs server.MapPath("excelfile") & "\" & ReportFile
'intLine = 0
Set oRng = Nothing
Set oSheet = Nothing
Set oSheetOther = Nothing
oWB.Close
Set oWB = Nothing
Set oXL = Nothing
response.redirect "excelfile/" & ReportFile
尚和空四 2005-09-27
  • 打赏
  • 举报
回复
沙发

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧