有了这个,我可以在本地目录下载一个excel文件,但我想在浏览器的本地目录中下载该文件。
return _obituaryModel.find(carId)
答案 0 :(得分:0)
您可以使用MVC文件结果返回文件名,如下例所示:
public ActionResult DownloadExcelFile() {
string fileName = @"D:\NewFolder\Test.xlsx";
oWB.SaveAs(fileName, XlFileFormat.xlOpenXMLWorkbook, missing, missing, missing, missing, XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
oWB.Close(missing, missing, missing);
oXL.UserControl = true;
oXL.Quit();
return File(fileName, "application/vnd.ms-excel", "file.xls");
}
答案 1 :(得分:0)
如果要下载物理文件,请将FilePathResult用于MVC控制器
public FilePathResult DownloadExcelFile()
{
var filePath = Server.MapPath("~/MyFiles/test.xls");
return File(filePath, "application/xls", "FileName");
}