Easy way to export html table to excel file in ASP.NET?

You have a report created from the database, you need to add an export button so that they can get the same report in an excellent readable sheet of some kind. The key here is ease of implementation, which is why CSV does a great job with XLS if it's easier.

+3
source share
2 answers

Excel is actually somewhat good at reading HTML. Especially if your HTML contains only one table. If you want to tell the browser to open the file in excel, you can use

Response.ContentType = "application/vnd.ms-excel"

Excel , . . , , - OO.org calc. , excel, . , . , , , CSV.

+4

HtmlTextWriter:

  System.IO.StringWriter stringWriter = new System.IO.StringWriter();

  System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);

  grid.RenderControl(htmlWriter);

grid - DataGrid. .

0

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


All Articles