In this how-to tutorial, we will discuss the procedure to convert Excel to Image in Java. You will learn how to configure the document conversion library and how to consume converter APIs for the development of the Java Excel to Image converter. Further, this guide can be followed on any operating system such as Windows, Linux, and macOS without setting up any third-party tools.
Steps to Convert Excel to Image in Java
- Install GroupDocs.Conversion for Java from the Maven repository in Java application for implementing Excel to Image capability
- Import necessary classes for performing document conversion from Excel to Image
- Create an instance of the Converter class and load the source Excel file for transforming to Image format
- Initialize the ImageConvertOptions class for setting up properties to customize the converted PNG
- Finally, call the Convert method of the Converter class to save Excel as an Image file on the disk
The above stepwise instructions help you to create the Java Excel to Image capability as well as provide a reference to the relevant resources. The first two steps enable you to set up the required document conversion library and add the essential classes for doing the document transformation. The next step helps you to load the input Excel file by initializing the Converter class and then ImageConvertOptions allows you to define various parameters for customizing the converted Image file. In the last step, the Converter method does the document transformation and saves the resultant file to the specified path.
Code to Convert Excel to Image in Java
import com.groupdocs.conversion.Converter; | |
import com.groupdocs.conversion.licensing.License; | |
import com.groupdocs.conversion.options.convert.ImageConvertOptions; | |
public class ConvertExcelToImageInJava { | |
public static void main(String[] args) { // Main function to convert Excel to Image in Java | |
// Remove the watermark in output Excel document by adding license | |
License lic = new License(); | |
lic.setLicense("GroupDocs.Conversion.lic"); | |
// Load the source Excel file for conversion to Excel | |
Converter converter = new Converter("sample.xls"); | |
// Set the convert options for Excel format | |
ImageConvertOptions options = new ImageConvertOptions(); | |
options.setPageNumber(1); | |
options.setPagesCount(1); | |
// Convert and save the XLS in PNG format | |
converter.convert("converted.png", options); | |
System.out.println("Done"); | |
} | |
} |
This sample code snippet demonstrates the implementation of the Excel to Image Java application consuming the steps provided in the earlier section. As you can see that it only required writing a few lines of code that consists of simple API calls. Further, we have customized the resultant PNG file by defining a couple of parameters using the ImageConvertOptions object and you can set many other properties as per your requirements.
We have discussed the detailed procedure for developing the functionality to convert Excel to Image using Java. Recently, we published an article on converting Outlook Email to HTML using Java, take a look at how to convert Outlook Email to HTML in Java post for more information.