当我尝试打开由下面的代码创建的 test.xlsx 时,我得到“无法下载 test.xlsx”。也就是说,如果我选择保存文件,我可以很好地保存和打开文件。
请让我知道我做错了什么。
谢谢!
Dim pack As New ExcelPackage
Dim ws As ExcelWorksheet = pack.Workbook.Worksheets.Add("Sheet1")
Dim ms As New MemoryStream
Dim dt As New DataTable
ws.Cells(1, 1).Value = "Test"
pack.SaveAs(ms)
ms.WriteTo(Context.Response.OutputStream)
Context.Response.Clear()
Context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Context.Response.AddHeader("Content-Disposition", "attachment;filename=test.xlsx")
Context.Response.StatusCode = 200
Context.Response.End()