converting to excel - strings that look like numbers

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
 
P

Patrick Penet

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
 
B

Bernie Yaeger

Hi Patrick,

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

Thanks very much!

Bernie
 

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

Top