我目前正在开发MailMerge Word-docx。当我们有以下内容时,一切正常:
如果没有任何授权事件,我们想要的是不显示此表,因此我将其更改为以下内容:
如您所见,即使存在AuthorizationEvents,该表现在也是空的。有可能以某种方式在IF-MERGEFIELD
内使用动态表吗?这是Aspose的MailMerging中的错误,还是我做错了什么?
PS:我知道我们与{{Something}}
一起使用的MailMerge-synthax的知名度低于<<Something>>
,但它们的工作方式相同。因为我过去对MailMerge-synthax有疑问,所以只是单挑。
这是.NET代码(虽然我怀疑它与我的问题相关):
public class PrintDto
{
public PrintDto(OurObject ourObject, ProcessTimeline processTimeline)
{
...
AutorisatieEvents = GetAutorisatieEvents(processTimeline);
HeeftAutorisatieEvents = AutorisatieEvents.Any();
}
...
public IList<AutorisatieEventDto> AutorisatieEvents { get; private set; }
public bool HeeftAutorisatieEvents { get; private set; }
}
AutorisatieEventDto:
public class AutorisatieEventDto
{
public string Happened { get; set; }
public string Event { get; set; }
public string Performer { get; set; }
public string Opmerking { get; set; }
}
MailMerging代码:
public byte[] GenerateDocument(Stream template, DocumentDataSource dataSource)
{
var doc = new Document(template);
doc.MailMerge.UseNonMergeFields = true;
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveContainingFields |
MailMergeCleanupOptions.RemoveUnusedFields |
MailMergeCleanupOptions.RemoveUnusedRegions |
MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.ResourceLoadingCallback = new ImageLoadingHandler();
// Support html MailMerge-fields
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertHtml();
doc.MailMerge.Execute(dataSource);
doc.MailMerge.ExecuteWithRegions((IMailMergeDataSourceRoot) dataSource);
doc.UpdateFields();
using (var memoryStream = new MemoryStream())
{
doc.Save(memoryStream, SaveFormat.Pdf);
return memoryStream.ToArray();
}
用于:
public byte[] CreatePrintAsBytes(PrintDto printData)
{
if (printData == null) throw new ArgumentNullException("printData");
var path = Path.Combine(_templatePath, "printdto.docx");
using (var fileStream = File.OpenRead(path))
{
var dataSource = new DocumentDataSource(printData);
return DocumentConverter.GenerateDocument(fileStream, dataSource);
}
}
并显示如下:
[HttpGet]
public ActionResult Print(Guid id)
{
var ourObject = NhSession.GetByGuid<OurObject>(id);
var processTimeline = GetProcessTimelineOfOurObject(ourObject);
var printData = new PrintDto(ourObject, processTimeline);
var documentAsByteArray = _documentService.CreatePrintAsBytes(printData);
return File(documentAsByteArray, "application/pdf");
}