Home > Software engineering >  VB.NET is created and download Excel;
VB.NET is created and download Excel;

Time:10-25

Private Sub PrintExcel ()
Dim time As String=DateTime. Now. ToString (" yyyyMMddHHmmss ")

Dim xlApp. As Microsoft Office. Interop. Excel. Application
Dim xlBook. As Microsoft Office. Interop. Excel. The Workbook
Dim xlSheet. As Microsoft Office. Interop. Excel. The Worksheet

XlApp=CreateObject (" Excel. Application ")
XlBook=xlApp. Workbooks. Add
XlSheet=xlBook. Worksheets (1)
XlSheet. Activate ()

XlBook. SaveAs (Server. MapPath (" \ TmpReport \ TMP "& amp; Time & amp; "1. XLS"))

XlBook. Close ()
XlApp. Quit ()

XlApp=Nothing
XlBook=Nothing
XlSheet=Nothing

The Response. The Expires=0
The Response. The Clear ()
The Response. The Buffer=True
The Response. The Charset="utf-8"
'Response. ContentEncoding=System. Text. Encoding. The UTF8
Response. ContentEncoding=System. Text. Encoding. Unicode
Response. The ContentType="application/VND. Ms - excel"
The Response. AddHeader (" the Content - the Disposition ", "legislation; Filename="& amp; HttpUtility. UrlEncode (time & amp; ". XLS "))
Response. WriteFile (Server. MapPath (" \ TmpReport \ TMP "& amp; Time & amp; "1. XLS"))
The Response. The Flush ()
The Response. The Clear ()
End Sub

WEB access, use the above code generation empty Excel, then prompt to download!
Preserved Excel with HTML code, should be to generate Excel the HTML page itself,
Is there a way to solve! O give advice or comments!!!!!
  • Related