Groups | Blog | Home
all groups > asp.net datagrid control > april 2005 >

asp.net datagrid control : Export to excel problem


kelvinweb NO[at]SPAM gmail.com
4/25/2005 1:23:22 AM
Hi All,

I don't know why my program exports to excel which can't convert cell
format ?
for example, I am using the following code:
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;
filename=OutstandingOrderDetailReport.xls");

"OrderNo" field should be 00001234, but it can display 1234 in excel
file.

DataFormatString defined the following:
<asp:boundcolumn headertext="OrderNo" datafield="OrderNo"
DataFormatString="{0:0000000}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundColumn>

Elton W
4/25/2005 1:47:35 PM
Hi Kelvin,

Actually I think it may be an Excel bug. When digital
data, e.g. 00001234, is filled in a excel column, it
automatically recognizes it as number, so trims its
leading zero(s).

If you use Excel automation COM object to deal with this
kind of data, you can format the column as TEXT first,
then fill up data. That will keep leading zero(s).

However, I haven't found any way to figure it out in
exporting datagrid to excel in ASP.NET.

HTH

Elton Wang
elton_wang@hotmail.com



[quoted text, click to view]
Alvin Bruney [MVP - ASP.NET]
4/26/2005 12:00:00 AM
one workaround is to append a quote before the string like so '00002034234.
The downside is that you would have to write iteration code to do that which
can be a performance drain

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc
[quoted text, click to view]

AddThis Social Bookmark Button