How to add a photo to Excel in Java

Adding pictures to Excel files helps make your spreadsheets easier to understand. Images can support your data, highlight key points, and improve the overall look of your reports. In this blog post, you will learn how to add a photo to Excel in Java. We will guide you through each step using simple Java code examples. By the end, you will be able to add images to your Excel files quickly and efficiently.

This article covers the following:

Java Excel Library to Add a Photo

Aspose.Cells for Java is a powerful library for working with Excel files in Java. It allows you to insert images, format cells, and generate Excel documents programmatically. You can add, move, or resize pictures easily.

To install Aspose.Cells for Java, use Maven:

<dependency>
  <groupId>com.aspose</groupId>
  <artifactId>aspose-cells</artifactId>
  <version>25.6</version>
</dependency>

Or download it from the official releases page.

How to Add a Picture to Excel in Java

Please follow these steps to add a photo to Excel using Java:

  1. Create a Workbook object.
  2. Access the desired worksheet.
  3. Use Pictures.add() to insert the image.
  4. Save the workbook.

Here is a sample Java code:

How to Add a Photo to Excel in Java

How to Add a Photo to Excel in Java

Add a Picture Based on Cell Reference

You can add a picture at a specific cell reference too by following the steps below:

  1. Create a Workbook class object.
  2. Access the target worksheet from the Worksheets collection.
  3. Add text or data to the relevant cells.
  4. Use the addPicture() method to insert the photo at a specific cell.
  5. Set the image size or position if needed.
  6. Save the workbook using the save() method.
Insert Picture Based on Cell Reference

Add a Picture Based on Cell Reference

Get a Free License

You can request a free temporary license to evaluate all features without limitations. Visit the temporary license page to get yours today.

Add Picture to Excel: Free Resources

Explore more Aspose resources to boost your Excel automation projects:

Conclusion

In this article, we learned how to add a photo to Excel using Java and Aspose.Cells. With simple code, you can enhance your worksheets with images. Try it out and explore more features in Aspose.Cells for Java.

If you need help, visit our support forum.

See Also