【发布时间】:2013-02-22 09:57:36
【问题描述】:
我已经编写了这段代码,它将生成一个 Excel 电子表格并将其保存到指定位置。然后我想通过从存储位置读取文件然后询问用户他们想要存储它的位置来显示一个“另存为”对话框。
Excel.Application excelApp = null;
Excel.Workbook wb = null;
Excel.Worksheet ws = null;
Excel.Range range = null;
excelApp = new Excel.Application();
wb = excelApp.Workbooks.Add();
ws = wb.Worksheets.get_Item(1) as Excel.Worksheet;
for(int i = 0; i< 10;++i) {
ws.Cells[i, 1] = i+
}
wb.SaveAs(@"C:\test.xls", Excel.XlFileFormat.xlWorkbookNormal);
wb.Close(true);
excelApp.Quit();
以下格式如何下载?
string str = "Hello, world";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
return File(bytes, "text/plain");
【问题讨论】:
-
请阅读 this question 以讨论要使用的正确 MIME 类型 -
text/plain不适用于 Excel 文档。
标签: asp.net