I’m planning on implementing a SaveToExcel feature in an ASP.NET web page by sending the HTML back to the server in a hidden field, and then just pumping it back out as an attachment with an .xls extension.
The problem is that the web page is heavily styled through CSS. And since those styles aren’t an intrinsic part of the HTML, I don’t think they’ll transfer to the Excel file. (I now see why the programmer of the report I’m adapting this from used FONT tags so heavily, which I wondered about.)
It has occurred to me that it might be possible to run a jQuery script on the page before submitting it back to the server, copying the actual styles from the css property to the element’s own intrinsic properties.
I don’t know how well that would work, but it might be better than nothing.
Is there a better way?
Carlos Aguilar Mares has a free Excel XML library that I’ve used in the past. The sample code is helpful as well.
http://www.carlosag.net/tools/excelxmlwriter/