Anomalies adding PNG in xlsx - Apache POI 3.9

2019-08-27 06:13发布

问题:

I'm able to add pngs to my xlsx but with a few anomalies: On the last row (only), the image is overlaid on the previous row's image:

I suspect the anchoring:

    int pictureIndex = report.addPicture(curve, XSSFWorkbook.PICTURE_TYPE_PNG);
    anchor.setCol1(7);
    **anchor.setRow1(rowNumber-1);**
    anchor.setCol2(8);
    anchor.setRow2(rowNumber);
    drawing.createPicture(anchor, pictureIndex);

But if I follow the examples I've seen, anchor.setRow1(rowNumber) then my images don't show at all.

Last, is there a way to put the image into a Cell (I would like the option to sort this spreadsheet)?

Thank you.

回答1:

After trying many permutations of setCol and setRow, this eventually worked:

anchor.setCol1(col);
anchor.setRow1(row);
anchor.setCol2(col + 1);
anchor.setRow2(row + 1);