Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep format intact after Datagrid Export to Excel

Status
Not open for further replies.

123ASP

MIS
Nov 2, 2002
239
0
0
US
Hi , I have created datagrid and added a link to export the content of the datagrid to excel. All format was lost when I export the data. Is there a way to keep the same format in the datagrid in the exported excel. Please click on the link to have a visual snap shot of the problem.


Thanks for your help
Al
 
You shouldn't need to do anything special, but I've found two quirks that can screw with the export a little.

1. If ViewState is enabled for the DataGrid, Excel doesn't know what to do with the extra information (and will ignore formatting), so it's best to disable it, and yank out any other information that isn't necessary.

2. Sometimes Excel can only do approximations of colors. If one doesn't work, try experimenting with different colors/shades.
 
Boulder - thanks for the tip on Viewstate. I use this routine also, and have found that if a column has a mix of field types, e.g., string + doubles:

Row1: 786
Row2: 786, 813, 912
Row3: 918, 877
...

that after the export to Excel the first row is used in the final formatting -- here it would try to save the row as doubles (showing errors otherwise), etc... so to correct this problem during the insert of records I put an initial comma:

Row1: ,786
Row2: ,786, 813, 912
Row3: ,918, 877
...

thereby assuring the entire column is returned in the Excel sheet as a "string" column.

I have also ran into problems with times (11:00) in this routine. I'll check the Viewstate condition, which I assume is on by default, and see if there are any differences.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top