[英]Export data to Excel template c#
You should not install Excel on the server which is sometimes seen as a solution. 您不应该在有时被视为解决方案的服务器上安装Excel。 One straightforward way is to create a download as a csv file.
一种简单的方法是将下载文件创建为csv文件。 This will then open in Excel on the client computer.
然后,它将在客户端计算机上的Excel中打开。 The following method shows you how to do this:
以下方法显示了如何执行此操作:
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));
}
Use BuildReportAsCSV(ReportID)
to generate your report for downloading. 使用
BuildReportAsCSV(ReportID)
生成要下载的报告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.