I should be how to export data to Excel files same image.
Asked
Active
Viewed 2,144 times
0
-
Is this image that you want to export or the data that is stored somewhere in DB. Read this http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c-sharp?rq=1 – Anirudha Gupta Nov 13 '16 at 04:51
-
Your question would benefit from more detail. Especially on how you are generating the data for downloading. – Peter Smith Nov 13 '16 at 11:42
1 Answers
0
You should not install Excel on the server which is sometimes seen as a solution. One straightforward way is to create a download as a csv file. This will then open in Excel on the client computer. 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.

Peter Smith
- 5,528
- 8
- 51
- 77