Freeze/ Unfreeze Excel Panes in Java Application
Tags: java, excel, freezepanes
Published: 2020-08-28 07:10:02

When viewing an Excel worksheet with a lot of data, freezing panes can help us freeze the specified row or column and keep them  visible while scrolling through the rest of the worksheet, which is very convenient for us to view and compare the data.

**Installation**
**Method 1:** Download the [Free Spire.XLS for Java](https://www.e-iceblue.com/Download/xls-for-java-free.html) and unzip it. Then add the Spire.Xls.jar file to your project as dependency.

**Method 2:** You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.

```java
<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>2.2.0</version>
    </dependency>
</dependencies>

```



**Freeze Top Row:**

```java
import com.spire.xls.*;

public class FreezeTopRow {
    public static void main(String[] args) {

        ////Load a sample Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("sample1.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Freeze top row
        sheet.freezePanes(2,1);

        //Save to file
        workbook.saveToFile("FreezeTopRow.xlsx", ExcelVersion.Version2010);
    }
}

```

![](https://dev-to-uploads.s3.amazonaws.com/i/1mdaukczvg9d7d3wyjpt.jpg)



**Freeze Fisrt Column:**

```java
import com.spire.xls.*;

public class FreezeFirstColumn {
    public static void main(String[] args) {

        //Load a sample Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("sample1.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Freeze frist column
        sheet.freezePanes(1, 2);

        //Save to file
        workbook.saveToFile("FreezeFirstColumn.xlsx", ExcelVersion.Version2016);
    }
}

```

![](https://dev-to-uploads.s3.amazonaws.com/i/vvvwv4xcieume8pljwzt.jpg)



**Freeze Few Rows and Columns:**

```java
import com.spire.xls.*;

public class FreezePane {
    public static void main(String[] args) {

        //Load a sample Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("sample1.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Freeze the first two rows and first two columns
        sheet.freezePanes(3, 3);

        //Save to file
        workbook.saveToFile("FreezePanes.xlsx", ExcelVersion.Version2016);
    }
}
```

![](https://dev-to-uploads.s3.amazonaws.com/i/llao13tb1hc4zt6j9rd0.jpg)



**Unfreeze Panes:**

```java
import com.spire.xls.*;

public class UnfreezePanes {
    public static void main(String[] args) {

        //Load a sample Excel file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("sample1.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Unfreeze panes
        sheet.removePanes();

        //Save to file
        workbook.saveToFile("UnfreezePanes.xlsx", ExcelVersion.Version2016);
    }
}

```