Excel spreadsheets are widely used to store, organize and analyze data. However, you can not embed the Excel workbooks or worksheets directly into your web or desktop applications. One of the suitable options is converting worksheets to image or HTML formats. In this article, you will learn how to convert Excel XLSX/XLS files to PNG, JPEG, BMP, and other image formats using Java.
- Excel to Image Converter API
- Convert Excel Files to Image
- Additional Options for Excel to Image Conversion
- Get Free License
Java Excel to Image Converter API
In order to convert Excel XLSX or XLS files to image formats, we’ll use Aspose.Cells for Java API. It is a powerful spreadsheet manipulation API that provides high-quality conversion of worksheets into PNG, JPEG, BMP, and other popular image formats. Aspose.Cells for Java can be downloaded as JAR or installed using the following Maven configurations.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository>
<dependency> <groupId>com.aspose</groupId> <artifactId>aspose-cells</artifactId> <version>21.2</version> </dependency>
Aspose.Cells for Java supports conversion of Excel files to the following image formats:
Convert Excel XLSX to Image in Java
The following are the steps along with API references to convert a worksheet into a PNG image.
- Load the Excel file using the Workbook class.
- Create an instance of ImageOrPrintOptions class.
- Set output image type using ImageOrPrintOptions.setImageType(ImageType) method.
- Get the worksheet you want to convert into a Worksheet object.
- Create a SheetRender object and initialize it with Worksheet and ImageOrPrintOptions objects.
- Convert the worksheet and save the image file using SheetRender.toImage(int, String) method.
The following code sample shows how to convert an Excel XLSX file to image using Java.
Additional Options for Excel to Image Conversion
Aspose.Cells for Java also provides additional options to customize XLSX to image conversion. For example, you can specify the style for gridlines, render one image per sheet, and so on. The ImageOrPrintOptions class is used to set these options. The following code sample shows how to use ImageOrPrintOptions class in Excel to image conversion.
Get a Free License
You can get a free temporary license in order to try the API without evaluation limitations.
In this article, you have learned how to convert Excel files to PNG, JPEG, BMP, or other image formats using Java. Furthermore, you have seen how to customize Excel to image conversion with additional options. You can explore more about Java spreadsheet manipulation API using documentation. In case you would have any questions or queries, contact us via our forum.