我需要通过 OLE 或 native API 使用 C++、VBScript、VB.Net 或 C# 在 OpenOffice 中进行简单的邮件合并。有什么好的例子吗?
最佳答案
我还没有想出一个我非常满意的解决方案,但这里有一些注意事项:
A. http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html
A. http://user.services.openoffice.org/en/forum/viewforum.php?f=20
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
A. file:///C:/Program%20Files/OpenOffice.org_2.4_SDK/examples/examples.html(SDK自带)
http://www.oooforum.org/forum/viewtopic.phtml?p=94970
A. 例如,对于 WriterDemo (C:\Program Files\OpenOffice.org_2.4_SDK\examples\CLI\VB.NET\WriterDemo)
A. 它允许一系列数据源,包括 csv 文件
A. 您可以合并到一个新文档,打印并通过电子邮件发送
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)
一种。
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)
一种。
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)
一种。
设置 objServiceManager = WScript.CreateObject("com.sun.star.ServiceManager")
'现在使用从该文档中提取的设置设置一个新的 MailMerge
设置 oMailMerge = objServiceManager.createInstance("com.sun.star.text.MailMerge")
oMailMerge.DocumentURL = "file:///C:/Users/me/Desktop/OpenOffice调查/邮件合并.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(Array())
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]() {})
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
关于c# - 如何在 OpenOffice 中进行简单的邮件合并,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38842/