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

问题描述

我需要在OpenOffice中使用C ++,VBScript,VB.Net或C#通过OLE或本机API进行简单的邮件合并。有没有好的例子?

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。什么是用于邮件合并的OO API?

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

A。

什么支持组?

A。

Q。示例代码?

A。

Q。还有更多的例子吗?

Q. Any more examples?

A。 file:/// C:/Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html(自带SDK)

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

Q。如何构建示例?

A。例如,对于WriterDemo(C:\Program Files\OpenOffice.org_2.4_SDK\examples\CLI\VB.NET\WriterDemo)

A. e.g., for 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对邮件合并使用相同的单独数据/文档文件吗?

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

    A。它允许一系列数据源,包括csv文件

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

    Q。 OO是否允许您合并到所有不同类型(传真,电子邮件,新文档打印机)?

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

    A。您可以合并到新文档,打印并通过电子邮件发送

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

    Q。您可以添加自定义字段吗?

    Q. Can you add custom fields?

    A。是

    Q。如何在VB.Net中创建新文档?

    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。如何储存文件?

  • 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。如何打开文档?

  • 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)
    


  • 如何在VB.Net中启动邮件合并?

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

    A。


    1. 不知道。此功能在API参考中,但在IDL中缺失。我们可能会轻微拧。

    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.

    在VBScript中:

    In VBScript:

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

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

    现在使用从该文档中提取的设置设置一个新的MailMerge
    Set oMailMerge = objServiceManager.createInstance(com.sun.star.text.MailMerge)

    'Now set up a new MailMerge using the settings extracted from that docSet oMailMerge = objServiceManager.createInstance("com.sun.star.text.MailMerge")

    oMailMerge.DocumentURL =file:/// C:/ Users / me / Desktop / OpenOffice Investigation / mail merged.odt
    oMailMerge.DataSourceName =添加
    oMailMerge.CommandType = 0'
    oMailMerge.Command =adds
    oMailMerge.OutputType = 2'
    oMailMerge.execute(Array())

    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#CommandTypeoMailMerge.Command = "adds"oMailMerge.OutputType = 2 ' http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html#OutputTypeoMailMerge.execute(Array())

    在VB.Net
    $ b

    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]() {})
    


  • 同样的事情,但是选项严格开(不起作用)

  • 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中进行简单的邮件合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    09-15 20:39