簡體   English   中英

jXLS jx:image 以 java.lang.IllegalArgumentException 結尾:imgBean 值必須包含圖像字節

[英]jXLS jx:image ends with java.lang.IllegalArgumentException: imgBean value must contain image bytes

我想用 jXLS 2.2.3 在 XLS 文件模板中放置一個圖像

XLS 模板定義如下:

單元格 A1,添加注釋:jx:area(lastCell="L10")

單元格 A10,添加注釋:jx:each(items="rows" var="r" lastCell="L10")

單元格 D10,添加注釋:jx:image(imgBean="r.barcodeJpgImage" imageType="JPEG" lastCell="L10")

當我執行代碼時:

        ByteArrayOutputStream fos = new ByteArrayOutputStream();
        //fis is template file input stream, fos is the output
        Transformer transformer = TransformerFactory.createTransformer(fis, fos);
        AreaBuilder areaBuilder = new XlsCommentAreaBuilder(transformer);
        List<Area> xlsAreaList = areaBuilder.build();
        Area xlsArea = xlsAreaList.get(0);
        Context context = new Context();
        for (Map.Entry<String, Object> entry : beans.entrySet()) {
            context.putVar(entry.getKey(), entry.getValue());
        }
        xlsArea.applyAt(new CellRef(0,0), context);
        transformer.write();

我得到這個例外:

引起:java.lang.IllegalArgumentException:imgBean 值必須包含 org.jxls.command.ImageCommand.applyAt(ImageCommand.java:76) 處的圖像字節 (byte[]) 在 org.jxls.area.XlsArea.applyAt(XlsArea. java:142) 在 org.jxls.command.EachCommand.applyAt(EachCommand.java:177) 在 org.jxls.area.XlsArea.applyAt(XlsArea.java:142)

變量r.barcodeJpgImage不為空並且包含 JPEG 圖像字節。

知道可能有什么問題嗎?!

  1. 升級到 jxls-2.2.5 或更高版本
  2. 像這樣指定圖像命令

    jx:image(src="r.barcodeJpgImage" imageType="JPEG" lastCell="L10")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM