Some of you might already know it, But for those who don’t this might be useful.
A Few months ago, a question was raised if there exist an OpenOffice / LibreOffice plugin for Xojo, and the answer was No.
Since I’m not that good to write plugins for Xojo, I wonder if there was another way to approach this issue.
As my main platform is windows (2nd Linux), I did some investigation how to access LibreOffice with use of the OLEObject class.
And this is the result with use of OLEObject link: http://pbrd.co/1b2jSK6
I used following code example http://api.libreoffice.org/examples/OLE/vbscript/WriterDemo.vbs for my test; rewrote a part of it to RealStudio.
The code consist of one PushButton and one Method
PushButton1.Action
[code] Dim objServiceManager As OLEObject
Dim objCoreReflection As OLEObject
Dim objDesktop As OLEObject
Dim objDocument As OLEObject
Dim objText As OLEObject
Dim objCursor As OLEObject
Dim objTable As OLEObject
Dim objRows As OLEObject
Dim objRow As OLEObject
Dim Lf As String = chr(10) // Line Feed
'The service manager is always the starting point
'If there is no office running then an office is started up
objServiceManager = New OLEObject(“com.sun.star.ServiceManager”)
'Create the CoreReflection service that is later used to create structs
objCoreReflection = objServiceManager.createInstance(“com.sun.star.reflection.CoreReflection”)
'Create the Desktop
objDesktop = objServiceManager.createInstance(“com.sun.star.frame.Desktop”)
'Open a new empty writer document
Dim args() As variant
objDocument= objDesktop.loadComponentFromURL(“private:factory/swriter”, “_blank”, 0, args)
'Create a text object
objText= objDocument.getText
'Create a cursor object
objCursor= objText.createTextCursor
'Inserting some Text
objText.insertString (objCursor, "The first line in the newly created text document, made by RealStudio 2012.R2.1 " +Lf , false)
'Inserting a second line
objText.insertString (objCursor, “Now we’re in the second line”, false)
'Create instance of a text table with 4 columns and 4 rows
objTable= objDocument.createInstance( “com.sun.star.text.TextTable”)
objTable.initialize (4, 4)
'Insert the table
objText.insertTextContent ( objCursor, objTable, false)
'Get first row
objRows= objTable.getRows
objRow= objRows.getByIndex( 0)
'Set the table background color
objTable.setPropertyValue (“BackTransparent”, false)
objTable.setPropertyValue (“BackColor”, 13421823)
'Set a different background color for the first row
objRow.setPropertyValue (“BackTransparent”, false)
objRow.setPropertyValue (“BackColor”, 6710932)
'Fill the first table row
insertIntoCell (“A1”,“FirstColumn”, objTable)
insertIntoCell (“B1”,“SecondColumn”, objTable)
insertIntoCell (“C1”,“ThirdColumn”, objTable)
insertIntoCell (“D1”,“SUM”, objTable)
objTable.getCellByName(“A2”).setValue 22.5
objTable.getCellByName(“B2”).setValue 5615.3
objTable.getCellByName(“C2”).setValue -2315.7
objTable.getCellByName(“D2”).setFormula"sum A2:C2"
objTable.getCellByName(“A3”).setValue 21.5
objTable.getCellByName(“B3”).setValue 615.3
objTable.getCellByName(“C3”).setValue -315.7
objTable.getCellByName(“D3”).setFormula “sum A3:C3”
objTable.getCellByName(“A4”).setValue 121.5
objTable.getCellByName(“B4”).setValue -615.3
objTable.getCellByName(“C4”).setValue 415.7
objTable.getCellByName(“D4”).setFormula “sum A4:C4”
'Change the CharColor and add a Shadow
objCursor.setPropertyValue (“CharColor”, 255)
objCursor.setPropertyValue (“CharShadowed”, true)
'Create a paragraph break
'The second argument is a com::sun::text::ControlCharacter::PARAGRAPH_BREAK constant
objText.insertControlCharacter (objCursor, 0 , false)
'Inserting colored Text.
objText.insertString (objCursor, " This is a colored Text - blue with shadow" + Lf, false)
'Create a paragraph break ( ControlCharacter::PARAGRAPH_BREAK).
objText.insertControlCharacter (objCursor, 0, false)
[/code]
Sub insertIntoCell(strCellName As String, strText As String, objTable As OLEObject)
[code] Dim objCellText As OLEObject
Dim objCellCursor As OLEObject
objCellText= objTable.getCellByName( strCellName)
objCellCursor= objCellText.createTextCursor
objCellCursor.setPropertyValue (“CharColor”,16777215)
objCellText.insertString (objCellCursor, strText, false)[/code]
This example works both in windows XP and in Windows 7 with Libreoffice 4.1 and Realstudio 2012R2.1
For more informations how to access LLibreOffice SpreadSheet, Drawing or presentation you can find on following site: http://www.openoffice.org/api/TipsAndTricks/external.html
I guess this example should be enough to get going