HOW TO preserve number formatting while exporting data from a web page to Excel

There are many ways of exporting data from a web page to Excel using ASP.NET. Many of these techniques inherently depend on the ability of Office 2000 (& above) documents to be converted from Word/Excel to HTML (File->Save As) and vice versa.

When you have to implement finer details like preserving number formatting etc. in the generated Excel sheet, you may have to utilize the Office XML & CSS code that Office documents themselves natively generate.

More info on Office XML & CSS can be found in the Microsoft Office HTML and XML Reference.

I have an article on generating Excel sheets dynamically using this Office XML & CSS technique on EggHeadCafe.

Using the same technique, I have put up quick & dirty example on preserving number formatting. You can check the demo & source code.

Comments