Java POI 使用 XSSFClientAnchor 在 Excel 中添加多张图片
int cellNum = 0; JSONObject temp = new JSONObject(data.optString(i)); for(cellNum=0;cellNum<displayKeys.length+2;cellNum++) { String value = temp.optString(dataKeys[cellNum]); System.out.println('value============' + value);
if(dataKeys[cellNum].equals('images'))
{
JSONArray images = temp.optJSONArray('images');
if(images != null)
{
for(int j=0; j<images.length(); j++)
{
String imageUrl = images.optString(j);
URL imageUrlObj = new URL(imageUrl);
InputStream imageStream = imageUrlObj.openStream();
byte[] byteArray = IOUtils.toByteArray(imageStream);
int pictureIndex = wb.addPicture(byteArray, Workbook.PICTURE_TYPE_JPEG);
XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cellNum, i+rowcount, (short) (cellNum+1), i+rowcount+1);
XSSFPicture picture = patriarch.createPicture(anchor, pictureIndex);
picture.resize();
}
}
}
else
{
CellUtil.createCell(r, cellNum, value);
}
}
原文地址: https://www.cveoy.top/t/topic/qDbT 著作权归作者所有。请勿转载和采集!