我已成功在Excel表格中插入图像;但是现在我遇到了很大麻烦,我希望图像集中在一个单元格中,因为当我用图像导出文件时,它们似乎在一个单元格中。但是当我仔细观察时,图像是几毫米使细胞难以工作的细胞图像无法识别它属于哪个单元格。使用Apache POI库。
我希望你能帮助我,谢谢。
这里我发给你一部分代码,
int posReporte = 1;
int posRow = 1;
for (List<Object> dr : datosReportes) {
Row filaReporte = hojaReporte.createRow(posReporte);
for (int a = 0; a < dr.size(); a++) {
Cell celdaD = filaReporte.createCell(angel);*
celdaD.setCellStyle(estiloDatos);
Object obj = dr.get(angel);
if (a == 0) {
hojaReporte.setColumnWidth(a, 180 * 38);
filaReporte.setHeight(Short.valueOf("1500"));
//Add image data to the book
try {
if (directorio("S:\\", dr.get(1) + "_mini")) {
InputStream is = new FileInputStream("S:\\" + dr.get(1) + "_mini.jpg");
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
CreationHelper helper = wb.getCreationHelper();
Drawing drawing = hojaReporte.createDrawingPatriarch();
//Add image
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(o);
anchor.setRow1(posRow);
anchor.setAnchorType(o);
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize();
}
} catch (Exception e) {
continue;
}
}
}
}