1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| XIncludeFile "COMatePLUS.pbi"
Define.COMateObject ExcelObject, WorkBook
ExcelObject = COMate_CreateObject("Excel.Application")
;Prepare our statement for writing to an individual cell. Our choice of cell is unimportant.
;What is important is that we use type-modifiers to set the parameter types.
;===========================================================================================
hStatement = COMate_PrepareStatement("Cells(1 as long,1 as long) = 1 as long")
If hStatement = 0
MessageRequester("COMatePLUS!", "Couldn't create the statement!" + #CRLF$ + #CRLF$ + "COMatePLUS error : " + COMate_GetLastErrorDescription())
End
EndIf
;Retrieve pointers to the first two parameters so that we can alter them later.
;==============================================================================
*row.VARIANT = COMate_GetStatementParameter(hStatement, 1)
*col.VARIANT = COMate_GetStatementParameter(hStatement, 2)
If ExcelObject
If ExcelObject\SetProperty("Visible = #True") = #S_OK
WorkBook = ExcelObject\GetObjectProperty("Workbooks\Add")
If WorkBook
;Write 10000 cells using our pre-compiled statement.
;We fill each of the 10000 cells with the value 1.
For row = 1 To 100
For col = 1 To 100
;Set parameters.
*row\lVal = row
*col\lVal = col
ExcelObject\SetProperty("", hStatement)
Next
Next
ExcelObject\Invoke("Quit()")
WorkBook\Release()
EndIf
EndIf
ExcelObject\Release()
Else
MessageRequester("COMate -Excel demo", "Couldn't create the application object!")
EndIf
;Free our statement.
;===================
COMate_FreeStatementHandle(hStatement) |
Partager