POI插入图片时,原来的图片被清除的问题3.7中还没解决啊
2010-07-17 18:12
330 查看
POI3.7的测试版本已经发布了,一直对POI操作图片的处理比较关心.
以前的版本中如果模板文件中有图片,然后再代码中再新增加图片的话,原来的图片会被清除掉.这个在实际的应用中不能不是说一个很大的不便.
原文描述如下:
createPicture() on the drawing patriarch. At the time of writing the following types are supported:
PNG
JPG
DIB
It should be noted that any existing drawings may be erased once you add a image to a sheet.
以前的版本中如果模板文件中有图片,然后再代码中再新增加图片的话,原来的图片会被清除掉.这个在实际的应用中不能不是说一个很大的不便.
原文描述如下:
Images
Images are part of the drawing support. To add an image just callcreatePicture() on the drawing patriarch. At the time of writing the following types are supported:
PNG
JPG
DIB
It should be noted that any existing drawings may be erased once you add a image to a sheet.
//create a new workbook Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); //add picture data to this workbook. InputStream is = new FileInputStream("image1.jpeg"); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG); is.close(); 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 anchor.setCol1(3); anchor.setRow1(2); Picture pict = drawing.createPicture(anchor, pictureIdx); //auto-size picture relative to its top-left corner pict.resize(); //save workbook String file = "picture.xls"; if(wb instanceof XSSFWorkbook) file += "x"; FileOutputStream fileOut = new FileOutputStream(file); wb.write(fileOut); fileOut.close();
相关文章推荐
- POI用addPicture插入图片到word里面无法显示问题解决
- 解决Word2010中插入图片时变成空白框问题
- POI插入图片的时候,使用resize函数还是变形的问题
- Adobe Illustrator 完美解决visio,Matlab图片插入Latex问题
- NPOI导出Word插入图片问题解决方案
- AR插入图片只能插入8K大小的问题解决
- 在动态插入Easyui datebox控件时,使用$.parser.parse()手工渲染时,解决日期控件原有的值被清除问题
- 在可编辑div中插入文字或图片的问题解决思路
- POI向word2007文件插入图片时的Bug问题
- 解决POI3.10 添加图片不成功的问题
- 解决js动态插入JQuery轮播图片出现的问题
- 解决word插入(粘贴)图片不能显示的问题
- eWebeditor在IE8、IE9中插入图片按钮不能使用问题的解决方法
- 解决sharepoint2010的多行文本框的插入图片—【从sharepoint】的disabled问题
- Latex 中双栏(跨栏)中插入跨双栏图片出现在下一页问题的解决
- xcode替换同名图片后,显示的还是旧图片。各种清除缓存都没有解决问题
- 在可编辑div中插入文字或图片的问题解决思路
- 解决从光标处插入图片光标消失的问题
- Emacs AUCTeX 解决不能插入高版本pdf图片的问题
- UEditor插入视频、图片显示问题解决