converting to excel - strings that look like numbers

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I'm using the following function (I'm displaying the guts of it only) to
convert a datatable to an excel spreadsheet:

For Each mrow In dt.Rows
rowindex += 1
colindex = 0
For Each col In dt.Columns
colindex += 1
objws.Cells(rowindex, colindex) = mrow(col.ColumnName).ToString()
Next
Next

This works fine, but if there's a string which looks like a number, prefix
'0's are dropped - eg, '07' become '7'. Is there any way to avoid this and
have the .xls file display '07'?

Thanks for any help.

Bernie Yaeger
 
Hi Bernie,
You should add a ' as the first char of the values you
pass to Excel, it then will be seen as a string.
OTH
Patrick Penet
 
Hi Patrick,

I got this answer somewhat earlier on an Excel newsgroup, and it works fine.

Thanks very much!

Bernie
 
Back
Top