Class Table

java.lang.Object
io.leandev.appfuse.document.Table

public class Table extends Object

表格

封裝底層 POI 的 XWPFTable,提供列的增刪、樣板列複製、儲存格合併與寬度設定。

Since:
4.0.0
  • Method Details

    • rowCount

      public int rowCount()
      取得列數
      Returns:
      列數
    • rows

      public List<TableRow> rows()
      取得所有列
      Returns:
      列列表
    • row

      public TableRow row(int i)
      取得指定列
      Parameters:
      i - 列索引(0 起算)
      Returns:
    • cell

      public TableCell cell(int row, int col)
      取得指定位置的儲存格
      Parameters:
      row - 列索引
      col - 欄索引
      Returns:
      儲存格
    • appendRow

      public TableRow appendRow()
      在表尾附加一列(欄數與既有列相同)
      Returns:
      新列
    • duplicateRow

      public TableRow duplicateRow(int i)
      複製指定列(含內容與格式),插入其後
      Parameters:
      i - 來源列索引
      Returns:
      複製後的新列
    • removeRow

      public void removeRow(int i)
      移除指定列
      Parameters:
      i - 列索引
    • mergeCellsVertically

      public void mergeCellsVertically(int col, int fromRow, int toRow)
      垂直合併某欄的數列儲存格
      Parameters:
      col - 欄索引
      fromRow - 起始列
      toRow - 結束列
    • mergeCellsHorizontally

      public void mergeCellsHorizontally(int row, int fromCol, int toCol)
      水平合併某列的數欄儲存格
      Parameters:
      row - 列索引
      fromCol - 起始欄
      toCol - 結束欄
    • mergeRegion

      public void mergeRegion(int fromRow, int fromCol, int toRow, int toCol)
      合併矩形區塊(先逐列水平合併,再於首欄垂直合併)
      Parameters:
      fromRow - 起始列
      fromCol - 起始欄
      toRow - 結束列
      toCol - 結束欄
    • setWidth

      public void setWidth(Length width)
      設定整表寬度
      Parameters:
      width - 寬度
    • setWidthPercent

      public void setWidthPercent(int pct)
      設定整表寬度為頁寬百分比
      Parameters:
      pct - 百分比(0–100)
    • setFullWidth

      public void setFullWidth()
      設定整表為滿版寬度(100%)
    • setColumnWidth

      public void setColumnWidth(int col, Length width)
      設定某欄寬度(套用到每一列的該欄儲存格)
      Parameters:
      col - 欄索引
      width - 寬度