Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Image in export to excel using hssf api

Im trying to create a excel sheet in webdynpro java using hssf api.
I am able to format the excel as per the requirement, and im facing a problem while adding a image(logo).
Iam using the following code:

FileInputStream fis=new FileInputStream("M:\\image.JPG");
ByteArrayOutputStream img_bytes=new ByteArrayOutputStream();
int b;
while((b=fis.read())!=-1)
img_bytes.write(b);
fis.close();
HSSFClientAnchor anchor = new
HSSFClientAnchor(0,0,0,0,(short)col,row,(short)++col,++row);
int index=wb.addPicture(img_bytes.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG);
HSSFSheet sheet=wb.getSheet("test");
HSSFPatriarch patriarch=sheet.createDrawingPatriarch();
patriarch.createPicture(anchor,index);
anchor.setAnchorType(2);
wb.write(fos);
System.out.println("Writing data to the xls file");
fos.close();
System.out.println("File closed");

But doesnt work. Can anyone suggest where im going wrong?

Regards,
Padmalatha.

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question