麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

Aspose.Words:如何添加另一個WORD文檔中的Node對象

2019-11-17 02:55:56
字體:
來源:轉載
供稿:網友

aspose.Words:如何添加另一個WORD文檔中的Node對象

首先看一段代碼,這段代碼意圖從docSource中獲取第一個表格,并插入docTarget的末尾:

1 var table = (Table)docSource.GetChild(NodeType.Table, 0, true);2 docTarget.FirstSection.Body.ChildNodes.Add(table);

這段代碼會拋出異常:“The newChild was created from a different document than the one that created this node.”,這是什么原因呢?

原因是,對于Aspose.Words的Node對象,它的一系列樣式和格式的控制,取決于它所在的DocumentBase父對象,這也是很多Aspose.Words對象聲明時,必須指定它的DocumentBase參數,比如聲明一個Table,應該如下:

1 Document doc=new Document();2 Table table=new Table(doc);

那么,我們有沒有辦法添加另一個文檔中的對象呢?有,必須通過Document.ImportNode方法或者使用NodeImporter對象。

這兩種方法思路都是將源文檔中的Node導入到目標文檔中,再追加Node到合適的位置。

Document.ImportNode
 1 /// <summary> 2 /// A manual implementation of the Document.AppendDocument function which shows the general  3 /// steps of how a document is appended to another. 4 /// </summary> 5 /// <param name="dstDoc">The destination document where to append to.</param> 6 /// <param name="srcDoc">The source document.</param> 7 /// <param name="mode">The import mode to use when importing content from another document.</param> 8 public void AppendDocument(Document dstDoc, Document srcDoc, ImportFormatMode mode) 9 {10     // Loop through all sections in the source document. 11     // Section nodes are immediate children of the Document node so we can just enumerate the Document.12     foreach (Section srcSection in srcDoc)13     {14         // Because we are copying a section from one document to another, 15         // it is required to import the Section node into the destination document.16         // This adjusts any document-specific references to styles, lists, etc.17         //18         // Importing a node creates a copy of the original node, but the copy19         // is ready to be inserted into the destination document.20         Node dstSection = dstDoc.ImportNode(srcSection, true, mode);21 22         // Now the new section node can be appended to the destination document.23         dstDoc.AppendChild(dstSection);24     }25 }
NodeImporter
 1 public static Document GenerateDocument(Document srcDoc, ArrayList nodes) 2         { 3             // Create a blank document. 4             Document dstDoc = new Document(); 5             // Remove the first paragraph from the empty document. 6             dstDoc.FirstSection.Body.RemoveAllChildren(); 7  8             // Import each node from the list into the new document. Keep the original formatting of the node. 9             NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting);10 11             foreach (Node node in nodes)12             {13                 Node importNode = importer.ImportNode(node, true);14                 dstDoc.FirstSection.Body.AppendChild(importNode);15             }16 17             // Return the generated document.18             return dstDoc;19         }

參考文檔:

http://www.aspose.com/docs/display/wordsnet/Aspose.Words.DocumentBase.ImportNode+Overload_1


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久草手机在线观看视频 | 日韩 综合 | 久久精品亚洲欧美日韩精品中文字幕 | 香蕉视频破解 | 日韩黄站| 欧美亚成人 | 欧美国产精品久久 | 神马福利电影 | 中文字幕在线观看精品 | 天天看成人免费毛片视频 | 成人午夜久久 | 国产精品自拍片 | 日本网站在线播放 | 国产日韩免费观看 | 亚洲视频在线视频 | 国产高潮国产高潮久久久91 | 国产精品久久久久久久久岛 | 久久网站热最新地址4 | 国产一级淫片免费看 | 日韩在线欧美在线 | 69av导航 | 国产精品久久久网站 | 国产美女视频一区二区三区 | 又黄又爽又色无遮挡免费 | 暴力肉体进入hdxxxx0 | 国产精品欧美久久久久一区二区 | 国产精品啪一品二区三区粉嫩 | 欧美日韩在线播放一区 | 久久一区二区三区av | 成人精品 | 久久亚洲精品久久国产一区二区 | 黑人操穴 | gril hd| www.狠狠插.com | 一级大片久久 | 美女福利视频国产 | 黄色大片网站在线观看 | 国产一区二区三区四区精 | 久草视频免费 | 欧美亚洲国产一区二区三区 | 日本一级黄色毛片 |