Page 1 of 1

Comate Prepare Statement reading excel file

Posted: Sun Apr 12, 2020 9:32 am
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

Re: Comate Prepare Statement reading excel file

Posted: Sun Apr 12, 2020 10:05 am
by mk-soft
Without specifying a property this will not work.

but, I don't know what the property for Statement is called

Re: Comate Prepare Statement reading excel file

Posted: Sun Apr 12, 2020 10:08 am
by loulou2522
It's for reading the content of a cells
Sentence in Comate
ExcelObject\GetStringProperty("Cells("+ Str(i)+","+Str(1)+")\Value")

Re: Comate Prepare Statement reading excel file

Posted: Sun Apr 12, 2020 10:48 am
by mk-soft
Sorry, I don't know

Re: Comate Prepare Statement reading excel file

Posted: Sun Apr 12, 2020 1:13 pm
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")

Re: Comate Prepare Statement reading excel file

Posted: Sat Apr 25, 2020 4:11 pm
by loulou2522
No one can help me ?

Re: Comate Prepare Statement reading excel file

Posted: Sun Apr 26, 2020 8:54 am
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.