DEV Community

CodeSharing
CodeSharing

Posted on

Converting Excel to Image in Java Application

In daily work, it’s inevitably that we will need to convert the format of the document to meet the needs of different work occasions. In my previous article, I have introduced how to convert Excel to PDF. Today I’m going to demonstrate how to convert Excel to Image 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>2.2.0</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

The input Excel file we used for demonstration:

Convert Excel to Image:

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

public class ExcelToImg {
    public static void main(String[] args) throws IOException {
        //Create a workbook instance
        Workbook workbook = new Workbook();
        //Load the Excel file
        workbook.loadFromFile("file1.xlsx");

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

        //Save the sheet to image
        sheet.saveToImage("image.png");
    }
}

Enter fullscreen mode Exit fullscreen mode

The output image file:

Top comments (0)