How to make a simple merge in OpenOffice

I need to make a simple merge in OpenOffice using C ++, VBScript, VB.Net or C # via OLE or my own API. Are there any good examples?

+4
source share
2 answers

I did not come up with a solution that I'm really happy with, but here are a few notes:

  • IN

    . What is the OO API for Mail Merge?

    a. http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html

  • IN

    . What support groups?

    a. http://user.services.openoffice.org/en/forum/viewforum.php?f=20

  • IN

    . Code example?

    a. http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=946&p=3778&hilit=mail+merge#p3778

    http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=8088&p=38017&hilit=mail+merge#p38017

  • IN

    . Any other examples?

    a. file: /// C: /Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html (comes with the SDK)

    http://www.oooforum.org/forum/viewtopic.phtml?p=94970

  • IN

    . How to create examples?

    a. e.g. for WriterDemo (C: \ Program Files \ OpenOffice.org_2.4_SDK \ examples \ CLI \ VB.NET \ WriterDemo)

    • Add links to everything here: C: \ Program Files \ OpenOffice.org 2.4 \ program \ assembly
    • These are cli_basetypes, cli_cppuhelper, cli_types, cli_ure
  • IN

    . Does OO use the same separate data / document file to merge mail?

    a. It allows you to use a variety of data sources, including csv files.

  • IN

    . Oo allows you to combine all types (fax, email, new document printer)?

    a. You can merge with a new document, print and send by email

  • IN

    . Can you add custom fields?

    a. Yes

  • IN

    . How to create a new document in VB.Net?

    a.

    Dim xContext As XComponentContext xContext = Bootstrap.bootstrap() Dim xFactory As XMultiServiceFactory xFactory = DirectCast(xContext.getServiceManager(), _ XMultiServiceFactory) 'Create the Desktop Dim xDesktop As unoidl.com.sun.star.frame.XDesktop xDesktop = DirectCast(xFactory.createInstance("com.sun.star.frame.Desktop"), _ unoidl.com.sun.star.frame.XDesktop) 'Open a new empty writer document Dim xComponentLoader As unoidl.com.sun.star.frame.XComponentLoader xComponentLoader = DirectCast(xDesktop, unoidl.com.sun.star.frame.XComponentLoader) Dim arProps() As unoidl.com.sun.star.beans.PropertyValue = _ New unoidl.com.sun.star.beans.PropertyValue() {} Dim xComponent As unoidl.com.sun.star.lang.XComponent xComponent = xComponentLoader.loadComponentFromURL( _ "private:factory/swriter", "_blank", 0, arProps) Dim xTextDocument As unoidl.com.sun.star.text.XTextDocument xTextDocument = DirectCast(xComponent, unoidl.com.sun.star.text.XTextDocument) 
  • IN

    . How to save a document?

    a.

      Dim storer As unoidl.com.sun.star.frame.XStorable = DirectCast(xTextDocument, unoidl.com.sun.star.frame.XStorable) arProps = New unoidl.com.sun.star.beans.PropertyValue() {} storer.storeToURL("file:///C:/Users/me/Desktop/OpenOffice Investigation/saved doc.odt", arProps) 
  • IN

    . How to open a document?

    a.

      Dim xComponent As unoidl.com.sun.star.lang.XComponent xComponent = xComponentLoader.loadComponentFromURL( _ "file:///C:/Users/me/Desktop/OpenOffice Investigation/saved doc.odt", "_blank", 0, arProps) 
  • IN

    . How do you start merging in VB.Net?

    a.

    • I do not know. This functionality is in the API link, but not in the IDL. We can be slightly screwed. Assuming the API works, it seems that starting a merge is pretty simple.

    • In VBScript:

      Set objServiceManager = WScript.CreateObject ("com.sun.star.ServiceManager")

      'Now configure the new MailMerge using the settings extracted from this document. Set oMailMerge = objServiceManager.createInstance ("com.sun.star.text.MailMerge")

      oMailMerge.DocumentURL = "file: /// C: / Users / me / Desktop / OpenOffice Investigation / mail merged.odt" oMailMerge.DataSourceName = "adds" oMailMerge.CommandType = 0 ' http://api.openoffice.org/ docs / common / ref / com / sun / star / text / MailMerge.html # CommandType oMailMerge.Command = "adds" oMailMerge.OutputType = 2 ' http://api.openoffice.org/docs/common/ref/com/ sun / star / text / MailMerge.html # OutputType oMailMerge.execute (Array ())

    • In VB.Net (option Strict Off)

        Dim t_OOo As Type t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager") Dim objServiceManager As Object objServiceManager = System.Activator.CreateInstance(t_OOo) Dim oMailMerge As Object oMailMerge = t_OOo.InvokeMember("createInstance", _ BindingFlags.InvokeMethod, Nothing, _ objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'Now set up a new MailMerge using the settings extracted from that doc oMailMerge.DocumentURL = "file:///C:/Users/me/Desktop/OpenOffice Investigation/mail merged.odt" oMailMerge.DataSourceName = "adds" oMailMerge.CommandType = 0 ' http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#CommandType oMailMerge.Command = "adds" oMailMerge.OutputType = 2 ' http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#OutputType oMailMerge.execute(New [Object]() {}) 
    • Same thing with the Strict On option (doesn't work)

        Dim t_OOo As Type t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager") Dim objServiceManager As Object objServiceManager = System.Activator.CreateInstance(t_OOo) Dim oMailMerge As Object oMailMerge = t_OOo.InvokeMember("createInstance", _ BindingFlags.InvokeMethod, Nothing, _ objServiceManager, New [Object]() {"com.sun.star.text.MailMerge"}) 'Now set up a new MailMerge using the settings extracted from that doc oMailMerge.GetType().InvokeMember("DocumentURL", BindingFlags.SetProperty, Nothing, oMailMerge, New [Object]() {"file:///C:/Users/me/Desktop/OpenOffice Investigation/mail merged.odt"}) oMailMerge.GetType().InvokeMember("DataSourceName", BindingFlags.SetProperty, Nothing, oMailMerge, New [Object]() {"adds"}) oMailMerge.GetType().InvokeMember("CommandType", BindingFlags.SetProperty, Nothing, oMailMerge, New [Object]() {0}) oMailMerge.GetType().InvokeMember("Command", BindingFlags.SetProperty, Nothing, oMailMerge, New [Object]() {"adds"}) oMailMerge.GetType().InvokeMember("OutputType", BindingFlags.SetProperty, Nothing, oMailMerge, New [Object]() {2}) oMailMerge.GetType().InvokeMember("Execute", BindingFlags.InvokeMethod Or BindingFlags.IgnoreReturn, Nothing, oMailMerge, New [Object]() {}) ' this line fails with a type mismatch error 
+9
source

You should take a look at the Apache OpenOffice API . API Creation Project for Open Office. Several languages โ€‹โ€‹they said support: C ++, Java, Python, CLI, StarBasic, JavaScript, and OLE.

Java An example of a mailbox in OpenOffice .

+2
source

Source: https://habr.com/ru/post/1276514/


All Articles