答案 0 :(得分:0)
您不应在有时被视为解决方案的服务器上安装Excel。一种直接的方法是创建一个下载为csv文件。然后,它将在客户端计算机上的Excel中打开。以下方法说明如何执行此操作:
public ActionResult DownloadSelectedReport(int ReportID)
{
string filename = String.Format("DownloadList{0:yyMMdd}.csv", DateTime.Today);
MemoryStream memStream = new MemoryStream();
UnicodeEncoding uniEncoding = new UnicodeEncoding();
byte[] reportString = uniEncoding.GetBytes(BuildReportAsCSV(ReportID));
memStream.Write(reportString, 0, reportString.Length);
return File(memStream.ToArray(), "application/vnd.ms-excel", Server.UrlEncode(filename));
}
使用BuildReportAsCSV(ReportID)
生成报告以供下载。