- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正面临有关 MS Word 的 MailMerge 功能的问题。
我不得不将旧的 VBA 应用程序重写为 C#。我几乎已经完成了。新应用程序工作正常。
除了一个我无法摆脱的 PopUp。
因此,过去 2 天我一直在网上四处寻找,因为我们的客户不希望该弹出窗口出现,因为它在旧应用程序中不存在。
但是我找不到合适的解决方案。除了少数人提到可能连接字符串不正确。但我发现没有资源告诉我它在 C# 代码中的外观
这是它在旧应用程序中的外观:
Word.ActiveDocument.MailMerge.OpenDataSource Name:=strSourceDoc, ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:="", _
Revert:=False, Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=" & strSourceDoc & ";Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";" _
, SQLStatement:="SELECT * FROM `Tabelle1$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
mailApp.ActiveDocument.MailMerge.OpenDataSource(processedPath + file, true, false, true,
true, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=" +
processedPath + file + ";Mode=Read;",
"SELECT * FROM 'Tabelle1$'",
ref oMissing, ref oMissing, ref oMissing,
Word.WdMergeSubType.wdMergeSubTypeAccess);
最佳答案
所以我找到了一个解决方案,它以某种方式起作用。
实际问题(至少从我测试的情况来看)是文件扩展名而不是连接字符串。我使用 .xlsx 文件作为我的源文件。但是,一旦我使用一些 xls 文件进行测试,弹出窗口就消失了。
我刚刚参加了一个“谷歌 session ”来找出 xls 和 xlsx 之间的区别。
所以我可以更改我的代码以仅使用 xls 文件。问题解决了。但对我来说仍然是一个令人不快的解决方案。
如果您想进行一些测试以使其与 xlsx 一起使用。这是一些要测试的代码(只需将其绑定(bind)在winforms中的按钮单击或其他东西上)
class PerformMailMerge
{
Word.Application mailApp;
Object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;
string _path = @"Your Path to Excel File";
string savePath = @"Your Path to Word Document";
public void mailMerge2()
{
mailApp = new Word.Application();
mailApp.Visible = false;
mailApp.Documents.Add();
mailApp.ActiveDocument.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdMailingLabels;
//OpenDataSource:
mailApp.ActiveDocument.MailMerge.OpenDataSource(_path,
Word.WdOpenFormat.wdOpenFormatAllWordTemplates, true, true, true,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, "TABLE Tabelle1$", "SELECT * FROM `Tabelle1$",
ref oMissing, ref oMissing,
Word.WdMergeSubType.wdMergeSubTypeWord2000);
mailApp.ActiveDocument.SaveAs2(savePath);
mailApp.ActiveDocument.Close();
mailApp.Quit();
}
}
关于c# - MailMerge:从 Excel 到 Word C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50736240/
显然,我们的应用程序基于模板生成 Word 文档的正确方法是鼓励管理员用户(负责管理模板)在模板文档中嵌入正确的合并字段或书签。 但是,在过去,我们发现我们的典型管理员用户通常不使用 MailMerg
我的宏需要帮助。我需要通过邮件合并保存生成的 Word 文件。 Sub RunMerge() Dim wd As Object Dim wdocSource As Object Dim strWork
下午好, 我已经设置了一个宏来基于这个线程(Automating Mail Merge using Excel VBA)生成单独的证书。但是宏总是表现不规律,一天工作,第二天向我抛出错误。 我得到的最
是否可以在 FieldMergingCallback 中检索字段大小、计算字体大小并更改合并文本的字体大小? 在我的模板中,我有固定大小单元格的表格。表不能增长。 因此,当我将长文本放入单元格时,当文
我目前正面临有关 MS Word 的 MailMerge 功能的问题。 我不得不将旧的 VBA 应用程序重写为 C#。我几乎已经完成了。新应用程序工作正常。 除了一个我无法摆脱的 PopUp。 因此,
我有一个包含 MailMerge 字段的文档,但是我不想使用整个数据源->mailmerge 的想法。相反,我在 Autonew() 上呈现一个用户窗体,并要求用户在字段中输入数据。 原因是因为该文档
我正在开发一个Python脚本,它分析Excel文件,并基于使用mailmerge库用多个变量填充docx文件。对于字符串值,一切正常,但我在将图像插入文件时遇到问题。由于我现在必须从 7 个图像中进
我目前正在制作一个 MailMerge 文件并希望显示一个字符串列表。在过去,我使用了一个对象列表(例如 Customer)并且能够在 Word-doc 中包含这样的内容: {{ #foreach C
我正在尝试在一些工作表数据、文档模板和最终文档模板之间创建合并。 主要是,我可以像这样访问这些文件: var contratotemplate = DocumentApp.openById(con
我是一名优秀的程序员,十分优秀!