Page 1 of 1

Read Excel With COMate

Posted: Mon Nov 24, 2008 3:19 pm
by jackymb
Hi,

I am try READ un Excel File, but Excel Open = Ok, file not appear.

Code: Select all

IncludePath #PB_Compiler_Home + "Include\"
XIncludeFile "COMate.pbi"

intRow.i = 2

Define.COMateObject ExcelObject, WorkBook
ExcelObject = COMate_CreateObject("Excel.Application")
;ExcelObject = GetObjectProperty("Workbooks\Open 'FileName:=Comate.xls'")
ExcelObject\SetProperty("Visible = #True")
ExcelObject\GetObjectProperty("Workbooks\Open 'FileName:=ComateTest.xls'")



If ExcelObject
  MessageRequester("COMate -Excel demo", "" )
;  Repeat
;     MessageRequester("",ExcelObject\GetStringProperty("Cells(intRow,1)"))
;    intRow = intRow + 1
;  Until ExcelObject\GetStringProperty("Cells(intRow,1) = ''")

   ExcelObject\Invoke("Quit()") 
  ExcelObject\Release()
Else
  MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
Please HelpMe

Re: Read Excel With COMate

Posted: Mon Nov 24, 2008 3:37 pm
by Kiffi
jackymb wrote:

Code: Select all

ExcelObject\GetObjectProperty("Workbooks\Open 'FileName:=ComateTest.xls'")

Code: Select all

ExcelObject\Invoke("Workbooks\Open('[YourFullPathHere]\ComateTest.xls')")
Greetings ... Kiffi

Posted: Mon Nov 24, 2008 3:43 pm
by srod
Ack Kiffi is too fast! :wink:

Code: Select all

WorkBook = ExcelObject\GetObjectProperty("Workbooks\Open('c:\test.xls')")

Posted: Tue Nov 25, 2008 8:16 am
by jackymb
Thanks Kiffi & Srod

another question: how to read a string in a cell, which increases the index intRow

Code: Select all

intRow.i = 2
  Repeat
    Cell$ = ExcelObject\GetStringProperty("Cells(intRow,1)")
    
     MessageRequester("Row: " + Str(intRow),Cell$)
    intRow = intRow + 1
  Until ExcelObject\GetStringProperty("Cells(intRow,1) = #nullstring")

Posted: Tue Nov 25, 2008 10:03 am
by Kiffi

Code: Select all

Cell$ = ExcelObject\GetStringProperty("Cells(" + Str(intRow) + ",1)")
(same in your Until - Statement)

Greetings ... Kiffi

Posted: Tue Nov 25, 2008 12:32 pm
by jackymb
Thank you very much Kiffi.
It's really stupid to have forgotten that ir string.

Posted: Sun Feb 08, 2009 3:50 pm
by Pierre Mercier
I tried that code on Excel 2007 wrote by Jackymb, corrected by Kiffi and srod. It worked until
this line

Code: Select all

until Cell$ = ExcelObject\GetStringProperty("Cells(" + Str(intRow) + ",1) = #NullString")
To make it worked i replace it with

Code: Select all

Until Cell$ = ""
Is it working with another excel version.

Also how can i put a header and footer ?

Posted: Sun Feb 08, 2009 9:09 pm
by srod

Code: Select all

until Cell$ = ExcelObject\GetStringProperty("Cells(" + Str(intRow) + ",1) = #NullString")
That line makes no sense whatsoever and does not represent a valid COMate command string.