DEV Community

CodeSharing
CodeSharing

Posted on

[Java] Set Worksheet Zoom Factor

Usually the default zoom factor for an Excel worksheet is 100%, but sometimes we may need to adjust the zoom factor to meet the requirements of some special occasions. In this article, I will share how to set the worksheet zoom factor by using Free Spire.XLS for Java.

Installation
Method 1: Download the Free Spire.XLS for Java 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.

<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>3.9.1</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

Set Zoom Factor

import com.spire.xls.*;

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

        //Create a workbook and load a file
        Workbook workbook = new Workbook();
        workbook.loadFromFile("Data.xlsx");

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

        //Set the zoom factor of the worksheet to 120
        sheet.setZoom(120);

        //Save the Excel file
        workbook.saveToFile("output/Zoomfactor.xlsx", ExcelVersion.Version2010);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:
zoom

Top comments (0)