This precise article explains all the details about how to add image in Excel using Java. You may use this process while creating a workbook from scratch or for processing an existing workbook. The details about any of these use cases are covered with to-the-point information about how using Java insert picture in Excel cell and save the generated file in XLSX or XLS format.
Steps to Add Image in Excel using Java
- Add Aspose.Cells dependency from the Maven repository to add an image in Excel
- Create an object of the Workbook class to instantiate an Excel file
- Get the reference to a Worksheet by mentioning its index value
- Specify the row and column index and the image path for adding the image
- Write the output workbook as an XLSX file
These precise steps elaborate the basic procedure to insert image in Excel using Java. Instantiate an empty Excel file with the Workbook class instance and then mention the indexes of the row and column in addition to the input image path. However, please note that the indexes are zero-based where 5 means F column in the worksheet.
Code to Add Image in Excel using Java
The above sample code explains how you can add image to Excel in Java with a few API calls. Moreover, you do not need to install any other software to work with this feature. During this process, you can also adjust the image size like autofit into some cells as per your requirements.
This tutorial includes whole details to answer the question of how to add image in Excel using Java. However, if you want to learn Excel to image rendering, please head to the article about how to convert Excel sheets to Image in Java.