美文网首页
java-Aspose.word使用(表格合并,生成)

java-Aspose.word使用(表格合并,生成)

作者: 69e1d9dadce5 | 来源:发表于2019-06-24 10:37 被阅读0次
    • 相关jar包或破解文件下载
    https://www.jianshu.com/p/dcb1fe9cfb6b
    
    • cell 官网api地址
    https://apireference.aspose.com/java/words/com.aspose.words/cellmerge#PREVIOUS
    
    • 获取word文档中所有表格的集合
    NodeCollection allTables  = document.getChildNodes(NodeType.TABLE,true);
    
    • 从表格集合中获取第一个表格
    Table table = (Table) allTables.get(0);
    
    • 构建新的表格
    builder.startTable();
    builder.write("品名");
    builder.insertCell();
    builder.write("数量");
    builder.insertCell();
    builder.write("单价");
    builder.insertCell();
    builder.write("备注");
    builder.endRow();
    builder.endTable();
    
    • cell格式-垂直居中
    builder.getCellFormat().setVerticalAlignment(CellVerticalAlignment.CENTER);
    
    • 段落样式-居中
    builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
    
    • 清除cell样式
    builder.getCellFormat().clearFormatting();
    
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.insertCell();
    builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
    builder.write("Text in merged cells.");
    builder.insertCell();
    // This cell is merged to the previous and should be empty.
    builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
    builder.endRow();
    builder.insertCell();
    builder.getCellFormat().setHorizontalMerge(CellMerge.NONE);
    builder.write("Text in one cell.");
    builder.insertCell();
    builder.write("Text in another cell.");
    builder.endRow();
    builder.endTable();
    
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.insertCell();
    builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
    builder.write("Text in merged cells.");
    builder.insertCell();
    builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
    builder.write("Text in one cell");
    builder.endRow();
    builder.insertCell();
    // This cell is vertically merged to the cell above and should be empty.
    builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
    builder.insertCell();
    builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
    builder.write("Text in another cell");
    builder.endRow();
    builder.endTable();
    

    相关文章

      网友评论

          本文标题:java-Aspose.word使用(表格合并,生成)

          本文链接:https://www.haomeiwen.com/subject/idluqctx.html