我有一个带有这样的合并字段的 Word 文档模板。我需要用<<History>>
一个字符串列表替换它,但结果我得到了这个.
这是我的代码:
public static byte[] GetPdfReport(Template template, int id, string user)
{
var onc = GetData(id, user);
var document = new Document();
using (var source = new MemoryStream(content))
{
document.LoadFromStream(source, format);
}
document.MailMerge.ClearFields = true;
...
var myViewModel = new MyViewModel();
myViewModel.Histories = new List<string>();
foreach (var oncHistory in onc.History)
{
myViewModel.Histories.Add($"{oncHistory.Azione} {oncHistory.Autore} {oncHistory.Data} {oncHistory.Commento}");
}
document.MailMerge.Execute(myViewModel);
document.ViewSetup.DocumentViewType = DocumentViewType.PrintLayout;
byte[] result;
using (var ms = new MemoryStream())
{
document.SaveToStream(ms, FileFormat.PDF);
result = ms.ToArray();
}
document.Close();
return result;
}
有什么建议我该如何解决?