zoukankan      html  css  js  c++  java
  • Aspose.Word for DotNet 定位到每页,画笔 移动到某页。

    Aspose.Word 的基础类型是Node,   并没有像Spire.Doc 那样 有直接的页对象。 所以要通过  Aspose.Words.Layout.LayoutCollector   布局收集器,来定位页面。  
    官方api   https://apireference.aspose.com/words/net/aspose.words.layout/layoutcollector

    以下代码  是实现了 在跨页表格的最后一行添加  接下页的。   主要找页的代码  如红色部分。

     1             Aspose.Words.Section section = doc.Sections[1];
     2             Aspose.Words.Tables.Table tableb = section.GetChild(NodeType.Table, 1, true) as Aspose.Words.Tables.Table;
     3             int pageCount = doc.PageCount;
     4             LayoutCollector layoutCollector = new LayoutCollector(doc);
     5 
     6             List<int> rowIndexs = new List<int>();
     7             int pageindex = 3;
     8             doc.UpdatePageLayout();
     9             NodeCollection nodes = tableb.GetChildNodes(NodeType.Row, true);
    10             for (int i = 0; i < nodes.Count; i++)
    11             {
    12                 Node tmpNode = nodes[i];
    13                 int numPage = layoutCollector.GetStartPageIndex(tmpNode);
    14                 //如果找到指定页
    15                 if (numPage == pageindex + 1)
    16                 {
    //将画笔移动到该页
    tmpbuilder.MoveTo(tmpNode);
    17 if (pageindex + 1 > pageCount) 18 { 19 break; 20 } 21 else 22 { pageindex++; rowIndexs.Add(i - 1); } 23 } 24 25 } 26 27 Aspose.Words.Tables.Row templateRow = tableb.LastRow.Clone(true) as Aspose.Words.Tables.Row; 28 templateRow.FirstCell.Paragraphs.RemoveAt(templateRow.FirstCell.Paragraphs.Count - 1); 29 Run run = new Run(doc, "(接下页)"); 30 Aspose.Words.Paragraph paragraph = new Aspose.Words.Paragraph(doc); 31 paragraph.Runs.Add(run); 32 templateRow.FirstCell.Paragraphs.Add(paragraph); 33 //2.2 添加接下页的 行 34 foreach (var index in rowIndexs) 35 { 36 tableb.Rows.Insert(index, templateRow.Clone(true)); 37 }

    另外发现,aspose.word 没有办法插入浮动位置的文本框,只能通过插入图片(tmpbuilder.InsertImage)来实现,也有可能是我没有找到哈。

    以上纯属个人总结,如有不正确的地方,欢迎大家指出。

  • 相关阅读:
    iOS9 News 应用
    swift中,Optional、?与!之间的关系
    [翻译] CotEditor
    [book] iOS 8 Swift Programming Cookbook
    便利的操作plist文件
    消除 Xcode7 中 directory not found for option 'xxxx' 警告
    点击单个cell高度变化的动画效果
    [翻译] LiquidFloatingActionButton
    一脸懵逼学习Zookeeper(动物园管理员)---》高度可靠的分布式协调服务
    一脸懵逼学习基于CentOs的Hadoop集群安装与配置(三台机器跑集群)
  • 原文地址:https://www.cnblogs.com/dearroy/p/14513988.html
Copyright © 2011-2022 走看看