Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default display long number as text

I have a very long number (16 digits). How can I display it as text so that
it would not be truncated as 1.18621E+16 in the cell while the cell has been
set to autofit format? It also might be a general question simply display
data as text in each cell?

I am using XP pro/Visual studio 2003/Office 2003. Part of the code is as
following. Thanks!


Try
If dr.FieldCount Then
While dr.Read()

For i = 0 To dr.FieldCount - 1

'write to excel
oSheet.Cells(rowNum, i + 1) = dr.GetValue(i).ToString

'write to text file
strLine2 = strLine2 & dr.GetValue(i).ToString & ","
Next
rowNum += 1

objStreamWriter2.WriteLine(strLine2)
strLine2 = ""
End While

For i = 1 To dr.FieldCount - 1
'write to excel
oSheet.Cells(rowNum, i + 1).EntireColumn.Autofit()
oSheet.Cells(rowNum, i + 1).autofilter()
Next


End If
Catch ex As Exception
Console.WriteLine(ex.Message.ToString)
End Try

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default display long number as text

oSheet.Cells(rowNum, i + 1) = "'" & dr.GetValue(i).ToString

The single quote will make it a string and will not display.

--
Regards,
Tom Ogilvy

"Daisy" wrote in message
...
I have a very long number (16 digits). How can I display it as text so

that
it would not be truncated as 1.18621E+16 in the cell while the cell has

been
set to autofit format? It also might be a general question simply display
data as text in each cell?

I am using XP pro/Visual studio 2003/Office 2003. Part of the code is as
following. Thanks!


Try
If dr.FieldCount Then
While dr.Read()

For i = 0 To dr.FieldCount - 1

'write to excel
oSheet.Cells(rowNum, i + 1) =

dr.GetValue(i).ToString

'write to text file
strLine2 = strLine2 & dr.GetValue(i).ToString &

","
Next
rowNum += 1

objStreamWriter2.WriteLine(strLine2)
strLine2 = ""
End While

For i = 1 To dr.FieldCount - 1
'write to excel
oSheet.Cells(rowNum, i + 1).EntireColumn.Autofit()
oSheet.Cells(rowNum, i + 1).autofilter()
Next


End If
Catch ex As Exception
Console.WriteLine(ex.Message.ToString)
End Try



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default display long number as text

It works. Thanks a lot!

"Tom Ogilvy" wrote:

oSheet.Cells(rowNum, i + 1) = "'" & dr.GetValue(i).ToString

The single quote will make it a string and will not display.

--
Regards,
Tom Ogilvy

"Daisy" wrote in message
...
I have a very long number (16 digits). How can I display it as text so

that
it would not be truncated as 1.18621E+16 in the cell while the cell has

been
set to autofit format? It also might be a general question simply display
data as text in each cell?

I am using XP pro/Visual studio 2003/Office 2003. Part of the code is as
following. Thanks!


Try
If dr.FieldCount Then
While dr.Read()

For i = 0 To dr.FieldCount - 1

'write to excel
oSheet.Cells(rowNum, i + 1) =

dr.GetValue(i).ToString

'write to text file
strLine2 = strLine2 & dr.GetValue(i).ToString &

","
Next
rowNum += 1

objStreamWriter2.WriteLine(strLine2)
strLine2 = ""
End While

For i = 1 To dr.FieldCount - 1
'write to excel
oSheet.Cells(rowNum, i + 1).EntireColumn.Autofit()
oSheet.Cells(rowNum, i + 1).autofilter()
Next


End If
Catch ex As Exception
Console.WriteLine(ex.Message.ToString)
End Try




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula to display just number and not text edeaston1983 Excel Discussion (Misc queries) 3 March 25th 09 11:43 AM
Display only n numbers of characters for long text? Astro Excel Worksheet Functions 1 November 4th 08 08:03 AM
How do I display number into form of text or word? Isaac Steven Excel Worksheet Functions 1 October 8th 07 08:15 AM
"formula is too long" AND test for whether double-quotes are next-to text or number?? The Moose Excel Discussion (Misc queries) 2 September 14th 06 05:29 AM
how to display number(10) to text(ten) ajay Excel Discussion (Misc queries) 2 August 24th 06 11:06 AM


All times are GMT +1. The time now is 08:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"