无法使用 HTTP 响应
Cannot use HTTP Response
我正在使用 NPOI 将文件保存为 .xls 格式。
我想暂时保存一个空文件,因为用户有一个对话框并提示在本地保存它。
我遇到的问题是无法设置响应字段,因为
The name 'Response' does not exist in the current context.
这是我要使用的 class:
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 个选择:
- 安装包 "IdentityMode"、
- 安装包"Selenium.WebDriver"
- 安装包"Swashbuckle.AspNetCore.Swagger"
也是这篇文章,我正在关注:
https://steemit.com/utopian-io/@haig/how-to-create-excel-spreadsheets-using-npoi
我不需要这些。我做错了什么?
我找到了我需要做的事情。
我没有使用控制器我正在编写一个在控制器中调用的服务。
我所要做的就是在服务的方法中注入 Response。
我正在使用 NPOI 将文件保存为 .xls 格式。
我想暂时保存一个空文件,因为用户有一个对话框并提示在本地保存它。
我遇到的问题是无法设置响应字段,因为
The name 'Response' does not exist in the current context.
这是我要使用的 class:
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 个选择:
- 安装包 "IdentityMode"、
- 安装包"Selenium.WebDriver"
- 安装包"Swashbuckle.AspNetCore.Swagger"
也是这篇文章,我正在关注:
https://steemit.com/utopian-io/@haig/how-to-create-excel-spreadsheets-using-npoi
我不需要这些。我做错了什么?
我找到了我需要做的事情。
我没有使用控制器我正在编写一个在控制器中调用的服务。
我所要做的就是在服务的方法中注入 Response。