Java 通过JXL或POI在Excel中插入图像

Java 通过JXL或POI在Excel中插入图像,java,apache-poi,jxl,Java,Apache Poi,Jxl,我陷入了将图像插入excel文件的困境。条件是我不希望显示全尺寸图像。图像大小为常规像素(1280*1024),但在excel中,我希望显示大约10%的图像。如果有人双击图像,则应显示全尺寸图像。当我们离开这个细胞时,它的大小应该是一样的(10%)。任何帮助都将不胜感激 Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("My Sample Excel"); InputStream inputStream

我陷入了将图像插入excel文件的困境。条件是我不希望显示全尺寸图像。图像大小为常规像素(1280*1024),但在excel中,我希望显示大约10%的图像。如果有人双击图像,则应显示全尺寸图像。当我们离开这个细胞时,它的大小应该是一样的(10%)。任何帮助都将不胜感激

Workbook wb = new HSSFWorkbook();
   Sheet sheet = wb.createSheet("My Sample Excel");

   InputStream inputStream = new FileInputStream("C:/opt/ZZEclipseWorkspace2/WFCLAuto/ScreenShots/12_Mar_2013__09_40_22PM_192.168.30.145.jpeg");

   byte[] bytes = IOUtils.toByteArray(inputStream);

   int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);


   inputStream.close();


   CreationHelper helper = wb.getCreationHelper();

   Drawing drawing = sheet.createDrawingPatriarch();
   ClientAnchor anchor = helper.createClientAnchor();
   //set top-left corner for the image
   anchor.setCol1(1);
   anchor.setRow1(2);

   Picture pict = drawing.createPicture(anchor, pictureIdx);
   pict.resize(0.1);

   FileOutputStream fileOut = null;
   fileOut = new FileOutputStream("C:/opt/ZZEclipseWorkspace2/WFCLAuto/ScreenShots/testing1.xls");
   wb.write(fileOut);
   fileOut.close();

尝试设置左上角和右下角,使其仅填充所需的部分

HSSFClientAnchor anchor;
anchor=new HSSFClientAnchor(0,0,0,255,(short)1,2,(short)7,10);
anchor.setAnchorType(2);

该代码将把图片放在一个以1,2角和7,10角为界的矩形中。不过,我不确定是否要添加双击功能。

当您手动使用Excel时,是否可以在Excel中执行此操作?