Export to excel

R

Reggie

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!
 
J

Julia B

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.Add("class", "text")
Next
Next

Hope this helps.
Julia
 
R

Reggie

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!
 
S

sloan

I was going to say about the same thing.

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

' would be even more abrupt.
 
R

Reggie

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top