0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Java結合とWordドキュメント内の表のセルの分割

Posted at

ここでは、JavaアプリケーションでWordドキュメント内の表のセルの結合と分割を紹介します

セルの結合:

Spire.Doc結合セルは、水平結合と垂直結合の2つに分類されます。水平結合の場合applyVerticalMerge(int a , int a ,int a) 列の指定、結合したい開始行と終了行. 垂直結合時に、applyHorizontalMerge(int a, int a, int a) 行の指定、結合したい開始列、終了列を指定します。


import com.spire.doc.*;

public class MergeTableCell {
    public static void main(String[] args) throws Exception {

        String output = "output/MergeTableCells.docx";

        //新しいwordの例
        Document document = new Document();

        // 4*4のテーブルを追加します
        Section section = document.addSection();
        Table table = section.addTable(true);
        table.resetCells(4, 4);
        
        //水平結合
        table.applyHorizontalMerge(0, 0, 3);

        // 垂直結合
        table.applyVerticalMerge(0, 2, 3);

        // 文書を保存
        document.saveToFile(output, FileFormat.Docx);
    }
}

Merge cells.jpg

セルの分割:
セルを分割するには、まずセルを取得し、セルの分割された列の数と行の数を指定します。
import com.spire.doc.*;

public class SplitTableCell {
    public static void main(String[] args) throws Exception {

        String output = "output/SplitTableCells.docx";

        //新しいwordの例
        Document document = new Document();

        //4*4のテーブルを追加
        Section section = document.addSection();
        Table table = section.addTable(true);
        table.resetCells(4, 4);

        //セルの分割
        table.getRows().get(3).getCells().get(3).splitCell(2, 2);

        //文書を保存
        document.saveToFile(output, FileFormat.Docx);
    }
}

Split cell.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?