# Freeze/ Unfreeze Excel Panes in Java Application

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);
    }
}
```

![row1.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1598598833106/SPjCg56Mq.jpeg)



**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);
    }
}
```

![co.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1598598888427/OeQJvXOAf.jpeg)



**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);
    }
}
```

![few.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1598598945969/R5g_q210n.jpeg)



**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);
    }
}
```

