Page 1 of 1

Harbour TOleAuto():New() 1 will read as 1.00

Posted: Mon Apr 14, 2008 12:50 am
by ShumingWang
Hi,
excel file, cell type normal .
itemid qty
001 1
002 1
010 8

oExcel := TOleAuto():New( "Excel.Application" )
oExcel:WorkBooks:Open(ALLTRIM(cfile))
oSheet := oExcel:ActiveSheet()
? oSheet:Cells(2,1):Value
//1.00

? oSheet:Cells(2,1):Value
//2.00

? oSheet:Cells(3,1):Value
//10.00
Best regards!

Shuming Wang

Posted: Mon Apr 14, 2008 12:57 am
by nageswaragunupudi
If the first column of the Excel is formatted as text, TOleAuto reads the values as text '001', etc

Posted: Mon Apr 14, 2008 1:33 am
by ShumingWang
But xharbour could.
For sometimes customers do not know the changement, so get errors .
I think harbour should change this ,or there is a function could change this.
Shuming Wang

Posted: Mon Apr 14, 2008 2:23 am
by nageswaragunupudi
XHarbour knows what excel knows. Excel itself thinks it is a number ( in canse of general format ). How can xharbour knwo what excel itself does not know ?

Posted: Mon Apr 14, 2008 3:05 am
by ShumingWang
It could read int as int type , float as float:
1 read as 1
1.00 read as 1.00

Cell 001, 1 and 1.00 in excel are different.

Shuming Wang

Posted: Mon Apr 14, 2008 12:46 pm
by Rick Lipkin
ShumingWang

If I understand you correctly .. you are looking to 'format' a column ?? If so you can uses the following :

For alpha\numeric column :
oSheet:Range( "A:C" ):Set( "NumberFormat", '@' )

For a numeric column with 2 decimals:
oSheet:Range( "A:C" ):Set( "NumberFormat", '0.00' )

The formatting comes after you define your workbook.

Hope this helps

Rick Lipkin

Posted: Mon Apr 14, 2008 12:51 pm
by nageswaragunupudi
Mr Richard

That is not what he wants. Even I misunderstood him earlier. What he says is this.

He is reading from excel sheet using TOleAuto. He is reading second column. All the numbers in the second column in the excel sheet are integers.

After harbour reads these integers, Harbour shows these intergers as 1.00, 2.00, etc. but not as 1, 2, etc. He says why can not Harbour show them as 1, 2, etc.

Posted: Mon Apr 14, 2008 3:47 pm
by Enrico Maria Giordano
It's only a display problem. Try using Int() function or SET DECIMAL TO 0 command.

EMG

Posted: Mon Apr 14, 2008 3:54 pm
by nageswaragunupudi
kindly see the following code:

n := 9
m := 10.00
msginfo( n ) // displays 9
msginfo( m ) // displays 10.0000

That means (x)harbour internally notes that n is integer and m is not. What Mr Richard asks is to do that when reading values by TOleAuto class.

Posted: Mon Apr 14, 2008 3:57 pm
by Enrico Maria Giordano
You better ask to Ron Pinkas in comp.lang.xharbour.

EMG

Posted: Mon Apr 14, 2008 3:58 pm
by nageswaragunupudi
Yes. that is the right forum. not this

Posted: Tue Apr 15, 2008 12:39 am
by ShumingWang
Thank you all for take interested to this!
Some time a table with a field named itemid char type might load some data from an excel sheet.

read from excel seet:

itemid qty
001 1
002 1
003 2
004 2.11
011 18.10

--->

to database table1

wanted result :
itemid(char) qty (float)
001 1.00
002 1.00
003 2.00
004 2.11
011 18.10

But actual wrong result:
itemid(char) qty (float)
1.00 1.00
2.00 1.00
3.00 2.00
4.00 2.11
11.00 18.10

Sorry ,I posted to http://lists.harbour-project.org/piperm ... /date.html , but failed.

Best regard!
Shuming Wang