Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; by jeeswg
- ;https://www.autohotkey.com/boards/viewtopic.php?t=61084
- ;[MakePropertyValue function]
- ;API/UNO - LibreOffice/OpenOffice Calc - AutoHotkey Community
- ;https://autohotkey.com/boards/viewtopic.php?f=5&t=16046
- ;LibreOffice - populate cells + custom class for getting info
- oSM := ComObjCreate("com.sun.star.ServiceManager")
- oDesk := oSM.createInstance("com.sun.star.frame.Desktop")
- oArray := ComObjArray(0xC, 2) ;VT_VARIANT := 0xC
- oArray.1 := MakePropertyValue(oSM, "Hidden", ComObject(0xB, True)) ;VT_BOOL := 0xB
- oDoc := oDesk.loadComponentFromURL("private:factory/scalc", "_blank", 0, oArray)
- vSheet := "Sheet1"
- oSheet := oDoc.getSheets().getByName(vSheet)
- ;vCol := 1, vRow := 1, vNum := 1
- ;oSheet.getCellByPosition(vCol-1, vRow-1).setValue(vNum)
- ;vCol := 2, vRow := 2, vText := "a"
- ;oSheet.getCellByPosition(vCol-1, vRow-1).setString(vText)
- ;vCol := 3, vRow := 3, vFormula := "=1+1"
- ;oSheet.getCellByPosition(vCol-1, vRow-1).setFormula(vFormula)
- ;vCol := 2, vRow := 2
- ;oSheet.getCellByPosition(vCol-1, vRow-1).clearContents(0x3FF)
- Loop, 10
- {
- vRow := A_Index
- Loop, 10
- {
- vCol := A_Index
- , vAddr := Chr(A_Index + 64) vRow
- , vText := "[" vAddr "]"
- , oSheet.getCellByPosition(vCol-1, vRow-1).setString(vText)
- }
- }
- oSheet.getCellRangeByName("E10").cellBackColor := 0xFF0000
- oSheetX := new LOSheet(oSheet)
- MsgBox, % oSheetX.E10.Row ;9
- MsgBox, % oSheetX.E10.Column ;4
- MsgBox, % oSheetX.E10.String ;[E10]
- ;MsgBox, % oSheetX.E10.Value
- ;MsgBox, % oSheetX.E10.Formula
- MsgBox, % Format("0x{:06X}", oSheetX.E10.Color)
- oSheetX.E10.cellBackColor := 0xFFFF00
- MsgBox, % Format("0x{:06X}", oSheetX.E10.Color)
- MsgBox
- ExitApp
- ;==================================================
- MakePropertyValue(poSM, cName, uValue)
- {
- oPropertyValue := poSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
- oPropertyValue.Name := cName
- oPropertyValue.Value := uValue
- return oPropertyValue
- }
- ;==================================================
- class LOSheet
- {
- __New(oSheet)
- {
- this.Sheet := oSheet
- }
- __Get(vKey)
- {
- local
- global LOCell
- return new LOCell(this.Sheet, vKey)
- }
- }
- ;==================================================
- class LOCell
- {
- __New(oSheet, vAddr)
- {
- ObjRawSet(this, "Sheet", oSheet)
- ObjRawSet(this, "Address", vAddr)
- ObjRawSet(this, "Cell", this.Sheet.getCellRangeByName(this.Address))
- }
- __Get(vKey)
- {
- local
- oRange := this.Sheet.getCellRangeByName(this.Address)
- if (vKey = "Row")
- return oRange.getCellAddress().Row
- else if (vKey = "Column")
- return oRange.getCellAddress().Column
- else if (vKey = "Color")
- return oRange.cellBackColor
- else
- return oRange[vKey]
- }
- __Set(vKey, vValue)
- {
- local
- oRange := this.Sheet.getCellRangeByName(this.Address)
- if (vKey = "Color")
- oRange.cellBackColor := vValue
- else
- oRange[vKey] := vValue
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement