如何在客户端保存Excel?

xu0007 2003-10-11 02:57:37
在服务器上生成了一个Excel,怎么在客户端保存,而不是在IE中显示出来?
...全文
81 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
whl9234 2003-10-12
  • 打赏
  • 举报
回复
up
yuanylong 2003-10-11
  • 打赏
  • 举报
回复
别人的例子:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
BindGrid()
End Sub
Private Sub BindGrid()
conn = New SqlConnection("Initial Catalog=Northwind;Data Source=127.0.0.1;uid=sa;pwd=sa")
sql = New SqlCommand("select * from products", conn)
conn.Open()
Dim reader As SqlDataReader
reader = sql.ExecuteReader()
DataGrid1.DataSource = reader
DataGrid1.DataBind()
reader.Close()
conn.Close()
End Sub
Private Sub WriteDataGrid2Excel()
Dim xlsheet As New SpreadsheetClass()
conn.Open()
Dim reader As SqlDataReader
reader = sql.ExecuteReader()
Dim numbercols As Int16
numbercols = reader.FieldCount
Dim row As Int16 = 1
Dim i As Int16
While reader.Read()
For i = 0 To numbercols - 1
xlsheet.ActiveSheet.Cells(row, i + 1) = reader.GetValue(i).ToString()
Next
row += 1
End While
reader.Close()
conn.Close()
'xlsheet.ActiveSheet.Export()
Try
xlsheet.ActiveSheet.Export(Server.MapPath(".") + "\wx.xls", OWC.SheetExportActionEnum.ssExportActionNone)
Catch e As Exception
Dim wx As String
wx = e.Message
End Try
Response.Redirect("wx.xls")

End Sub

Private Sub export2excel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles export2excel.Click
Dim xlApp, xlBook, XlSheet


xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.add
XlSheet = xlBook.Worksheets(1)
xlApp.Caption = "test表"
XlSheet.name = "test表"

XlSheet.Rows("1:1").RowHeight = 36.6
XlSheet.Range("A1").FormulaR1C1 = "test"
XlSheet.Range("A1").Font.Bold = True
XlSheet.Range("A1").Font.ColorIndex = 3
XlSheet.Range("A1").Font.Size = 16

xlApp.Visible = True

'xlApp = Nothing
'xlBook = Nothing
'XlSheet = Nothing
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WriteDataGrid2Excel()
End Sub
End Class

xu0007 2003-10-11
  • 打赏
  • 举报
回复
我是用Excel.Application生成的Excel

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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