java把图片写入excel_使用POI向excel中写入图片的java代码
List headlist = this.getCS_HEAD(allFactoryNo);
HSSFSheet sheet = workbook.createSheet();
sheet.setColumnWidth((short)0, 6000);
sheet.setColumnWidth((short)1, 10000);
HSSFRow row3 = sheet.createRow(3);
HSSFPatriarch pa = sheet.createDrawingPatriarch(); //增加多個(gè)圖片時(shí)只需要?jiǎng)?chuàng)建一個(gè)對(duì)象
HSSFRow row4 = sheet.createRow(4);
HSSFCell cell40 = row4.createCell(0);
cell40.setCellValue("編碼");
HSSFCell cell41 = row4.createCell(1);
cell41.setCellValue("名稱(chēng)");
for(int i=0;i
Cs_head cshead = (Cs_head) headlist.get(i);
SmbFile smbFile = new SmbFile("smb://erp002:[email?protected]/cac_phot/"+cshead.getProduct());//訪問(wèn)網(wǎng)絡(luò)共享文件
InputStream is = smbFile.getInputStream();
int x1=0;
int y1=0;
int x2=x1+255;
int y2=y1+255;
HSSFClientAnchor anchor = new HSSFClientAnchor(x1,y1,x2,y2,(short)(2+(i*2)),0,(short)(4+(i*2)),2);
anchor.setAnchorType(2);
BufferedImage bi = ImageIO.read(is);
ByteArrayOutputStream bout=new ByteArrayOutputStream();
ImageIO.write(bi,"JPG",bout);
pa.createPicture(anchor , workbook.addPicture(bout.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
總結(jié)
以上是生活随笔為你收集整理的java把图片写入excel_使用POI向excel中写入图片的java代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 树袋熊网咖每小时网费多少钱?
- 下一篇: spark mysql 驱动_spark