【发布时间】:2014-11-07 03:20:08
【问题描述】:
我正在使用第三方库,其中一种方法返回FileStreamResult。
public FileStreamResult GenerateFile(OutFormat format, dynamic params);
我的控制器中的一个动作调用了这个方法:
public ActionResult GenerateExcel()
{
Utils.XCore core = new Utils.XCore(...); // where ... are contructor params
// ... other codes here ...
return core.GenerateFile(OutFormat.EXCEL, new { FileName = "Report" });
}
这会很好,但有时我想将多个 Excel 工作表合并为一个,就像这样:
public ActionResult GenerateExcel()
{
Utils.XCore core = new Utils.XCore(...); // where ... are contructor params
// ... other codes here ...
var excel1 = core.GenerateFile(OutFormat.EXCEL, new { FileName = "rpt1" });
var excel2 = core.GenerateFile(OutFormat.EXCEL, new { FileName = "rpt2" });
var excel3 = core.GenerateFile(OutFormat.EXCEL, new { FileName = "rpt3" });
var finalContent = combineFile(excel1, excel2, excel3);
return new FileStreamResult(finalContent, "application/ms-excel")
{
FileDownloadName = "Report.xls"
};
}
我现在的问题是我不知道如何从FileStreamResult 获取内容。关于如何做的任何想法?甚至包含网络链接的 cmets 也非常受欢迎。谢谢!
【问题讨论】:
-
在使用它来保存/提示用户之前,您需要重置流的搜索来源:stackoverflow.com/questions/1121703/…
-
@Papa 我没有任何内存流对象。
标签: c# asp.net-mvc