Bug 51098

Summary: Error in calculating image width/height, if image fits into one cell
Product: POI Reporter: kleindienst
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Modified java file with bug fixed

Description kleindienst 2011-04-21 02:03:42 UTC
Created attachment 26918 [details]
Modified java file with bug fixed

Overview

The calculation of image width and height in the class
  XSSFPicture
of the package
  org.apache.poi.xssf.usermodel
has a bug:

If an image fits into one cell (in the second or one of the following columns), the width calculation leads to wrong results, because cw is taken from the next column, which is not relevant in that case:
  double cw = getColumnWidthInPixels(col2 + 1);
A quick and dirty solution would be to check, if the last column (col2) is the same as the first and calculate the dx2 accordingly:
  if (col2 == anchor.getCol1()) {
     = (int) (EMU_PER_PIXEL * scaledWidth);
  }
Same for image height.


Steps to Reproduce

Just ad an image to a an XLSX which fits into one cell (using the XSSF model).


Build Date & Platform

poi-3.7-20101029 on Windows


Attachment

The java file with the corrections is attached. (However, there might be a better way to solve this.)
Comment 1 Yegor Kozlov 2011-05-27 18:46:30 UTC
Fixed in r1128422

Yegor