0

I need a function to convert any HTML table to a excel file!

I like to add a button to my page and once that button is clicked I pass a complete HTML table in to such a function that will generate an excel file and past the html table into the file with the same layout and design!

I appreciate any help with this request.

I am using c# and asp.net

3
  • Try DataTable: datatables.net Commented Dec 31, 2012 at 0:32
  • Try the following: save the HTML table to a file and give it the .xls extension. If the file has that extension it should open in Excel Commented Dec 31, 2012 at 0:32
  • Daniel, I am new to asp.net and c#. So i am not sure where to start! I have been Googling this for a while now and i am unable to figure it out! Commented Dec 31, 2012 at 1:16

1 Answer 1

1

This is a nasty trick, but it works in recent version of excel.

You just save the html table as a normal html file, then just rename it to xls. If your application is a web application use response.setHeader("Content-Disposition", "attachment; filename=order.xls").

Recent version of excel support Microsoft Office XML Formats, so if the previous solution doesn't work, you may want to try to generate the xml from the html table. See XML Spreadsheet Reference.

What I do, is to generate the xml from excel in the xml format, then hack into it. You can implement also advanced features like automatic filters, and cool layouts. I used a template engine to generate the xml (Freemarker, it's Java stuff, but I'm sure there are template engines also for .NET)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.