我需要在OpenOffice中使用C ++,VBScript,VB.Net或C#通过OLE或本机API进行简单的邮件合并。有没有好的例子?
答案 0 :(得分:9)
我还没有想出一个我真的很满意的解决方案,但这里有一些注意事项:
Q值。什么是邮件合并的OO API?
一个。 http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html
Q值。有哪些支持小组?
一个。 http://user.services.openoffice.org/en/forum/viewforum.php?f=20
Q值。示例代码?
一个。 http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=946&p=3778&hilit=mail+merge#p3778
Q值。还有更多例子吗?
一个。 file:/// C:/Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html(附带SDK)
Q值。我如何构建示例?
一个。例如,对于WriterDemo(C:\ Program Files \ OpenOffice.org_2.4_SDK \ examples \ CLI \ VB.NET \ WriterDemo)
Q值。 OO是否使用相同的单独数据/文档文件进行邮件合并?
一个。它允许包括csv文件在内的一系列数据源
Q值。 OO是否允许您合并到所有不同类型(传真,电子邮件,新文档打印机)?
一个。您可以合并到新文档,打印并通过电子邮件发送
Q值。你可以添加自定义字段吗?
一个。是
Q值。如何在VB.Net中创建新文档?
一个。
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值。你如何保存文件?
一个。
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值。你如何打开文件?
一个。
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中启动邮件合并?
一个。
不知道。此功能在API参考中,但在IDL中缺失。我们可能会略微搞砸。假设API正在运行,看起来运行合并非常简单。
在VBScript中:
设置objServiceManager = WScript.CreateObject(“com.sun.star.ServiceManager”)
'现在使用从该文档中提取的设置设置新的MailMerge 设置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'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(阵列())
在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]() {})
同样的事情,但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
答案 1 :(得分:2)
您应该查看 Apache OpenOffice API 。用于为Open Office创建API的项目。他们声称支持的几种语言是:C ++,Java,Python,CLI,StarBasic,JavaScript和OLE。