Click to See Complete Forum and Search --> : Exporting to Excel from SQL via ASP.NET...preserving HTML formatting?


JeTmAn
06-01-2007, 12:19 PM
I am trying to export to Excel from SQL. My problem is not actually getting the export to work, but preserving the HTML formatting present in the SQL tables I am pulling from. When I export to Excel, either via a Datagrid bound w/the data or a custom function I have written which dumps to .csv, it goes through correctly but garbage characters appear every time a bullet point or some other non-standard formatting was present in the table.

I know this formatting has been preserved in SQL so it's still there, it's just not making it through to the spreadsheet. I have tried doing a manual export in SQL Enterprise Manager to a text file and surprisingly the bullets and other such formatting were preserved there. I just don't know why it won't show up in Excel. Actually when I loaded that text file into Excel the bullet points did make it through in that case, but they still don't when I dump to .csv or export from a Datagrid to Excel.

I am using ASP.NET 1.x and SQL 2000. When I export to .csv, I am first putting all the data into a custom datatable, then writing the contents of that datatable using a streamwriter.

kashif_82
06-04-2007, 04:19 PM
try opening the excel file that you get as export from your Web page and open it in Notepad.
When we write code to write the datagrid on the page as while making the content type as excel, it doesn't actually create an excel file but creates HTML tables from datagrid and opens them in a file which has extension of XLS (or at least that is what it did a while ago for my apps). But I am very sure the XLS/CVS file that you are getting from your Web page contains HTML table and see how the formatting tags (bold, bullets so on) are showing up. that might give you an idea what you can do to fix the problem. Hope this helps.