我正在使用 NPOI 将文件保存为 .xls 格式。
现在我想保存一个空文件,因为用户有一个对话框并被提示将其保存在本地。
我的问题是我无法设置响应字段,因为
当前上下文中不存在名称“响应”。
这是我想使用的类:
https://docs.microsoft.com/en-us/dotnet/api/system.web.httpresponse?view=netframework-4.8
//Load all documents sorted by DocNumber and export them
var documents = await _ctx.Db.Documents
.AsNoTracking()
.OrderByDescending(d => d.Number)
.ToListAsync();
var workbook = new HSSFWorkbook();
var sheet = workbook.CreateSheet("Invoicing_Docs");
using (var exportData = new MemoryStream())
{
workbook.Write(exportData);
string saveAsFileName = string.Format("Invoicing_Docs-{0:d}.xls", DateTime.UtcNow).Replace("/", "-");
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
Response.Clear();
Response.BinaryWrite(exportData.GetBuffer());
Response.End();
}
我已经在项目中安装了 System.Web。
当我ctrl + .
响应时,我有 3 个选择:
这也是这篇文章,我正在关注:
https://steemit.com/utopian-io/@haig/how-to-create-excel-spreadsheets-using-npoi
我不需要这些。我究竟做错了什么?
我发现我需要做什么。
我没有使用控制器我正在编写一个在控制器中调用的服务。
我所要做的就是在服务的方法中注入响应。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句