Comate Prepare Statement reading excel file

Just starting out? Need help? Post your questions and find answers here.
loulou2522
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Oct 14, 2014 12:09 pm

Comate Prepare Statement reading excel file

Post by loulou2522 »

Hi all,
Can someone help me for the right staement to read a cell with prepare statement
I use
hStatement = comate::COMate_PrepareStatement("Cells(" + Str(@i) + " As long BYREF," + Str(@j) + " As long BYREF)")
and for reading
ExcelObject\GetStringProperty("",hStatement)
But this isn't work and generate an error
Here and example

Code: Select all

XIncludeFile #PB_Compiler_Home+"comate\COMatePLUS.pbi"
   Global.comateobject ExcelObject,Workbook,WorkSheet,Range,Sheet
    ;========================================
    ; Prepare statements
    ;========================================
    hStatement = COMate_PrepareStatement("Cells(" + Str(@i) + " As long BYREF," + Str(@j) + " As long BYREF)")
    
 fichier.s= "xxx.cls" ; nom du fichier a changer
    
    ExcelObject = COMate_CreateObject("Excel.Application")
 
      ExcelObject\SetProperty("Visible = #True") 
      Delay(5000)
    ExcelObject\SetProperty("DisplayAlerts=1")
    excelObject\SetProperty("ScreenUpdating = #true")
   
    If ExcelObject  
      WorkBook = ExcelObject\GetObjectProperty("Workbooks\Open("+"'"+fichier+"',0)")
      i=1
      Workbook\Invoke("Sheets('feuil1')\Select") ;nom de la feuille a changer
      debut=#True 
      message.s=""
      
      Repeat
        i=3
        J=0
        
         Debug ExcelObject\GetStringProperty("",hStatement)
        Debug COMate_GetLastErrorDescription() 
    
        i+1
           
          If i=4;on sort de la boucle ne faire le test que pour la premiére ligne 
            Break
          EndIf 
        
      ForEver 
      
      ExcelObject\Invoke("ActiveWorkbook\Close(0)")
      ExcelObject\SetProperty("Displayalerts = #True")
      ExcelObject\Invoke("Quit")
      Workbook\Release()
      ExcelObject\Release()
      
 EndIf
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Comate Prepare Statement reading excel file

Post by mk-soft »

Without specifying a property this will not work.

but, I don't know what the property for Statement is called
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
loulou2522
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Oct 14, 2014 12:09 pm

Re: Comate Prepare Statement reading excel file

Post by loulou2522 »

It's for reading the content of a cells
Sentence in Comate
ExcelObject\GetStringProperty("Cells("+ Str(i)+","+Str(1)+")\Value")
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Comate Prepare Statement reading excel file

Post by mk-soft »

Sorry, I don't know
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
loulou2522
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Oct 14, 2014 12:09 pm

Re: Comate Prepare Statement reading excel file

Post by loulou2522 »

Can anyone help me to solve that problem ?

i want to use Prepare Statement in comateplus to Read some text in a cell
The normal code for excel and comate is

Code: Select all

ExcelObject\GetStringProperty("Cells("+ Str(i)+","+Str(1)+")\Value")
loulou2522
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Oct 14, 2014 12:09 pm

Re: Comate Prepare Statement reading excel file

Post by loulou2522 »

No one can help me ?
morosh
Enthusiast
Enthusiast
Posts: 329
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: Comate Prepare Statement reading excel file

Post by morosh »

Hello:
to read an excel file, I always used the following:

Code: Select all

XIncludeFile "E:\install\dvd1\dev_soft\purebasic\extra\COMatePLUS\COMatePLUS.pbi"

Declare.s read_excel(fname.s,sheet.s,col.u,lig.u)
Debug read_excel("e:\my_data\xlw\banque.xls","banque",1,15)
End

Procedure.s read_excel(fname.s,sheet.s,col.u,lig.u)
Define.COMateObject ExcelObject, WorkBook, Worksheet
Define result.s
ExcelObject = COMate_CreateObject("Excel.Application")
If ExcelObject
  Lookin$ = "Workbooks\Open('"+fname+"')"
  WorkBook = ExcelObject\GetObjectProperty(Lookin$)
  If WorkBook
    WorkSheet = ExcelObject\GetObjectProperty("Sheets('"+sheet+"')")
    If WorkSheet
      WorkSheet\Invoke("Activate()") 
      result = ExcelObject\GetStringProperty("Cells("+Str(lig)+"," + Str(col) + ")" )    ; Cells(Row,Column)
    Else
      MessageRequester("COMate ", "error ExcelObject\GetObjectProperty(Sheets)")       
    EndIf
  Else  
    MessageRequester("COMate ", "error ExcelObject\GetObjectProperty(Workbooks\Open)")      
  EndIf
Else
  MessageRequester("COMate ", "error COMate_CreateObject")  
EndIf
WorkSheet\Release()
WorkBook = ExcelObject\GetObjectProperty("Workbooks\Close")
ExcelObject\Invoke("Quit()")
ExcelObject\Release()
ProcedureReturn result
EndProcedure

But I'm not sure if that's what you're searching for.
HTH.
PureBasic: Surprisingly simple, diabolically powerful
Post Reply