【问题标题】:ASPOSE.Word - Creation of a bibliography using a custom sourceASPOSE.Word - 使用自定义来源创建参考书目
【发布时间】:2022-01-22 20:32:25
【问题描述】:

我来找你是因为作为项目的一部分,我必须尽可能使用 Aspose.Word 和 .NET 将参考书目添加到 Word 文档中。

我真的不知道该怎么做,因为文档非常稀少,而且网上几乎没有帮助。因此,我把它留给你问你如何到达那里。

这是我的实际代码:

                    CustomXmlPart xmlPart = document.CustomXmlParts.Add("Books",
                        "<books>" +
                            "<book>" +
                                "<title>Everyday Italian</title>" +
                                "<author>Giada De Laurentiis</author>" +
                            "</book>" +
                            "<book>" +
                                "<title>The C Programming Language</title>" +
                                "<author>Brian W. Kernighan, Dennis M. Ritchie</author>" +
                            "</book>" +
                            "<book>" +
                                "<title>Learning XML</title>" +
                                "<author>Erik T. Ray</author>" +
                            "</book>" +
                        "</books>");

                    StructuredDocumentTag sdtBiblio = new StructuredDocumentTag(document, SdtType.Bibliography, MarkupLevel.Row);
                    sdtBiblio.XmlMapping.SetMapping(xmlPart, "/books[1]/book", string.Empty);

【问题讨论】:

    标签: c# .net aspose.words bibliography


    【解决方案1】:

    在 MS Word 中使用 BIBLIOGRAPHY 字段。不幸的是,Aspose.Words 不支持更新这种类型的字段。但是,您可以使用结构化文档标签实现类似的效果。例如看下面的代码:

    Document document = new Document();
    
    CustomXmlPart xmlPart = document.CustomXmlParts.Add("Books",
    "<books>" +
        "<book>" +
            "<title>Everyday Italian</title>" +
            "<author>Giada De Laurentiis</author>" +
        "</book>" +
        "<book>" +
            "<title>The C Programming Language</title>" +
            "<author>Brian W. Kernighan, Dennis M. Ritchie</author>" +
        "</book>" +
        "<book>" +
            "<title>Learning XML</title>" +
            "<author>Erik T. Ray</author>" +
        "</book>" +
    "</books>");
    
    StructuredDocumentTag sdtTitle = new StructuredDocumentTag(document, SdtType.RichText, MarkupLevel.Inline);
    sdtTitle.XmlMapping.SetMapping(xmlPart, "/books[1]/book/title", string.Empty);
    
    StructuredDocumentTag sdtAuthor = new StructuredDocumentTag(document, SdtType.RichText, MarkupLevel.Inline);
    sdtAuthor.XmlMapping.SetMapping(xmlPart, "/books[1]/book/author", string.Empty);
    sdtAuthor.ContentsFont.Italic = true;
    
    DocumentBuilder builder = new DocumentBuilder(document);
    builder.InsertNode(sdtTitle);
    builder.Write(" ");
    builder.InsertNode(sdtAuthor);
    
    document.Save(@"C:\temp\out.docx");
    

    这个想法是将自定义 XML 的每个部分放入一个单独的结构化文档标记中并应用适当的格式。

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 2014-01-25
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多