从 C# ASP.NET 中的数据集进行邮件合并
Posted
技术标签:
【中文标题】从 C# ASP.NET 中的数据集进行邮件合并【英文标题】:Mail Merge from a dataset in C# ASP.NET 【发布时间】:2009-10-14 12:49:12 【问题描述】:我是 OpenOffice 的新手,并且已经阅读了很多关于它的文章。我需要在 C# 中编写邮件合并功能,以指示 OpenOffice 对提供的文档执行邮件合并。我已经看到很多使用 VB.NET 的邮件合并示例,但是当我将 VB 转换为 C# 时,它的邮件合并组件总是无法正确创建。我的代码如下。我已经注释掉了邮件合并代码,因为它不能与它一起编译。我将如何更正代码以便它执行邮件合并?
public int InitialiseOpenOffice()
// This is the document with the mail merge tags in that I want to be used as the source.
string filePathStr = "file:///C:/DotNetDev/MailMerge//MailMergeSample.doc";
Type openOffice;
openOffice = Type.GetTypeFromProgID("com.sun.star.ServiceManager");
object objServiceManager = System.Activator.CreateInstance(openOffice);
// arguments for IDispatch-call
object[] parameters = new object[1];
parameters[0] = "com.sun.star.frame.Desktop";
// arguments for document
object[] args = new object[4];
args[0] = "private:factory/swriter";
args[1] = "_blank";
args[2] = 0;
args[3] = new object[] ;
// arguments for document
object[] existingargs = new object[4];
existingargs[0] = filePathStr;
existingargs[1] = "_blank";
existingargs[2] = 0;
existingargs[3] = new object[] ;
object startdesktop;
object doc;
try
startdesktop = (object)openOffice.InvokeMember("createInstance",
BindingFlags.InvokeMethod, null,
objServiceManager, parameters);
doc = startdesktop.GetType().InvokeMember("loadComponentFromUrl",
BindingFlags.InvokeMethod, null, startdesktop, existingargs);
object openOfficeServiceManagerObj = System.Activator.CreateInstance(openOffice);
// arguments for MailMerge
object[] mailMergeParameters = new object[1];
mailMergeParameters[0] = "com.sun.star.text.MailMerge";
//
//
// All the code up to this point works, but the code below doesn't. At this
// point OponOffice is open with the document I want to use in the mailmerge.
//
//
//Type t_OOo;
//t_OOo = Type.GetTypeFromProgID("com.sun.star.ServiceManager");
//objServiceManager = System.Activator.CreateInstance(t_OOo);
//object oMailMerge;
//oMailMerge = t_OOo.InvokeMember("createInstance", BindingFlags.InvokeMethod, null, objServiceManager, new Object[] "com.sun.star.text.MailMerge" );
//oMailMerge.DocumentURL = "file:///C:/Users/me/Desktop/OpenOffice Investigation/mail merged.odt";
//oMailMerge.DataSourceName = "adds";
//oMailMerge.CommandType = 0;
//oMailMerge.Command = "adds";
//oMailMerge.OutputType = 2;
//oMailMerge.execute(new Object[] );
if (doc == null)
return 1; // error!!
catch (Exception e)
string s = e.Message;
return 1;
return 0;
【问题讨论】:
【参考方案1】:看起来这个问题已经在Mailmerge using OpenOffice...
【讨论】:
我已经看过这个 URL,它没有告诉你如何进行实际的邮件合并,它似乎只是绕过了主题。以上是关于从 C# ASP.NET 中的数据集进行邮件合并的主要内容,如果未能解决你的问题,请参考以下文章
从 Twitter API 获取用户的电子邮件以进行外部登录身份验证 ASP.NET MVC C#
发送包含存储在数据库中的多个附件的电子邮件(ASP.NET C#)
ASP.NET C# 如何合并DataTable中的重复数据(做数据整合)
如何在 ASP.NET C# 中检索程序集信息窗口的文件版本 [重复]