Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I need to convert html page to excel with formatting using c#. Please help me to work on this. Or suggest me any third party tools to convert html to excel (with formatting).

Thanks in Advance,
Arunachalam M.
Posted

 
Share this answer
 
v2
As for html to excel with formatting issue, you can see below code:
C#
Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition","attachment;filename="+DateTime.
Now.ToString("yyyyMMdd")+".xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = ""application/ms-excel";;
this.EnableViewState = false;


The "ContentType" property which the default set is text/HTML can help us a lot. And hypertext will be exported to client. If we change it to ms-excel, it will be exported as Excel format and your browser will remind you to download and store it. The property of "ContentType" includes image/JPEG, text/HTML, image/GIF and vnd.ms-excel/msword.
 
Share this answer
 
What formatting ? Excel will open a CSV, so just emit your data as a CSV to create an Excel compatible download.
 
Share this answer
 
Comments
Arunachalam Muthukumar 7-Jan-13 2:02am    
For instance, the content in html table (td) is (15,345). When this is exported to excel, it will be changed to -15,345. Thats why I am looking for the tool to export to excel with formatting.
Christian Graus 7-Jan-13 2:20am    
So you put (15,345) in the column of your CSV

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900