ASP.NETでWebページから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()
ありがとう