VB.NET創建并下載Excel;
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.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets(1)
xlSheet.Activate()
xlBook.SaveAs(Server.MapPath("\TmpReport\tmp" & time & "1.xls"))
xlBook.Close()
xlApp.Quit()
xlApp = Nothing
xlBook = Nothing
xlSheet = Nothing
Response.Expires = 0
Response.Clear()
Response.Buffer = True
Response.Charset = "utf-8"
'Response.ContentEncoding = System.Text.Encoding.UTF8
Response.ContentEncoding = System.Text.Encoding.Unicode
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment; filename=" & HttpUtility.UrlEncode(time & ".xls"))
Response.WriteFile(Server.MapPath("\TmpReport\tmp" & time & "1.xls"))
Response.Flush()
Response.Clear()
End Sub
WEB訪問,使用上面代易做图生成空Excel、然後提示下載!
保存下來的Excel有HTML代易做图、應該是生成Excel頁面本身的HTML,
有什麽辦法解決!求指教!! VB Excel
补充:VB , 网络编程