Java merge & unmerge Excel cell

In this paper, I will show you how to use Spire.XLS for Java Excel Java Merge & Unmerge Excel Cell

Tools used: Free Spire.XLS for Java Free Edition

Getting and installing Jar files:

Method 1: Download the jar file bag through the homepage. After downloading, unzip the file and put the Spire.xls.jar file under the lib folder into the Java program. Introduce to.

Method 2: maven warehouse Introduction by installation.

Merged Excel cell

In Spire.XLS, we can merge rows and columns of cells with the worksheet. getRange (). Get (). Merge () method.


import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class MergeCells {
    public static void main(String[] args){
        //Workbook creation example
        Workbook workbook = new Workbook();
        //Import an Excel document
        workbook.loadFromFile("Test1.xlsx");

        //Get the first sheet
        Worksheet sheet = workbook.getWorksheets().get(0);
        //Combine cell ranges A 1 to C 1
        sheet.getRange().get("A1:C1").merge();
        
        //Save result document
        workbook.saveToFile("MergeCells.xlsx", FileFormat.Version2013);
    }
}

Merge Excel cell.png

Unmerge cells

Spire.XLS Unmerge cells using the worksheet. GetRange (). Get (). UnMerge () method provided at the same time.


import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class UnmergeCells {
    public static void main(String[] args){
        //Workbook creation example
        Workbook workbook = new Workbook();
        //Import an Excel document
        workbook.loadFromFile("MergeCells.xlsx");

        //Get the first sheet
        Worksheet sheet = workbook.getWorksheets().get(0);
        //Range of unmerging cells A 1 to C 1
        sheet.getRange().get("A1:C1").unMerge();

        //Save result document
        workbook.saveToFile("UnMergeCells.xlsx", FileFormat.Version2013);
    }
}

Unmerge Excel cell.png

Recommended Posts

Java merge & unmerge Excel cell
[Java 8+] Merge maps
Print Java Excel Worksheet
Merge Java Word documents
Save Java PDF in Excel
Let's operate Excel with Java! !!
Importing Excel data in Java 2
Activate Excel file A1 cell of each sheet in Java
Java turns Excel into PDF
Import Excel data in Java
Java addition excel data validation
Java creates an Excel document
Importing Excel data in Java 3
Java sets Excel document properties
Java Excel Insertion and Image Extraction
EXCEL file update sample with JAVA
Java adds and reads Excel formulas