Domanda

Devo eseguire una semplice stampa unione in OpenOffice utilizzando C++, VBScript, VB.Net o C# tramite OLE o API nativa.Ci sono buoni esempi disponibili?

È stato utile?

Soluzione

Non ho trovato una soluzione di cui sono davvero soddisfatto, ma ecco alcune note:

  • Q.Cos'è l'API OO per la stampa unione?

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

  • Q.Quali gruppi di sostegno?

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

  • Q.Codice d'esempio?

    UN. 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

  • Q.Altri esempi?

    UN.file:///C:/Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html (fornito con l'SDK)

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

  • Q.Come costruisco gli esempi?

    UN.ad esempio, per WriterDemo (C:\Program Files\OpenOffice.org_2.4_SDK\examples\CLI\VB.NET\WriterDemo)

    1. Aggiungi riferimenti a tutto qui:C:\Programmi\OpenOffice.org 2.4\programma\assembly
    2. Cioè cli_basetypes, cli_cppuhelper, cli_types, cli_ure
  • Q.OO utilizza lo stesso file di dati/documenti separato per la stampa unione?

    UN.Consente una gamma di origini dati inclusi file CSV

  • Q.OO ti consente di unire tutti i diversi tipi (fax, e-mail, nuova stampante per documenti)?

    UN.È possibile unirli in un nuovo documento, stamparlo e inviarlo tramite e-mail

  • Q.Puoi aggiungere campi personalizzati?

    UN.SÌ

  • Q.Come si crea un nuovo documento in VB.Net?

    UN.

            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.Come si salva il documento?

    UN.

            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.Come si apre il documento?

    UN.

            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.Come si avvia una stampa unione in VB.Net?

    UN.

    1. Non lo so.Questa funzionalità è nel riferimento API ma manca nell'IDL.Potremmo essere leggermente fregati.Supponendo che l'API funzioni, sembra che eseguire un'unione sia abbastanza semplice.

    2. In VBScript:

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

      'Ora impostare un nuovo Mailmerge utilizzando le impostazioni estratte da quel set Doc OmailMerge = ObjserviceManager.CreateInstance ("com.sun.star.text.mailmerge")

      omailmerge.documentUrl = "File: /// C:/Users/Me/Desktop/OpenOffice Investigation/Mail Malged.odt" omailmerge.datasourcename = "aggiunge" omailmerge.commandtype = 0 ' http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#CommandTypeomailmerge.command = "aggiunge" omailmerge.outputType = 2 ' http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#OutputTypeoMailMerge.execute(Array())

    3. In VB.Net (opzione rigorosamente disattivata)

          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]() {})
      
    4. La stessa cosa ma con Option Strict On (non funziona)

          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
      

Altri suggerimenti

Dovresti dare un'occhiata API Apache OpenOffice.Un progetto per la creazione di un'API per Open Office.Alcune lingue che hanno detto di supportare sono:C++, Java, Python, CLI, StarBasic, JavaScript e OLE.

Java Esempio di mailmerge in OpenOffice.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top