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

Post Reply
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

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

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

If the first column of the Excel is formatted as text, TOleAuto reads the values as text '001', etc
Regards

G. N. Rao.
Hyderabad, India
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post 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 ?
Regards

G. N. Rao.
Hyderabad, India
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post 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
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Post 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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

It's only a display problem. Try using Int() function or SET DECIMAL TO 0 command.

EMG
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Post by nageswaragunupudi »

Yes. that is the right forum. not this
Regards

G. N. Rao.
Hyderabad, India
ShumingWang
Posts: 454
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Post 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
Post Reply