zoukankan      html  css  js  c++  java
  • com.itextpdf.layout.element.Table

    IText 7 使用Table

    • 使用表格来呈现数据。

    Demo1

    // 创建对象指定固定比例的列
    Table table = new Table(UnitValue.createPercentArray(10)).useAllAvailableWidth()
    
    // 设置边框
    table.setBorder(Border.NO_BORDER)
    
    // 可以设置表头表尾巴,当表呈现在两个页面的时候,第二页会自动呈现出表头。
    table.addHeaderCell(...)
    table.addFooterCell(...)
    
    // 添加Cell 以及 合并参数:rowspan,colspan
    table.addCell(new Cell(1, 4)
            .setBorder(Border.NO_BORDER)
            .add(new Paragraph("")))
    table.addCell(new Cell(1, 6)

    Demo2

    • 通常我们创建一个Style 对象来控制所有的 Cell 的样式。
    • .setTextAlignment(TextAlignment.RIGHT) 设置容器内文本的对其方式
    • .setVerticalAlignment(VerticalAlignment.MIDDLE) 设置容器内容器的垂直位置
    • cellStyle.setKeepTogether(true) 当一个单元格处在两个页面中间的时候,默认会被拆开,这里让他保持在一起。
    Style cellStyle = new Style()
    cellStyle.setVerticalAlignment(VerticalAlignment.MIDDLE)
    cellStyle.setTextAlignment(TextAlignment.CENTER)
    cellStyle.setKeepTogether(true)

    Demo3

    • 如何有效的调整 Table中 Cell 的宽度?
    float[] width = new float[]{0.5,1.5,1,1,1,1,1,1,1,1}
    Table table = new Table(width).useAllAvailableWidth()
  • 相关阅读:
    2020.05.02【NOIP普及组】模拟赛C组31总结
    【提高组NOIP2008】传纸条 题解
    【NOIP2006PJ】Jam的计数法(count)题解
    话说placeholder
    css垂直居中
    fixed和absolute的区别
    链接的属性href=“?” ?该些什么及优缺点
    论ul、ol和dl的区别
    笔记本插拔电源黑屏一下
    CSS 样式书写规范
  • 原文地址:https://www.cnblogs.com/duchaoqun/p/13994336.html
Copyright © 2011-2022 走看看