Here is a solution - it uses Common Language Infrastructure (CLI) Uno with VB 2005 to open swriter.exe and insert some text.
This solution is a translation of C# from:
http://opendocument4all.com/content/view/68/47/
1. Start VB 2005 and create a new project - Windows application.
2. View Code.
3. Copy the following to replace all code.
Code: Select all
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports unoidl.com.sun.star.lang
Imports unoidl.com.sun.star.uno
Imports unoidl.com.sun.star.bridge
Imports unoidl.com.sun.star.frame
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Call the bootstrap method to get a new ComponentContext
'object. If OpenOffice isn't already started this will
'start it and then return the ComponentContext.
Dim FileName As String = "C:\odtfiles est.odt"
Dim localContext As unoidl.com.sun.star.uno.XComponentContext = uno.util.Bootstrap.bootstrap()
'Get a new service manager of the MultiServiceFactory type
'we need this to get a desktop object and create new CLI
'objects.
Dim multiServiceFactory As unoidl.com.sun.star.lang.XMultiServiceFactory = DirectCast(localContext.getServiceManager(), unoidl.com.sun.star.lang.XMultiServiceFactory)
'Create a new Desktop instance using our service manager
'Notice: We cast our desktop object to XComponent loader
'so that we could load or create new documents.
Dim componentLoader As XComponentLoader = DirectCast(multiServiceFactory.createInstance("com.sun.star.frame.Desktop"), XComponentLoader)
'Create a new blank writer document using our component
'loader object.
'a blank writer document
'into a blank frame use no searchflag
'use no additional arguments.
Dim xComponent As XComponent = componentLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, New unoidl.com.sun.star.beans.PropertyValue(-1) {})
'Cast our component to a the XText interface
'and write some simple text into document.
DirectCast(xComponent, unoidl.com.sun.star.text.XTextDocument).getText().setString("Hello I'm the first text!")
'After we insert our text, we cast our component to XStorable
'to save it onto the harddisk
'Convert the file path into a OpenOffice path
'no additional arguments
DirectCast(xComponent, XStorable).storeToURL(PathConverter(FileName), New unoidl.com.sun.star.beans.PropertyValue(-1) {})
End Sub
Private Shared Function PathConverter(ByVal file As String) As String
Try
file = file.Replace("\", "/")
Return "file:///" & file
Catch ex As System.Exception
Throw ex
End Try
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class
3. From the VB toolbox, in design mode, add 2 command buttons. Button1 when clicked starts OOo writer. Button2 exits.
4. Close VB and Save.
5. Copy these files (they are in Program files) to your VB project folder, the one under folder with .sln & .suo
cli_basetypes.dll
cli_cppuhelper.dll
cli_oootypes.dll
cli_ure.dll
cli_uretypes.dll
6. Start VB again and open the saved project.
7. Do Project - Add reference - Browse - select all 5 files.
8. F5 to run - Press Button1 - it should start swriter.
9. The .exe is in the release folder of the VB project.