1

我目前正在研究 MailMerge Word-docx。当我们有以下内容时,一切正常: 在此处输入图像描述

结果是: 在此处输入图像描述


如果没有任何授权事件,我们想要不显示此表,因此我将其更改为以下内容: 在此处输入图像描述

结果如下: 在此处输入图像描述

如您所见,该表现在是空的,即使有 AuthorizationEvents。是否有可能以某种方式在内部使用动态表IF-MERGEFIELD?这是 Aspose 的 MailMerging 中的错误,还是我只是做错了什么?

PS:我知道我们使用的 MailMerge-synthax{{Something}}不如<<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; }
}

邮件合并代码:

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");
}
4

0 回答 0