Java: Unfreeze Panes and Get Frozen Panes in Excel

The Freeze Panes feature in Excel allows users to lock specific rows and columns while scrolling, ensuring that critical information remains visible regardless of the dataset's size. However, there are instances where unfreezing panes becomes necessary. Unfreezing rows and columns grants users the freedom to navigate large datasets seamlessly, facilitating comprehensive data analysis, editing, and formatting. the contents of frozen panes are often important information, and being able to obtain the range of frozen panes can facilitate easier access to this content. This article demonstrates how to use Spire.XLS for Java to unfreeze panes and obtain frozen rows and columns in Excel worksheets with Java code.

Install Spire.XLS for Java

First of all, you're required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls</artifactId>
        <version>14.11.0</version>
    </dependency>
</dependencies>
    

Unfreeze Panes in Excel Worksheets with Java

With Spire.XLS for Java, developers get a worksheet using Workbook.getWorksheets().get() method and unfreeze the panes using Worksheet.RemovePanes() method. The detailed steps for unfreezing panes in an Excel worksheet are as follows:

  • Create an object of Workbook class.
  • Load an Excel workbook using Workbook.loadFromFile() method.
  • Get a worksheet from the workbook using Workbook.getWorksheets().get() method.
  • Unfreeze panes in the worksheet using Worksheet.removePanes() method.
  • Save the workbook using Workbook.saveToFile() method.
  • Java
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class UnfreezePanes {
    public static void main(String[] args) {
        // Create an object of Workbook class
        Workbook wb = new Workbook();

        // Load an Excel workbook
        wb.loadFromFile("Sample.xlsx");

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

        // Unfreeze the panes
        sheet.removePanes();

        // Save the workbook
        wb.saveToFile("output/UnfreezePanes.xlsx");
        wb.dispose();
    }
}

Java: Unfreeze Panes and Get Frozen Panes in Excel

Obtain Frozen Rows and Columns in Excel Worksheets with Java

Spire.XLS for Java provides the Worksheet.getFreezePanes() method to get the row and column indexes of the frozen panes, which allows developers to conveniently extract, remove, or format the content of the frozen panes. The parameters obtained are in the format of an int list: [int rowIndex, int columnIndex]. For example, [1, 0] indicates that the first row is frozen.

The detailed steps for obtaining the row and column parameters of the frozen panes are as follows:

  • Create an object of Workbook class.
  • Load an Excel workbook using Workbook.loadFromFile() method.
  • Get the first worksheet using Workbook.getWorksheets().get() method.
  • Get the indexes of the frozen rows and columns using Worksheet.getFreezePanes() method.
  • Output the result.
  • Java
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class GetFrozenCellRange {
    public static void main(String[] args) {
        // Create an object of Document clas
        Workbook wb = new Workbook();

        // Load an Excel file
        wb.loadFromFile("Sample.xlsx");

        // Get the first worksheet
        Worksheet ws = wb.getWorksheets().get(0);

        // Get the indexes of the frozen rows and columns
        int[] index = ws.getFreezePanes();

        // Output the result
        System.out.println("Frozen Rows: " + index[0] + "\r\nFrozen Columns: " + index[1]);
        wb.dispose();
    }
}

Java: Unfreeze Panes and Get Frozen Panes in Excel

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.