Generating visual previews of spreadsheet data is a frequent requirement when building reporting dashboards or email summaries. Conholdate.Total for Java provides a robust SDK that simplifies the process of converting Excel to image in Java applications. In this guide you will see how to load an XLSX workbook, configure JPEG output, and render worksheet pages to image files. By the end you’ll have a ready‑to‑run code sample that you can adapt to your own projects.
What Convert Excel Files to Image Demands from Your Application
Developers often need to turn spreadsheet content into static images for web previews, PDF reports, or mobile thumbnails. The requirement typically includes preserving cell formatting, rendering worksheet content accurately, and controlling image resolution. Handling these tasks manually by opening Excel, taking screenshots, and saving them does not scale and can lead to inconsistent results.
Technical constraints for a reliable solution are: support for XLSX files, accurate rendering of worksheet layout, configurable image resolution, and the ability to handle worksheets that span multiple printed pages. The conversion must run on a server or desktop environment without requiring Microsoft Office.
Choosing Conholdate.Total for Java for the Job
Conholdate.Total for Java offers a straightforward API that covers all the needed capabilities. The Workbook and Worksheet classes give you direct access to spreadsheet content, while ImageOrPrintOptions give fine‑grained control over resolution and image format, and SheetRender handles the actual page‑by‑page rendering. The SDK works on any Java runtime, requires only the Maven dependency, and handles large workbooks efficiently.
For detailed API usage see the official documentation. The full reference for classes such as Workbook, Worksheet, ImageOrPrintOptions, and SheetRender is available in the API reference. You can download the latest library from the release page.
Implementing Excel To Image Conversion in Java
The conversion process can be broken down into a few clear steps. The following sections walk you through each part, with short code excerpts taken directly from the full example.
Install Conholdate.Total for Java via Maven
Add the Conholdate Maven repository and the SDK dependency to your pom.xml:
<repositories>
<repository>
<id>conholdate-repo</id>
<name>Conholdate Maven Repository</name>
<url>https://repository.conholdate.com/repo/</url>
</repository>
</repositories>
<dependency>
<groupId>com.conholdate</groupId>
<artifactId>conholdate-total</artifactId>
<version>24.9</version>
<type>pom</type>
</dependency>
Load the Excel File and Access the Worksheet
Load the workbook with the Workbook class, then get a reference to the worksheet you want to convert:
// Load Excel file
com.aspose.cells.Workbook book = new com.aspose.cells.Workbook("input.xlsx");
// Get the reference of the desired worksheet
com.aspose.cells.Worksheet sheet = book.getWorksheets().get(0);
Configure Image Output Options for JPEG
Set the desired image resolution and format using ImageOrPrintOptions:
// Set image options
com.aspose.cells.ImageOrPrintOptions options = new com.aspose.cells.ImageOrPrintOptions();
options.setHorizontalResolution(200);
options.setVerticalResolution(200);
options.setImageType(com.aspose.cells.ImageType.JPEG);
Render the Worksheet to JPEG Images
Create a SheetRender for the worksheet and loop over its pages, saving each one as a separate JPEG file. A worksheet may span more than one printed page, so getPageCount() tells you how many images to expect:
// Convert sheet to JPG image
com.aspose.cells.SheetRender sr = new com.aspose.cells.SheetRender(sheet, options);
for (int j = 0; j < sr.getPageCount(); j++)
{
sr.toImage(j, "excel-to-jpg" + (j + 1) + ".jpg");
}
The steps above demonstrate how to convert Excel to image using the Conholdate.Total for Java SDK while giving you control over resolution, format, and multi‑page worksheets.
Complete Code Example: Convert Excel to Image with Full Sheet Support
The following code shows the complete, ready‑to‑run implementation described in the steps above.
public class ExcelToImageConverter {
public static void main(String[] args) throws Exception {
// Load Excel file
com.aspose.cells.Workbook book = new com.aspose.cells.Workbook("input.xlsx");
// Get the reference of the desired worksheet
com.aspose.cells.Worksheet sheet = book.getWorksheets().get(0);
// Set image options
com.aspose.cells.ImageOrPrintOptions options = new com.aspose.cells.ImageOrPrintOptions();
options.setHorizontalResolution(200);
options.setVerticalResolution(200);
options.setImageType(com.aspose.cells.ImageType.JPEG);
// Convert sheet to JPG image
com.aspose.cells.SheetRender sr = new com.aspose.cells.SheetRender(sheet, options);
for (int j = 0; j < sr.getPageCount(); j++)
{
sr.toImage(j, "excel-to-jpg" + (j + 1) + ".jpg");
}
System.out.println("Excel to image conversion completed successfully.");
}
}
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update the file path (
input.xlsx) to match your actual file location, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.
Conclusion
Converting Excel to image in Java becomes straightforward when you leverage Conholdate.Total for Java. The SDK handles worksheet rendering and high‑quality JPEG output with minimal code. By following the step‑by‑step guide you can integrate this capability into reporting tools, email generators, or any application that needs visual spreadsheet representations. Remember that production deployments require a commercial license; you can explore pricing options on the Conholdate.Total pricing page and obtain a temporary license from the temporary license page while evaluating.
FAQs
How can I convert Excel to image in Java?
Load the file withWorkbook, get the worksheet you need frombook.getWorksheets(), configureImageOrPrintOptions, and render it withSheetRender.Can I convert a specific Excel worksheet to an image?
Yes. Usebook.getWorksheets().get(index)to select the worksheet, then pass it intoSheetRenderfor conversion.Why do I get more than one image file from a single worksheet?
A worksheet can span multiple printed pages.SheetRender.getPageCount()returns the number of pages, and the loop saves one image per page.What licensing is required for production use?
A commercial license is required. Review the costs on the Conholdate.Total pricing page and obtain a temporary license from the temporary license page.
