gpt4 book ai didi

vb.net - 无法下载 test.xlsx - EPPlus

转载 作者:行者123 更新时间:2023-12-04 18:10:38 25 4
gpt4 key购买 nike

当我尝试打开由以下代码创建的 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()

最佳答案

下面的示例代码应该可以完成这项工作:

Using pkg = New ExcelPackage()
Dim ws = pkg.Workbook.Worksheets.Add("Sheet 1")
ws.Cells(1, 1).Value = "Hello"

Dim buf = pkg.GetAsByteArray()

Response.Clear()
Response.AddHeader("Content-Disposition", "attachment;filename=test.xlsx")
Response.ContentType = MimeMapping.GetMimeMapping("*.xlsx")
Response.BinaryWrite(buf)
Response.Flush()
Response.[End]()
End Using

关于vb.net - 无法下载 test.xlsx - EPPlus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13825610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com