Advertisement
tabnation

libreoffice

Mar 9th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. ; by Capn Odin
  2. ;https://www.autohotkey.com/boards/viewtopic.php?f=5&t=16046
  3.  
  4. ;'This is a VBScript example
  5. ;'The service manager is always the starting point
  6. ;'If there is no office running then an office is started up
  7. f1::
  8. objServiceManager := ComObjCreate("com.sun.star.ServiceManager")
  9.  
  10. ;'Create the CoreReflection service that is later used to create structs
  11. objCoreReflection := objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
  12.  
  13. ;'Create the Desktop
  14. objDesktop := objServiceManager.createInstance("com.sun.star.frame.Desktop")
  15.  
  16. ;'Open a new empty writer document
  17. args := ComObjArray(VT_VARIANT := 12, 2)
  18. objDocument := objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
  19.  
  20. ;'Create a text object
  21. objText := objDocument.getText
  22.  
  23. ;'Create a cursor object
  24. objCursor := objText.createTextCursor
  25.  
  26. ;'Inserting some Text
  27. objText.insertString(objCursor, "The first line in the newly created text document.`n", 0)
  28.  
  29. ;'Inserting a second line
  30. objText.insertString(objCursor, "Now we're in the second line", 0)
  31.  
  32. ;'Create instance of a text table with 4 columns and 4 rows
  33. objTable := objDocument.createInstance( "com.sun.star.text.TextTable")
  34. objTable.initialize( 4, 4)
  35.  
  36. ;'Insert the table
  37. objText.insertTextContent(objCursor, objTable, false)
  38.  
  39. ;'Get first row
  40. objRows := objTable.getRows()
  41. objRow := objRows.getByIndex(0)
  42.  
  43. ;'Set the table background color
  44. objTable.setPropertyValue("BackTransparent", false)
  45. objTable.setPropertyValue("BackColor", 13421823)
  46.  
  47. ;'Set a different background color for the first row
  48. objRow.setPropertyValue("BackTransparent", false)
  49. objRow.setPropertyValue("BackColor", 6710932)
  50.  
  51. ;'Fill the first table row
  52. insertIntoCell("A1","FirstColumn", objTable) ;'insertIntoCell is a helper function, see below
  53. insertIntoCell("B1","SecondColumn", objTable)
  54. insertIntoCell("C1","ThirdColumn", objTable)
  55. insertIntoCell("D1","SUM", objTable)
  56.  
  57. objTable.getCellByName("A2").setValue(22.5)
  58. objTable.getCellByName("B2").setValue(5615.3)
  59. objTable.getCellByName("C2").setValue(-2315.7)
  60. objTable.getCellByName("D2").setFormula("sum ")
  61.  
  62. objTable.getCellByName("A3").setValue(21.5)
  63. objTable.getCellByName("B3").setValue(615.3)
  64. objTable.getCellByName("C3").setValue(-315.7)
  65. objTable.getCellByName("D3").setFormula("sum ")
  66.  
  67. objTable.getCellByName("A4").setValue(121.5)
  68. objTable.getCellByName("B4").setValue(-615.3)
  69. objTable.getCellByName("C4").setValue(415.7)
  70. objTable.getCellByName("D4").setFormula("sum ")
  71.  
  72. ;'Change the CharColor and add a Shadow
  73. objCursor.setPropertyValue("CharColor", 255)
  74. ;objCursor.setPropertyValue("CharShadowed", true)
  75.  
  76. ;'Create a paragraph break
  77. ;'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant
  78. objText.insertControlCharacter(objCursor, 0 , false)
  79.  
  80. ;'Inserting colored Text.
  81. objText.insertString(objCursor, " This is a colored Text - blue with shadow`n", false)
  82.  
  83. ;'Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK).
  84. objText.insertControlCharacter(objCursor, 0, false)
  85.  
  86. ;'Create a TextFrame.
  87. objTextFrame := objDocument.createInstance("com.sun.star.text.TextFrame")
  88.  
  89. ;'Create a Size struct.
  90. objSize := createStruct("com.sun.star.awt.Size") ;'helper function, see below
  91. objSize.Width := 15000
  92. objSize.Height := 400
  93. ;objTextFrame.setSize(objSize)
  94.  
  95. ;' TextContentAnchorType.AS_CHARACTER = 1
  96. objTextFrame.setPropertyValue("AnchorType", 1)
  97.  
  98. ;'insert the frame
  99. objText.insertTextContent(objCursor, objTextFrame, false)
  100.  
  101. ;'Get the text object of the frame
  102. objFrameText := objTextFrame.getText()
  103.  
  104. ;'Create a cursor object
  105. objFrameTextCursor := objFrameText.createTextCursor()
  106.  
  107. ;'Inserting some Text
  108. objFrameText.insertString(objFrameTextCursor, "The first line in the newly created text frame.", false)
  109. objFrameText.insertString(objFrameTextCursor, "`nWith this second line the height of the frame raises.", false)
  110.  
  111. ;'Create a paragraph break
  112. ;'The second argument is a com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK constant
  113. objFrameText.insertControlCharacter(objCursor, 0 , false)
  114.  
  115. ;'Change the CharColor and add a Shadow
  116. objCursor.setPropertyValue("CharColor", 65536)
  117. ;objCursor.setPropertyValue("CharShadowed", false)
  118.  
  119. ;'Insert another string
  120. objText.insertString(objCursor, " That's all for now !!", false)
  121.  
  122.  
  123. insertIntoCell(strCellName, strText, objTable){
  124. objCellText := objTable.getCellByName(strCellName)
  125. objCellCursor := objCellText.createTextCursor()
  126. objCellCursor.setPropertyValue("CharColor", 16777215)
  127. objCellText.insertString(objCellCursor, strText, false)
  128. }
  129.  
  130. createStruct(strTypeName){
  131. Global objCoreReflection
  132. classSize := objCoreReflection.forName(strTypeName)
  133. aStruct := ComObjArray(VT_VARIANT := 12, 2)
  134. classSize.createObject(aStruct)
  135. Return := aStruct
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement