So erstellen Sie einen einfachen Seriendruck in OpenOffice
-
09-06-2019 - |
Frage
Ich muss einen einfachen Seriendruck in OpenOffice mit C++, VBScript, VB.Net oder C# über OLE oder eine native API durchführen.Gibt es gute Beispiele?
Lösung
Ich habe keine Lösung gefunden, mit der ich wirklich zufrieden bin, aber hier sind einige Anmerkungen:
Q.Was ist die OO-API für den Seriendruck?
A. http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html
Q.Welche Selbsthilfegruppen?
A. http://user.services.openoffice.org/en/forum/viewforum.php?f=20
Q.Beispielcode?
A. http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=946&p=3778&hilit=mail+merge#p3778
Q.Noch mehr Beispiele?
A.file:///C:/Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html (wird mit dem SDK geliefert)
Q.Wie baue ich die Beispiele auf?
A.z. B. für WriterDemo (C:\Programme\OpenOffice.org_2.4_SDK\examples\CLI\VB.NET\WriterDemo)
- Fügen Sie hier Verweise auf alles hinzu:C:\Programme\OpenOffice.org 2.4\program\assembly
- Das sind cli_basetypes, cli_cppuhelper, cli_types, cli_ure
Q.Verwendet OO dieselbe separate Daten-/Dokumentdatei für den Serienbrief?
A.Es ermöglicht eine Reihe von Datenquellen, einschließlich CSV-Dateien
Q.Ermöglicht OO die Zusammenführung aller verschiedenen Typen (Fax, E-Mail, neuer Dokumentendrucker)?
A.Sie können es in ein neues Dokument einfügen, ausdrucken und per E-Mail versenden
Q.Können Sie benutzerdefinierte Felder hinzufügen?
A.Ja
Q.Wie erstellt man ein neues Dokument 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)
Q.Wie speichert man das Dokument?
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)
Q.Wie öffnet man das Dokument?
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)
Q.Wie initiieren Sie einen Seriendruck in VB.Net?
A.
Ich weiß es nicht.Diese Funktionalität ist in der API-Referenz enthalten, fehlt jedoch in der IDL.Wir sind vielleicht etwas durcheinander.Unter der Annahme, dass die API funktioniert, sieht es so aus, als wäre die Durchführung einer Zusammenführung recht einfach.
In VBScript:
Set objServiceManager = WScript.CreateObject("com.sun.star.ServiceManager")
Richten Sie nun einen neuen Seriendruck mit den Einstellungen ein, die aus diesem Dokument extrahiert wurden Set oMailMerge = objServiceManager.createInstance("com.sun.star.text.MailMerge")
oMailMerge.DocumentURL = "file:///C:/Users/me/Desktop/OpenOffice Untersuchung/Serien-E-Mail.odt" oMailMerge.DataSourceName = "addiert" oMailMerge.CommandType = 0 ' http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#CommandType oMailMerge.Command = "hinzufügt" oMailMerge.OutputType = 2 ' http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#OutputTypeoMailMerge.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]() {})
Das Gleiche, aber mit Option Strict On (funktioniert nicht)
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
Andere Tipps
Schauen Sie sich das mal an Apache OpenOffice-API.Ein Projekt zur Erstellung einer API für Open Office.Einige Sprachen, die sie angeblich unterstützen, sind:C++, Java, Python, CLI, StarBasic, JavaScript und OLE.