日期:2014-05-17  浏览次数:20452 次

求如何导出EXCEL表,并保存在服务器上指定地址文件中。
我有一个导出EXCEL文件程序,是直接通过浏览器导出保存的。

本人想修改为保存为EXCEL文件形式,

请高手指点:

 '导出文件
  Response.Clear()
  Response.Buffer = True
  Response.Charset = "GB2312"
  Response.AppendHeader("Content-Disposition", "attachment;filename=" & Now & ".xls")
  Response.ContentEncoding = System.Text.Encoding.UTF8
  Response.ContentType = "application/ms-excel"
  Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
  Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
  Me.ex.RenderControl(oHtmlTextWriter)
  Response.Output.Write(oStringWriter.ToString)
  Response.Flush()
  Response.End()


谢谢

------解决方案--------------------
保存的话,你改成

Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
Me.ex.RenderControl(oHtmlTextWriter)
System.IO.WriteAllText(Server.MapPath("~/xx.xls"),oStringWriter.ToString)