As far as I was concerned about jxl, I never found a way to insert an image without associating the aspect ratio with the cells instead of pixels / inches / any standard unit of measurement, and I have done decent research in the past with this.
The best you can do is adapt the images to the height / width of the cells you are inserting, or even better, set the width and height of the cell for the cells in which you are placing the image.
From the JExcel FAQ- http://jexcelapi.sourceforge.net/resources/faq/
private static final double CELL_DEFAULT_HEIGHT = 17; private static final double CELL_DEFAULT_WIDTH = 64; File imageFile = new File(GIF_OR_JPG_IMAGE_FILE); BufferedImage input = ImageIO.read(imageFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(input, "PNG", baos); sheet.addImage(new WritableImage(1,1,input.getWidth() / CELL_DEFAULT_WIDTH, input.getHeight() / CELL_DEFAULT_HEIGHT,baos.toByteArray()));
To maintain aspect ratio, you must also set the WritableImage parameter to not change if the user changes the row height or column width. Do this with any of the following (the preference depends on whether you want the image snapping to be locked or to move with resizing):
WritableImage.MOVE_WITH_CELLS; WritableImage.NO_MOVE_OR_SIZE_WITH_CELLS;
king14nyr
source share