PC Review


Reply
Thread Tools Rate Thread

converting to excel - strings that look like numbers

 
 
Bernie Yaeger
Guest
Posts: n/a
 
      21st Feb 2004
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


 
Reply With Quote
 
 
 
 
Patrick Penet
Guest
Posts: n/a
 
      22nd Feb 2004
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


"Bernie Yaeger" <(E-Mail Removed)> a écrit dans le message de news:eNftOPD%(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      22nd Feb 2004
Hi Patrick,

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

Thanks very much!

Bernie

"Patrick Penet" <(E-Mail Removed)> wrote in message
news:403877b9$0$5915$(E-Mail Removed)...
> 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
>
>
> "Bernie Yaeger" <(E-Mail Removed)> a écrit dans le message de

news:eNftOPD%(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting strings to numbers Big Bitty Microsoft Excel Programming 1 29th Apr 2010 03:29 PM
Converting Numbers from Excel to TXT files LinLin Microsoft Excel Misc 2 27th May 2009 06:53 AM
how to extract decimal numbers from alphanumeric strings in Excel =?Utf-8?B?T2xkIFRvbmU=?= Microsoft Excel Misc 13 23rd Mar 2006 03:49 PM
converting numbers in excel to access sonika Microsoft Excel Misc 0 8th Oct 2004 06:22 AM
PN: Converting C Strings to managed strings Peter Nolan Microsoft VC .NET 0 20th Nov 2003 11:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:45 AM.