Hi. I'm using apache poi 3.8 beta 5 (20111217) and i can't get it to
insert a picture on a XSSFWorkbook. It works just fine when i try to
insert it on a HSSFWorkbook, but when i change the type of the file it
doesn't show anything on the sheet. Does anyone knows how to fix this?
Is it a bug?
Here is the code i'm using:
public void insertPicture() throws Exception{
/*
* 0 = HSSFWorkbook
* anything else = XSSFWorkbook
*/
int type = 1;
Workbook wb = null;
if(type == 0){
wb = new HSSFWorkbook();
}else{
wb = new XSSFWorkbook();
}
CreationHelper createHelper = wb.getCreationHelper();
StringBuffer sb = new StringBuffer();
sb.append("C:\\temp\\");
File f = new File(sb.toString());
if (!f.isDirectory()) {
f.mkdirs();
}
String dataHoje = new
SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(Util.getCurrentDate());
sb.append("file_");
sb.append(dataHoje);
if(type == 0){
sb.append(".xls");
}else{
sb.append(".xlsx");
}
File arquivo = new File(sb.toString());
if (!arquivo.exists()) {
arquivo.createNewFile();
}
FileOutputStream outputStream;
Sheet sheet = null;
try {
outputStream = new FileOutputStream(arquivo);
sheet = wb.createSheet();
Drawing patriarch= sheet.createDrawingPatriarch();
ClientAnchor anchor = createHelper.createClientAnchor();
anchor.setCol1(4);
anchor.setCol2(4);
anchor.setRow1(0);
anchor.setRow2(0);
anchor.setDx1(400);
anchor.setDx2(655);
anchor.setDy1(10);
anchor.setDy2(200);
anchor.setAnchorType(1);
File pic = new File("C:\\Temp\\img_ok.png");
long length = pic.length( );
byte[]picData = new byte[ ( int ) length ];
FileInputStream picIn = new FileInputStream( pic );
picIn.read(picData);
int index = wb.addPicture(picData, wb.PICTURE_TYPE_PNG);
patriarch.createPicture(anchor,index);
wb.write(outputStream);
outputStream.close();
} catch (Exception e) {
throw e;
}
}
Thanks in advice!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org