Java joins and splitting table cells in Word documents

Here, we will introduce the merging and splitting of table cells in a Word document in a Java application.

Merge cells:

Spire.Doc merged cells are divided into two categories: horizontal merge and vertical merge. For horizontal join, specify the applyVerticalMerge (int a, int a, int a) column, start row and end row you want to join. At the time of vertical join, specify the applyHorizontalMerge (int a, int a, int a) row, start column you want to join. , Specify the end column.


import com.spire.doc.*;

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

        String output = "output/MergeTableCells.docx";

        //New word example
        Document document = new Document();

        // 4*Add 4 tables
        Section section = document.addSection();
        Table table = section.addTable(true);
        table.resetCells(4, 4);
        
        //Horizontal connection
        table.applyHorizontalMerge(0, 0, 3);

        //Vertical connection
        table.applyVerticalMerge(0, 2, 3);

        //Save document
        document.saveToFile(output, FileFormat.Docx);
    }
}

Merge cells.jpg

Cell split: To split a cell, first get the cell and specify the number of split columns and rows of the cell. import com.spire.doc.*;

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

        String output = "output/SplitTableCells.docx";

        //New word example
        Document document = new Document();

        //4*Add 4 tables
        Section section = document.addSection();
        Table table = section.addTable(true);
        table.resetCells(4, 4);

        //Cell split
        table.getRows().get(3).getCells().get(3).splitCell(2, 2);

        //Save document
        document.saveToFile(output, FileFormat.Docx);
    }
}

Split cell.jpg

Recommended Posts

Java joins and splitting table cells in Word documents
Java adds and removes watermarks in word documents
Java creates a table in a Word document
Add footnotes to Word documents in Java
Change paragraph text color in Java Word documents
Merge Java Word documents
[Java] [POI] Create a table in Word and start a new line in one cell
Implement Table Driven Test in Java 14
Encoding and Decoding example in Java
[Java] Loop processing and multiplication table
Java adds hyperlinks to Word documents
StringBuffer and StringBuilder Class in Java
Understanding equals and hashCode in Java
Java encryption, decryption of Word documents
Java draws shapes in PDF documents
Hello world in Java and Gradle
Difference between final and Immutable in Java
[Java] for Each and sorted in Lambda
Arrylist and linked list difference in java
Program PDF headers and footers in Java
Learn Flyweight patterns and ConcurrentHashMap in Java
Java Direction in C ++ Design and Evolution
Java to C and C to Java in Android Studio
Reading and writing gzip files in Java
Difference between int and Integer in Java
Discrimination of Enums in Java 7 and above
Create barcodes and QR codes in Java PDF
Detect similar videos in Java and OpenCV rev.2
Parallel and parallel processing in various languages (Java edition)
Difference between next () and nextLine () in Java Scanner
Differences in writing Java, C # and Javascript classes
Capture and save from selenium installation in Java
Detect similar videos in Java and OpenCV rev.3
[Java] Understand in 10 minutes! Associative array and HashMap
Basics of threads and Callable in Java [Beginner]
I tried to output multiplication table in Java
Distinguish between positive and negative numbers in Java
Detect similar videos in Java and OpenCV rev.1
Represents "next day" and "previous day" in Java / Android
Questions in java exception handling throw and try-catch
Upload and download notes in java on S3
Encrypt / decrypt with AES256 in PHP and Java
Generate OffsetDateTime from Clock and LocalDateTime in Java