Read Excel With COMate

Just starting out? Need help? Post your questions and find answers here.
User avatar
jackymb
User
User
Posts: 16
Joined: Wed Aug 11, 2004 7:37 pm
Location: AIX en PROVENCE (France)

Read Excel With COMate

Post 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
User avatar
Kiffi
Addict
Addict
Posts: 1487
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Read Excel With COMate

Post 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
Hygge
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ack Kiffi is too fast! :wink:

Code: Select all

WorkBook = ExcelObject\GetObjectProperty("Workbooks\Open('c:\test.xls')")
I may look like a mule, but I'm not a complete ass.
User avatar
jackymb
User
User
Posts: 16
Joined: Wed Aug 11, 2004 7:37 pm
Location: AIX en PROVENCE (France)

Post 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")
User avatar
Kiffi
Addict
Addict
Posts: 1487
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post by Kiffi »

Code: Select all

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

Greetings ... Kiffi
Hygge
User avatar
jackymb
User
User
Posts: 16
Joined: Wed Aug 11, 2004 7:37 pm
Location: AIX en PROVENCE (France)

Post by jackymb »

Thank you very much Kiffi.
It's really stupid to have forgotten that ir string.
Pierre Mercier
User
User
Posts: 10
Joined: Wed Apr 23, 2008 4:02 am
Location: CANADA

Post 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 ?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Post Reply