Sur un HSSFWorkbook avec une police personnalisée j'ai fait ce qui suit pour obtenir un logo à afficher dans les bonnes dimensions:
CreationHelper helper = wb.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setDx1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
anchor.setDx2(LOGO_WIDTH_IN_FUNNY_POI_FORMAT * XSSFShape.EMU_PER_PIXEL);
anchor.setDy1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(LOGO_HEIGHT_IN_FUNNY_POI_FORMAT * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
Où je LOGO_HEIGHT ... et LOGO_WIDTH .. à la taille de pixel désiré de l'image
L'image résultante n'était pas à son rapport d'origine et non à la taille de pixel attendue. J'ai donc utilisé le rapport taille/taille actuelle attendu et j'ai ajusté LOGO_WIDTH .. et LOGO_HEIGHT .. en conséquence. Pas beau, mais cela fonctionne:/
Et n'appelez pas Picture.resize()
après.
Voir Apache POIU Bug 52504 ou this newsgroup discussion about poi Picture.resize()
et POI quick guide for inserting pictures.
Mise à jour: code actuel ressemble à ceci, l'image originale est 2000x450:
LOGO_MARGIN = 2;
int index = getLogoPictureIndex();
CreationHelper helper = this.wb.getCreationHelper();
Drawing drawing = this.sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setDx1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
anchor.setDy1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
Picture pic = drawing.createPicture(anchor, index);
pic.resize(0.064);
Salut, je pense que j'ai un problème un peu similaire ici: http://stackoverflow.com/questions/28298947/npoi-images-created-in-foreach-loop-not-resizing-correctly et je voulais vous demander ce que votre "LOGO_MARGIN" et en particulier les moyens "IN_FUNNY_POI_FORMAT". Cordialement, Dominik – Dominik
@Dominik Je n'ai pas trouvé votre question, mais j'ai ajouté le code actuel, il utilise LOGO_MARGIN = 2 et j'appelle pic.resize après :-) – flob
yeh, disons que j'étais ... stupide. sry pour le désagrément :) thx, cependant. – Dominik