如何做到在OpenOffice的一个简单的邮件合并 [英] How to do a simple mail merge in OpenOffice

查看:417
本文介绍了如何做到在OpenOffice的一个简单的邮件合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用C ++做一个简单的邮件合并的OpenOffice中的VBScript,VB.Net或C#通过OLE或本机API。有没有什么好的例子可用?


解决方案

我还没有拿出一个解决方案,我真的很高兴,但用在这里一些注意事项:




  • 问:什么是邮件合并OO API?



    一个。 http://api.openoffice.org/docs/common/ref/ COM /阳光/明星/文/ MailMerge.html


  • 问:哪些支持小组?



    一个。 http://user.services.openoffice.org/en/forum/viewforum.php? F = 20


  • 问:示例代码?



    一个。 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


  • 问:更多的例子吗?



    一个。文件:/// C:/Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html(随SDK)



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


  • 问:如何构建的例子吗?



    一个。例如,对于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


  • 问: OO是否使用相同的单独的数据/文档文件进行邮件合并?



    一个。它允许多种数据源,包括CSV文件


  • 问。面向对象是否让你合并所有不同类型(传真,电子邮件,新的文件打印机)?



    一个。您可以合并到一个新文档,打印和电子邮件


  • 问:您可以添加自定义字段?



    一个。是


  • 问:你如何在VB.Net创建一个新的文件?



    一个。

     昏暗xContext作为XComponentContext 


      xContext = Bootstrap.bootstrap()


    昏暗xFactory作为XMultiServiceFactory
    xFactory = DirectCast(xContext.getServiceManager(),_
    XMultiServiceFactory)


    '创建b尺寸xDesktop桌面$ b $作为UNOIDL。 com.sun.star.frame.XDesktop
    xDesktop = DirectCast(xFactory.createInstance(com.sun.star.frame.Desktop),_
    unoidl.com.sun.star.frame.XDesktop )


    '打开一个新的空Writer文档
    昏暗xComponentLoader作为unoidl.com.sun.star.frame.XComponentLoader
    xComponentLoader = DirectCast(xDesktop,UNOIDL。 com.sun.star.frame.XComponentLoader)
    尺寸arProps()作为unoidl.com.sun.star.beans.PropertyValue = _
    新unoidl.com.sun.star.beans.PropertyValue() {}
    昏暗xComponent作为unoidl.com.sun.star.lang.XComponent
    xComponent = xComponentLoader.loadComponentFromURL(_
    私:工厂/ swriter,_blank,0,arProps )
    昏暗xTextDocument作为unoidl.com.sun.star.text.XTextDocument
    xTextDocument = DirectCast(xComponent,unoidl.com.sun.star.text.XTextDocument)




  • 问:你如何保存文档?



    一个。

     暗淡斯托勒由于unoidl.com.sun.star.frame.XStorable = DirectCast(xTextDocument,unoidl.com.sun.star.frame.XStorable)
    arProps =新unoidl.com.sun.star.beans.PropertyValue(){ }
    storer.storeToURL(文件:/// C:/用户/我/桌面/ OpenOffice的调查/保存doc.odt,arProps)


  • 问:你怎么开?



    一个。

     暗淡xComponent文档由于unoidl.com.sun.star.lang.XComponent 
    xComponent = xComponentLoader.loadComponentFromURL(_
    文件:/// C:/用户/我/桌面/ OpenOffice的调查/保存doc.odt _blank,0,arProps)


  • 问:你如何在VB.Net启动邮件合并?



    一个。




    1. 不知道。此功能在API的参考,但是从IDL失踪。我们可能会稍微拧紧。假设API是工作,它看起来像运行合并是相当简单


    2. 在VBScript中:



      设置objServiceManager = WScript.CreateObject(com.sun.star.ServiceManager)



      现在设置使用从DOC $ b提取设置一个新的邮件合并$ b将oMailMerge = objServiceManager.createInstance(com.sun.star.text.MailMerge)



      oMailMerge.DocumentURL =文件:/// C:/用户/我/桌面/ OpenOffice的调查/邮件merged.odt
      oMailMerge.DataSourceName =,增加了
      oMailMerge.CommandType = 0'的 http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#CommandType
      oMailMerge.Command =,增加了
      oMailMerge.OutputType = 2'的http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#OutputType
      oMailMerge.execute (阵列())


    3. 在VB.Net(选项严格关)

       昏暗t_OOo为类型
      t_OOo = Type.GetTypeFromProgID(com.sun.star.ServiceManager)
      昏暗objServiceManager作为对象
      objServiceManager = System.Activator.CreateInstance( t_OOo)


       昏暗oMailMerge作为对象
      oMailMerge = t_OOo.InvokeMember(createInstance建立,_
      的BindingFlags .InvokeMethod,没什么,_
      objServiceManager,新[对象](){com.sun.star.text.MailMerge})


      '现在成立了一个新的邮件合并使用来自DOC
      oMailMerge.DocumentURL =提取设置文件:/// C:/用户/我/桌面/ OpenOffice的调查/邮件merged.odt
      oMailMerge.DataSourceName =,增加了
      oMailMerge.CommandType = 0'http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#CommandType
      oMailMerge.Command =,增加了
      oMailMerge.OutputType = 2'http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#OutputType
      oMailMerge.execute(新[对象(){})




    4. 同样的事情,但与选项严格开启(不工作)

       暗淡t_OOo作为类型
      t_OOo = Type.GetTypeFromProgID(com.sun.star.ServiceManager)
      昏暗objServiceManager作为对象
      objServiceManager = System.Activator.CreateInstance(t_OOo)


       昏暗oMailMerge作为对象
      oMailMerge = t_OOo.InvokeMember(createInstance建立,_
      BindingFlags.InvokeMethod,没什么,_
      objServiceManager,新[对象](){com.sun.star.text.MailMerge})


      '现在设置使用从文档中提取的设置一个新的邮件合并
      oMailMerge.GetType()InvokeMember(DocumentURL,BindingFlags.SetProperty,没什么,oMailMerge,新[对象](){文件:/// C:/用户/我/桌面/ OpenOffice的调查/邮件merged.odt})
      oMailMerge.GetType()。InvokeMember(的datasourcename,BindingFlags.SetProperty,没什么,oMailMerge,新[对象](){补充说:})
      oMailMerge.GetType( ).InvokeMember(的CommandType,BindingFlags.SetProperty,没什么,oMailMerge,新[对象](){0})
      oMailMerge.GetType()。InvokeMember(命令,BindingFlags.SetProperty,没什么,oMailMerge,新[对象](){补充说:})
      oMailMerge.GetType()。InvokeMember(输出类型,BindingFlags.SetProperty,没什么,oMailMerge,新[对象](){2})
      oMailMerge.GetType()。InvokeMember(执行,BindingFlags.InvokeMethod或者BindingFlags.IgnoreReturn,没什么,oMailMerge,新[对象](){})'此行失败,类型不匹配错误






I need to do a simple mail merge in OpenOffice using C++, VBScript, VB.Net or C# via OLE or native API. Are there any good examples available?

解决方案

I haven't come up with a solution I'm really happy with but here are some notes:

  • Q. What is the OO API for mail merge?

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

  • Q. What support groups?

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

  • Q. Sample code?

    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. Any more 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

  • Q. How do I build the examples?

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

    1. Add references to everything in here: C:\Program Files\OpenOffice.org 2.4\program\assembly
    2. That is cli_basetypes, cli_cppuhelper, cli_types, cli_ure

  • Q. Does OO use the same separate data/document file for mail merge?

    A. It allows for a range of data sources including csv files

  • Q. Does OO allow you to merge to all the different types (fax, email, new document printer)?

    A. You can merge to a new document, print and email

  • Q. Can you add custom fields?

    A. Yes

  • Q. How do you 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)
    

  • Q. How do you save the 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)
    

  • Q. How do you Open the 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)
    

  • Q. How do you initiate a mail merge in VB.Net?

    A.

    1. Don't know. This functionality is in the API reference but is missing from the IDL. We may be slightly screwed. Assuming the API was working, it looks like running a merge is fairly simple.

    2. In VBScript:

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

      'Now set up a new MailMerge using the settings extracted from that doc 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. 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]() {})
      

    4. The same thing but with Option Strict On (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
      

这篇关于如何做到在OpenOffice的一个简单的邮件合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆