Excel images

Following example shows how to add images in different formats to ExcelWorksheet using various types of positioning.

Excel images added with GemBox.Spreadsheet for Java
Screenshot of Excel images added with GemBox.Spreadsheet for Java
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.

        ExcelFile workbook = new ExcelFile();
        ExcelWorksheet worksheet = workbook.addWorksheet("Images");

        worksheet.getCell(0, 0).setValue("Image examples:");

        // Small BMP added by using rectangle.
        worksheet.getPictures().add("%#SmallImage.bmp%", 50, 50, 48, 48, LengthUnit.PIXEL);

        // Large JPG added by using one anchor.
        worksheet.getPictures().add("%#FragonardReader.jpg%", "B9");

        // PNG added by using two anchors.
        worksheet.getPictures().add("%#Dices.png%", "J16", "K20");

        // GIF added by using anchors. Notice that animation is lost in MS Excel.
                new AnchorCell(worksheet.getColumn(9), worksheet.getRow(21), 100000, 100000),
                new AnchorCell(worksheet.getColumn(10), worksheet.getRow(23), 50000, 50000)).getPosition().setMode(PositioningMode.MOVE);

        // WMF added by using one anchor and size.
        worksheet.getPictures().add("%#Graphics1.wmf%", "J9", 250, 100, LengthUnit.PIXEL).getPosition().setMode(PositioningMode.FREE_FLOATING);


Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.

Like it?

Download Buy

If you want to try the GemBox.Spreadsheet for Java yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.