469,643 Members | 1,910 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Export to excel

Hi and TIA! I have an export procedure that exports my data from my
datagrids to excel. The problem is that I lose leading zero's cause excel
removes them and doesn't treat them as text. Is it possible to design an
excel template file, place it in my shared network folder and have the
procedure write data to the template file? I've thought of reading the
recordset line by line, field by field and concatenating an apostrophe at
the beginning of each field, but this seems a little overboard and some of
the recordsets are quit large. I'm open for any advice or if you could
point me in the correct direction I would appreciate it. Thanks!

Oct 2 '08 #1
5 2300
Hi, I had this problem also. This is an asp.net 1.1 solution - I don't know
what version you're working in but I'm sure there'll be something similar in
all versions. You can add a text attribute to your datagrid after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

For rowPos As Integer = 0 To DataGrid.Items.Count - 1
For colPos As Integer = 0 To
DataGrid.Items(rowPos).Cells.Count - 1

DataGrid.Items(rowPos).Cells(colPos).Attributes.Ad d("class", "text")
Next
Next

Hope this helps.
Julia

"Reggie" wrote:
Hi and TIA! I have an export procedure that exports my data from my
datagrids to excel. The problem is that I lose leading zero's cause excel
removes them and doesn't treat them as text. Is it possible to design an
excel template file, place it in my shared network folder and have the
procedure write data to the template file? I've thought of reading the
recordset line by line, field by field and concatenating an apostrophe at
the beginning of each field, but this seems a little overboard and some of
the recordsets are quit large. I'm open for any advice or if you could
point me in the correct direction I would appreciate it. Thanks!

Oct 2 '08 #2
Julia, Thanks but it still removes the leading zero's when I export the
grid. I'll keep looking and if I come up with something will post back.
Thanks!
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:98**********************************@microsof t.com...
Hi, I had this problem also. This is an asp.net 1.1 solution - I don't
know
what version you're working in but I'm sure there'll be something similar
in
all versions. You can add a text attribute to your datagrid after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

For rowPos As Integer = 0 To DataGrid.Items.Count - 1
For colPos As Integer = 0 To
DataGrid.Items(rowPos).Cells.Count - 1

DataGrid.Items(rowPos).Cells(colPos).Attributes.Ad d("class", "text")
Next
Next

Hope this helps.
Julia

"Reggie" wrote:
>Hi and TIA! I have an export procedure that exports my data from my
datagrids to excel. The problem is that I lose leading zero's cause
excel
removes them and doesn't treat them as text. Is it possible to design an
excel template file, place it in my shared network folder and have the
procedure write data to the template file? I've thought of reading the
recordset line by line, field by field and concatenating an apostrophe at
the beginning of each field, but this seems a little overboard and some
of
the recordsets are quit large. I'm open for any advice or if you could
point me in the correct direction I would appreciate it. Thanks!

Oct 2 '08 #3
"Reggie" <ch*********@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
>>Hi and TIA! I have an export procedure that exports my data from my
DataGrids to Excel. The problem is that I lose leading zeroes because
Excel removes them and doesn't treat them as text. Is it possible to
design

Hi, I had this problem also. This is an ASP.NET 1.1 solution - I don't
know what version you're working in but I'm sure there'll be something
similar in all versions. You can add a text attribute to your DataGrid
after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

Julia, Thanks but it still removes the leading zeroes when I export the
grid. I'll keep looking and if I come up with something will post back.
Have you tried prefixing the data with an apostrophe...?

E.g. '000123
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 2 '08 #4
I was going to say about the same thing.

I ended up putting an "@" in front of the value.

' would be even more abrupt.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ez**************@TK2MSFTNGP06.phx.gbl...
"Reggie" <ch*********@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
>>>Hi and TIA! I have an export procedure that exports my data from my
DataGrids to Excel. The problem is that I lose leading zeroes because
Excel removes them and doesn't treat them as text. Is it possible to
design

Hi, I had this problem also. This is an ASP.NET 1.1 solution - I don't
know what version you're working in but I'm sure there'll be something
similar in all versions. You can add a text attribute to your DataGrid
after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

Julia, Thanks but it still removes the leading zeroes when I export the
grid. I'll keep looking and if I come up with something will post back.

Have you tried prefixing the data with an apostrophe...?

E.g. '000123
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 2 '08 #5
Mark, That's my next step. Like I said some of these recordsets are quit
large, so was thinking this may be a little slow. I'll try and let u know.
Thanks!

Reggie

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ez**************@TK2MSFTNGP06.phx.gbl...
"Reggie" <ch*********@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
>>>Hi and TIA! I have an export procedure that exports my data from my
DataGrids to Excel. The problem is that I lose leading zeroes because
Excel removes them and doesn't treat them as text. Is it possible to
design

Hi, I had this problem also. This is an ASP.NET 1.1 solution - I don't
know what version you're working in but I'm sure there'll be something
similar in all versions. You can add a text attribute to your DataGrid
after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

Julia, Thanks but it still removes the leading zeroes when I export the
grid. I'll keep looking and if I come up with something will post back.

Have you tried prefixing the data with an apostrophe...?

E.g. '000123
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Oct 2 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matt | last post: by
6 posts views Thread by Elena | last post: by
13 posts views Thread by Hemant Sipahimalani | last post: by
5 posts views Thread by Simon | last post: by
3 posts views Thread by =?Utf-8?B?YzY3NjIyOA==?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.