Export to excel

  • Thread starter Thread starter Reggie
  • Start date Start date
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!
 
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
 
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!
 
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, 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
 
Back
Top