英文:
Include an image to the right of a Header in Excel in Java using POI
问题
下面是您的翻译内容:
private static void drawImageOnExcelSheet(XSSFSheet sheet, int row, int col, int height, int width, int pictureIdx)
throws Exception {
CreationHelper helper = sheet.getWorkbook().getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor1 = helper.createClientAnchor();
anchor1.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
anchor1.setRow2(row); // 第二个锚点确定右下位置
anchor1.setCol2(col);
anchor1.setDx2(Units.toEMU(width)); // dx = 左边界 + 所需宽度
anchor1.setDy2(Units.toEMU(height)); // dy = 顶边界 + 所需高度
Picture pic = drawing.createPicture(anchor1, pictureIdx);
pic.resize();
}
英文:
I want to add image to the right side of Header in Excel in java using POI. Below is my sample code
private static void drawImageOnExcelSheet(XSSFSheet sheet, int row, int col, int height, int width, int pictureIdx)
throws Exception {
CreationHelper helper = sheet.getWorkbook().getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor1 = helper.createClientAnchor();
anchor1.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
anchor1.setRow2(row); // second anchor determines bottom right position
anchor1.setCol2(col);
anchor1.setDx2(Units.toEMU(width)); // dx = left + wanted width
anchor1.setDy2(Units.toEMU(height)); // dy= top + wanted height
Picture pic = drawing.createPicture(anchor1, pictureIdx);
pic.resize();
}
答案1
得分: 3
我在答案中贴了一个stackoverflow的参考链接,因为我没有评论的权限。
请参阅https://stackoverflow.com/questions/51077404/apache-poi-adding-watermark-in-excel-workbook/51103756#51103756,了解如何在Excel中设置图像作为页眉内容。
英文:
I'm posting a stackoverflow reference in answer as i don't have privilege to comment.
See https://stackoverflow.com/questions/51077404/apache-poi-adding-watermark-in-excel-workbook/51103756#51103756 for how to set an image as header content in Excel
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论