Board index » delphi » Force cells in Excel to use Text format rather than Number format

Force cells in Excel to use Text format rather than Number format


2004-06-14 06:45:20 PM
delphi161
Dear All,
How does one force cells in Excel to use Text format rather than Number
format?
In my code below, if (say) aString is a numerical string (e.g. '417895240')
and if the Excel column width is small, the cell value will display as 4E+08
rather than as 417895240 ...
i.e. the NumberFormat := '@'; seems not to work.
var theRange : Variant;
...
theRange := VarArrayOf([aString, bString, cString]);
Excel.Range[Format('A%u',[i]),Excel.Cells.Item[i,varArrayHighBound(theRange,
1)+1]].Value := theRange;
Excel.Range[Format('A%u',[i]),Excel.Cells.Item[i,varArrayHighBound(theRange,
1)+1]].NumberFormat := '@';
Regards,
AndrewFG
 
 

Re:Force cells in Excel to use Text format rather than Number format

<<Andrew Fiddian-Green:
How does one force cells in Excel to use Text format rather
than Number format?
Quote
>
By prefixing an apostrophe to the value.
--
Deborah Pate (TeamB) delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html
 

Re:Force cells in Excel to use Text format rather than Number format

Dear Deborah,
Do you mean the following?
theRange := VarArrayOf([''''+aString, ''''+bString, ''''+cString]);
Regards,
AndrewFG
"Deborah Pate (TeamB)" <XXXX@XXXXX.COM>wrote in
message news:XXXX@XXXXX.COM...
Quote
<<Andrew Fiddian-Green:
How does one force cells in Excel to use Text format rather
than Number format?
>>

By prefixing an apostrophe to the value.

--
Deborah Pate (TeamB) delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html


 

Re:Force cells in Excel to use Text format rather than Number format

Andrew Fiddian-Green writes:
Quote
How does one force cells in Excel to use Text format rather than Number
format?
Try setting the format before you place the values into the cells.
... Joe
Member of the UK Borland User Group
 

Re:Force cells in Excel to use Text format rather than Number format

Quote
Try setting the format before you place the values into the cells.
Thanks Joe, it worked a treat. -- Obvious when you think about it.
AndrewFG
"Joe Griffin" <XXXX@XXXXX.COM>writes
Quote
Andrew Fiddian-Green writes:
>How does one force cells in Excel to use Text format rather than Number
>format?

Try setting the format before you place the values into the cells.

... Joe
Member of the UK Borland User Group