4

C++、VBScript、VB.Net、または OLE またはネイティブ API 経由の C# を使用して、OpenOffice で簡単な差し込み印刷を行う必要があります。利用可能な良い例はありますか?

4

2 に答える 2

9

私は本当に満足している解決策を思い付いていませんが、ここにいくつかのメモがあります:

  • Q. 差し込み印刷用の OO API とは何ですか?

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

  • Q. 支援団体は?

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

  • Q. サンプルコードは?

    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

  • Q. 他に例はありますか?

    A. file:///C:/Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html (SDK に付属)

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

  • Q. サンプルをビルドするにはどうすればよいですか?

    A. 例: WriterDemo の場合 (C:\Program Files\OpenOffice.org_2.4_SDK\examples\CLI\VB.NET\WriterDemo)

    1. ここにすべてへの参照を追加します: C:\Program Files\OpenOffice.org 2.4\program\assembly
    2. つまり、cli_basetypes、cli_cppuhelper、cli_types、cli_ure です。
  • Q. OO は差し込み印刷に同じ別のデータ/ドキュメント ファイルを使用しますか?

    A. csv ファイルを含むさまざまなデータ ソースを使用できます。

  • Q. OO では、すべての異なるタイプ (ファックス、電子メール、新規ドキュメント プリンター) にマージできますか?

    A. 新しいドキュメントにマージし、印刷して電子メールで送信できます

  • Q. カスタムフィールドを追加できますか?

    A.はい

  • Q. 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. ドキュメントの保存方法を教えてください。

    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. どのようにドキュメントを開きますか?

    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. VB.Net で差し込み印刷を開始するにはどうすればよいですか?

    A.

    1. わからない。この機能は API リファレンスにはありますが、IDL にはありません。私たちは少しねじ込まれているかもしれません。API が機能していると仮定すると、マージの実行は非常に簡単に見えます。

    2. VBScript の場合:

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

      'そのドキュメントから抽出した設定を使用して、新しい MailMerge をセットアップします 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())

    3. 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]() {})
      
    4. 同じことですが、Option Strict On (機能しません)

          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
      
于 2008-09-03T22:34:34.027 に答える
2

Apache OpenOffice APIをご覧ください。Open Office の API を作成するためのプロジェクト。彼らがサポートすると述べたいくつかの言語は、C++、Java、Python、CLI、StarBasic、JavaScript、および OLE です。

OpenOffice での差し込み印刷の Java の例

于 2008-09-02T07:25:45.577 に答える