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();
我得到这个异常:
Caused by: java.lang.IllegalArgumentException: imgBean value must contain image bytes (byte[])
at org.jxls.command.ImageCommand.applyAt(ImageCommand.java:76)
at org.jxls.area.XlsArea.applyAt(XlsArea.java:142)
at org.jxls.command.EachCommand.applyAt(EachCommand.java:177)
at org.jxls.area.XlsArea.applyAt(XlsArea.java:142)
变量 r.barcodeJpgImage
不为空且包含 JPEG 图像字节。
知道哪里出了问题吗?!
- 升级到 jxls-2.2.5 或更高版本
像这样指定Image-command
jx:image(src="r.barcodeJpgImage" imageType="JPEG" lastCell="L10")
我想用 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();
我得到这个异常:
Caused by: java.lang.IllegalArgumentException: imgBean value must contain image bytes (byte[]) at org.jxls.command.ImageCommand.applyAt(ImageCommand.java:76) at org.jxls.area.XlsArea.applyAt(XlsArea.java:142) at org.jxls.command.EachCommand.applyAt(EachCommand.java:177) at org.jxls.area.XlsArea.applyAt(XlsArea.java:142)
变量 r.barcodeJpgImage
不为空且包含 JPEG 图像字节。
知道哪里出了问题吗?!
- 升级到 jxls-2.2.5 或更高版本
像这样指定Image-command
jx:image(src="r.barcodeJpgImage" imageType="JPEG" lastCell="L10")