相关疑难解决方法(0)

Apache poi 在图像中放置超链接

这是我用于在 Excel 中插入图像作为图标的方法:

public void insertIcons(String URL, Sheet sheet, int colBegin, int colEnd, int rowBegin, int rowEnd) {
    try {
        InputStream iconInput = new FileInputStream(URL);
        byte[] byteTransf = IOUtils.toByteArray(iconInput);
        int pictureIdx = workbook.addPicture(byteTransf, org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_PNG);
        iconInput.close();


        CreationHelper helper = workbook.getCreationHelper();
        Drawing drawingIcon = sheet.createDrawingPatriarch();

        ClientAnchor anchorIcon = helper.createClientAnchor();
        anchorIcon.setCol1(colBegin);
        anchorIcon.setCol2(colEnd);
        anchorIcon.setRow1(rowBegin);
        anchorIcon.setRow2(rowEnd);

        Picture iconReady = drawingIcon.createPicture(anchorIcon, pictureIdx);
        iconReady.resize(1);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我使用这种方法来创建图标:

insertIcons(".idea/Icons/table.png", sheetName, 4, 4, 6, 9);
Run Code Online (Sandbox Code Playgroud)

是否可以在此图标中放置超链接以转到同一电子表格中的另一个工作表或网站?

我读到显然 POI 不支持,但使用底层的低级 API 是可能的。但是我还没有能够真正成功地使用它。

有什么建议?

java excel apache-poi

1
推荐指数
1
解决办法
1192
查看次数

标签 统计

apache-poi ×1

excel ×1

java ×1