hi bina,
i tried it long time ago and used 2 methods i found anywere in the
www, this should work
private static HSSFPicture createPicture(HSSFWorkbook workbook,String
sheetName,String imageFile,int dx1,int dy1,int dx2,int dy2,short
col1,int row1,short col2,int row2){
//Create the drawing patriarch. This is the top level
container for
//all shapes. This will clear out any existing shapes for
that sheet.
HSSFPatriarch patriarch = workbook.getSheet
(sheetName).createDrawingPatriarch();
HSSFClientAnchor anchor;
anchor = new HSSFClientAnchor
(dx1,dy1,dx2,dy2,col1,row1,col2,row2);
anchor.setAnchorType( 2 );
try {
return patriarch.createPicture(anchor, loadPicture
( imageFile, workbook ));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
private static int loadPicture( String path, HSSFWorkbook wb )
throws IOException{
int pictureIndex;
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
try{
fis = new FileInputStream( path);
bos = new ByteArrayOutputStream( );
int c;
while ( (c = fis.read()) != -1) bos.write( c );
pictureIndex = wb.addPicture( bos.toByteArray(),
HSSFWorkbook.PICTURE_TYPE_JPEG );
}
finally{
if (fis != null)
fis.close();
if (bos != null)
bos.close();
}
return pictureIndex;
}
On Apr 5, 2006, at 11:14 PM, Daniel Noll wrote:
Bina wrote:
hi,
I cannot insert an image in a excel sheet.
Any one there who can help me. Please help me.
I assume you've tried HSSFWorkbook#addPicture and there is an error
of some sort. Care to elaborate?
Daniel
--
Daniel Noll
Nuix Pty Ltd
Suite 79, 89 Jones St, Ultimo NSW 2007, Australia Ph: +61 2 9280
0699
Web: http://www.nuix.com.au/ Fax: +61 2 9212
6902
This message is intended only for the named recipient. If you are not
the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this
message or attachment is strictly prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List: http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/