我想从 ASP.NET 中的网页创建一个 excel 文件,我正在使用 Microsoft.Office.Interop.Excel 库,但我无法删除在服务器端创建的文件,因为我进入了与时俱进的麻烦。我想知道是否有一种方法可以使用例如数据库的数据创建一个 Excel 文件,然后客户端可以下载该文件而不会使服务器饱和。
实际上,在服务器中创建文件后,我在 VB 中使用此代码,但它不像我想要的那样工作:
Dim p As Process = New Process()
p.StartInfo = New ProcessStartInfo()
p.StartInfo.UseShellExecute = True
p.StartInfo.FileName = "taskkill.exe"
p.StartInfo.Arguments = "/F /IM EXCEL.exe"
p.Start()
p.WaitForExit()
Thread.Sleep(24)
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition", "attachment; filename=Reporte.xlsx")
Response.TransmitFile(Server.MapPath("~/Resources/" & HiddenField1.Value.ToString() & ".xlsx"))
'Thread.Sleep(10000)
'Dim fso, f2
'fso = CreateObject("Scripting.FileSystemObject")
'f2 = fso.GetFile(Server.MapPath("~/Resources/" & HiddenField1.Value.ToString() & ".xlsx"))
'f2.Delete()
'Thread.Sleep(24)
Response.End()
谢谢