我试图下载批量Excel数据,所以我使用server.mappath()保存文件,但问题是文件被下载到特定文件夹但我没有在浏览器中获取下载文件。那么如何在ASP.NET MVC中添加response.write
调用CreateExcelDocument方法:
string worksheet_name = "RetailerReport.xls";
string MyDocumentsPath = System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments);
CreateExcelFile.CreateExcelDocument(ds, MyDocumentsPath + "\\" + worksheet_name);
CreateExcelDocument方法:
public static bool CreateExcelDocument(DataSet ds, string excelFilename)
{
try
{
using (SpreadsheetDocument document = SpreadsheetDocument.Create(
excelFilename, SpreadsheetDocumentType.Workbook))
{
WriteExcelFile(ds, document);
}
Trace.WriteLine("Successfully created: " + excelFilename);
return true;
}
catch (Exception ex)
{
Trace.WriteLine("Failed, exception thrown: " + ex.Message);
return false;
}
}
创建excel文件后,我想添加response.write