Export data to an Excel file with multiple sheets in ASP.NET

In a C # ASP.NET 3.5 web application, I need to export multiple data (or a dataset) to an Excel 2007 file with multiple sheets, and then provide the user with an Open / Save dialog box WITHOUT saving the Excel file to the web server.

I used Excel Interop before. I read that it is inefficient and is not the best approach to achieve this, and there are more ways to do this: 2 of them: 1) Converting data in datatables to an XML string that Excel understands 2) Using the OPEN XML SDK 2.0.

It seems like the OPEN XML SDK 2.0 is better, please let me know. Are there any other ways to do this? I do not want to use third-party tools.

If I use the OPEN XML SDK, it creates an excel file, right? I don’t want to save it on the server’s hard drive (Windows 2003) (I don’t want to use Server.MapPath, these Excel files are dynamically created and they are not needed on the server as soon as the client receives them), I directly want to offer the user to open / save his. I know how to do this when using the XML string approach.

Please, help. Thank.

+3
source share
3 answers

Is Excel 2007 Support Required?

NPOI , ( , , ). .

, , Excel 2003, , OOXML.

, . .

+1

XML- XML Excel.

:

<a href="report.aspx" target="_blank"> Open excel Report</a>

Report.aspx:

 Response.Clear();
 Response.ContentType = "application/vnd.ms-excel";
 Response.AddHeader("Content-Disposition"
                     , "attachment;filename=" & _fileName & ".xml");
 Response.Write("<?xml version=""1.0""?>");
 Response.Write(excelXML);
+1

excel. . Open XML Office Interop. . . , , .

0

Source: https://habr.com/ru/post/1739624/


All Articles