Aspose.Cells - Add Images in Worksheet

//Get the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);

//Insert a string value to a cell

//Set the 4th row height
worksheet.getCells().setRowHeight(3, 150);

//Set the C column width

//Add a picture to the C4 cell
int index = worksheet.getPictures().add(3, 2, 3, 2, dataPath + "aspose.jpg");

//Get the picture object
com.aspose.cells.Picture pic = worksheet.getPictures().get(index);

//Set the placement type

Apache POI SS

//add picture data to this workbook.
InputStream is = new FileInputStream(dataPath + "aspose.jpg");
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);

CreationHelper helper = wb.getCreationHelper();

//create sheet
Sheet sheet = wb.createSheet();

// Create the drawing patriarch.  This is the top level container for all shapes. 
Drawing drawing = sheet.createDrawingPatriarch();

//add a picture shape
ClientAnchor anchor = helper.createClientAnchor();
//set top-left corner of the picture,
//subsequent call of Picture#resize() will operate relative to it
Picture pict = drawing.createPicture(anchor, pictureIdx);

//auto-size picture relative to its top-left corner

Download Source Code

For More Examples, Please Visit Aspose Docs

Last edited Jan 29, 2015 at 10:23 AM by shoaibkhan, version 2