Advertisement
tabnation

libre 2

Mar 9th, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. ; by jeeswg
  2. ;https://www.autohotkey.com/boards/viewtopic.php?t=61084
  3.  
  4. ;[MakePropertyValue function]
  5. ;API/UNO - LibreOffice/OpenOffice Calc - AutoHotkey Community
  6. ;https://autohotkey.com/boards/viewtopic.php?f=5&t=16046
  7.  
  8. ;LibreOffice - populate cells + custom class for getting info
  9.  
  10. oSM := ComObjCreate("com.sun.star.ServiceManager")
  11. oDesk := oSM.createInstance("com.sun.star.frame.Desktop")
  12. oArray := ComObjArray(0xC, 2) ;VT_VARIANT := 0xC
  13. oArray.1 := MakePropertyValue(oSM, "Hidden", ComObject(0xB, True)) ;VT_BOOL := 0xB
  14. oDoc := oDesk.loadComponentFromURL("private:factory/scalc", "_blank", 0, oArray)
  15.  
  16. vSheet := "Sheet1"
  17. oSheet := oDoc.getSheets().getByName(vSheet)
  18.  
  19. ;vCol := 1, vRow := 1, vNum := 1
  20. ;oSheet.getCellByPosition(vCol-1, vRow-1).setValue(vNum)
  21.  
  22. ;vCol := 2, vRow := 2, vText := "a"
  23. ;oSheet.getCellByPosition(vCol-1, vRow-1).setString(vText)
  24.  
  25. ;vCol := 3, vRow := 3, vFormula := "=1+1"
  26. ;oSheet.getCellByPosition(vCol-1, vRow-1).setFormula(vFormula)
  27.  
  28. ;vCol := 2, vRow := 2
  29. ;oSheet.getCellByPosition(vCol-1, vRow-1).clearContents(0x3FF)
  30.  
  31. Loop, 10
  32. {
  33. vRow := A_Index
  34. Loop, 10
  35. {
  36. vCol := A_Index
  37. , vAddr := Chr(A_Index + 64) vRow
  38. , vText := "[" vAddr "]"
  39. , oSheet.getCellByPosition(vCol-1, vRow-1).setString(vText)
  40. }
  41. }
  42.  
  43. oSheet.getCellRangeByName("E10").cellBackColor := 0xFF0000
  44.  
  45. oSheetX := new LOSheet(oSheet)
  46. MsgBox, % oSheetX.E10.Row ;9
  47. MsgBox, % oSheetX.E10.Column ;4
  48. MsgBox, % oSheetX.E10.String ;[E10]
  49. ;MsgBox, % oSheetX.E10.Value
  50. ;MsgBox, % oSheetX.E10.Formula
  51. MsgBox, % Format("0x{:06X}", oSheetX.E10.Color)
  52. oSheetX.E10.cellBackColor := 0xFFFF00
  53. MsgBox, % Format("0x{:06X}", oSheetX.E10.Color)
  54.  
  55. MsgBox
  56. ExitApp
  57.  
  58. ;==================================================
  59.  
  60. MakePropertyValue(poSM, cName, uValue)
  61. {
  62. oPropertyValue := poSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
  63. oPropertyValue.Name := cName
  64. oPropertyValue.Value := uValue
  65. return oPropertyValue
  66. }
  67.  
  68. ;==================================================
  69.  
  70. class LOSheet
  71. {
  72. __New(oSheet)
  73. {
  74. this.Sheet := oSheet
  75. }
  76. __Get(vKey)
  77. {
  78. local
  79. global LOCell
  80. return new LOCell(this.Sheet, vKey)
  81. }
  82. }
  83.  
  84. ;==================================================
  85.  
  86. class LOCell
  87. {
  88. __New(oSheet, vAddr)
  89. {
  90. ObjRawSet(this, "Sheet", oSheet)
  91. ObjRawSet(this, "Address", vAddr)
  92. ObjRawSet(this, "Cell", this.Sheet.getCellRangeByName(this.Address))
  93. }
  94. __Get(vKey)
  95. {
  96. local
  97. oRange := this.Sheet.getCellRangeByName(this.Address)
  98. if (vKey = "Row")
  99. return oRange.getCellAddress().Row
  100. else if (vKey = "Column")
  101. return oRange.getCellAddress().Column
  102. else if (vKey = "Color")
  103. return oRange.cellBackColor
  104. else
  105. return oRange[vKey]
  106. }
  107. __Set(vKey, vValue)
  108. {
  109. local
  110. oRange := this.Sheet.getCellRangeByName(this.Address)
  111. if (vKey = "Color")
  112. oRange.cellBackColor := vValue
  113. else
  114. oRange[vKey] := vValue
  115. }
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement