2012-10-09 42 views
3

我想創建一個帶有動態圖標和動態圖像列表的Excel文件。 在Excel文件中創建文本部分對jxls非常有用。 但我無法用jxls在每一行插入一個圖像。jxls - 使用動態圖像創建Excel文件

請問有沒有人對我有任何建議?

預先感謝您。

回答

1

我發現的唯一的解決方案是創建與JXLS和創建工作簿中插入與本地POI功能相似圖片後的XLS文件:

Workbook resultWorkbook = transformer.transformXLS(is, beans); 

     Iterator rowIter = resultWorkbook.getSheetAt(0).rowIterator(); 
     while (rowIter.hasNext()){ 
      HSSFRow row = (HSSFRow) rowIter.next(); 
      Iterator cellIter = row.cellIterator(); 
      while (cellIter.hasNext()){ 
       HSSFCell cell = (HSSFCell) cellIter.next(); 
       final String IMG_PREFIX = "#IMG#"; 
       if(cell.toString().startsWith(IMG_PREFIX)){ 
        String cellValue = cell.toString(); 
        cell.setCellValue(""); 
        String imagePath = cellValue.replaceFirst(IMG_PREFIX, ""); 
        File imageFile = new File(imagePath); 
        if(imageFile.exists()){ 
         FileInputStream isi = new FileInputStream(imageFile); 
         ImageTools imageTools = new ImageTools(); 
         byte[] imgBytes = imageTools.resizeImage(isi, 100); 
         int pictureIdx = resultWorkbook.addPicture(imgBytes, Workbook.PICTURE_TYPE_JPEG); 
         CreationHelper helper = resultWorkbook.getCreationHelper(); 

         Drawing drawing = resultWorkbook.getSheetAt(0).createDrawingPatriarch(); 
         ClientAnchor anchor = helper.createClientAnchor(); 
         anchor.setCol1(cell.getColumnIndex()); 
         anchor.setRow1(cell.getRowIndex()); 
         Picture pict = drawing.createPicture(anchor, pictureIdx); 
         pict.resize(); 
         isi.close(); 
        } 
       } 
      } 
     } 
0

我已經實現了這個problem.Below是提示: jx:each(items="persons" var="person" lastCell="G2" direction="DOWN")

jx:image(lastCell="F2" src="person.portrait") 

希望它適合你。

相關問題