Advertisement
tabnation

libra writer document

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