/// <summary> /// 添加到文档 /// </summary> /// <param name="srcDoc"></param> /// <param name="includeSection"></param> public void appendDoc(Document srcDoc, bool includeSection) { // Loop through all sections in the source document. // Section nodes are immediate children of the Document node so we can // just enumerate the Document. if (includeSection) { foreach (Section srcSection in srcDoc.Sections) { Node dstNode = WordDoc.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles); WordDoc.AppendChild(dstNode); } } else { //find the last paragraph of the last section Node node = WordDoc.LastSection.Body.LastParagraph; if (node == null) { node = new Paragraph(srcDoc); WordDoc.LastSection.Body.AppendChild(node); } if ((node.NodeType != NodeType.Paragraph) & (node.NodeType != NodeType.Table)) { throw new Exception("Use appendDoc(dstDoc, srcDoc, true) instead of appendDoc(dstDoc, srcDoc, false)"); } insertDocumentAfterNode(node, srcDoc); } }