簡體   English   中英

ASPOSE.Word - 使用自定義來源創建參考書目

[英]ASPOSE.Word - Creation of a bibliography using a custom source

我來找你是因為作為項目的一部分,我必須盡可能使用 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);

在 MS Word書目字段中使用。 不幸的是,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 的每個部分放入單獨的結構化文檔標簽中並應用適當的格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM