happyqiang

博客园 首页 新随笔 联系 订阅 管理

一:某表格后面要复制n个表格:

int copytbs = buildnumlist.Count - 1;
                    Aspose.Words.Tables.Table tb = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 1, true);
                    for (int i = 0; i < copytbs; i++)
                    {
                        //创建段落
                        Paragraph lastParagraph = new Paragraph(doc);
                        //第一个表格末尾加段落
                        tb.ParentNode.InsertAfter(lastParagraph, tb);
                        //
                        Run pageBreakRun = new Run(doc, ControlChar.PageBreak);
                        lastParagraph.AppendChild(pageBreakRun);
                        Aspose.Words.Tables.Table cloneTable = (Aspose.Words.Tables.Table)tb.Clone(true);
                        //在文档末尾段落后面加入复制的表格
                        tb.ParentNode.InsertAfter(cloneTable, lastParagraph);
                        lastParagraph = new Aspose.Words.Paragraph(doc);
                    }
                    tb = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
                    for (int i = 0; i < copytbs; i++)
                    {
                        //创建段落
                        Paragraph lastParagraph = new Paragraph(doc);
                        //第一个表格末尾加段落
                        tb.ParentNode.InsertAfter(lastParagraph, tb);
                        //
                        Run pageBreakRun = new Run(doc, ControlChar.PageBreak);
                        lastParagraph.AppendChild(pageBreakRun);
                        Aspose.Words.Tables.Table cloneTable = (Aspose.Words.Tables.Table)tb.Clone(true);
                        //在文档末尾段落后面加入复制的表格
                        tb.ParentNode.InsertAfter(cloneTable, lastParagraph);
                        lastParagraph = new Aspose.Words.Paragraph(doc);
                    }
在某表格后循环插入新页表格

二:一次性复制页:

 Aspose.Words.Document docpage = AsposeWordHelper.GetDocPage(doc, 1);
                    //先一次性复制表格页:
                    for (int i = 1; i < buildnumlist.Count; i++)
                    {
                        doc.AppendDocument(docpage, ImportFormatMode.KeepSourceFormatting);
                    }
一次性复制某页

 

posted on 2022-03-30 10:06  妙堂传奇  阅读(481)  评论(0编辑  收藏  举报