Bug 46569 - Image is reversed on a very wide column.
Summary: Image is reversed on a very wide column.
Status: RESOLVED WONTFIX
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.1-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-20 20:58 UTC by Pooja
Modified: 2009-02-06 18:07 UTC (History)
0 users



Attachments
sample program to demonstrate issue (4.58 KB, text/plain)
2009-01-20 20:58 UTC, Pooja
Details
updated standalone sample junit to demonstrate the problem (4.73 KB, text/plain)
2009-02-04 23:06 UTC, Pooja
Details
Image used by sample program (2.70 KB, image/jpeg)
2009-02-04 23:09 UTC, Pooja
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pooja 2009-01-20 20:58:05 UTC
Created attachment 23146 [details]
sample program to demonstrate issue

I am creating and excel worksheet , the width of whose columns may vary. There is an image on the top row - anchores to one of the last columns of the sheet. 
When the width of the column containing the image is very wide (say 1000 pixels), the image is reversed and placed on the column before the column where the image is anchored. A sample program to demonstrate the issue is attached.
Comment 1 Nick Burch 2009-01-21 03:06:28 UTC
I haven't looked into this at all, but I wonder if it might be a signed vs unsiged 16 bit integer issue. That'd be my first hunch on where to investigate
Comment 2 Yegor Kozlov 2009-02-02 07:20:35 UTC
Your sample programs uses unresolved ReportWriterHelper.convertPixelsToCharacters and ReportWriterHelper.convertPixelsToPoints. Please re-attach an isolated test case. 
Also attach the image you are using for the header. 

Yegor
Comment 3 Pooja 2009-02-04 23:06:43 UTC
Created attachment 23231 [details]
updated standalone sample junit to demonstrate the problem
Comment 4 Pooja 2009-02-04 23:09:48 UTC
Created attachment 23232 [details]
Image used by sample program

Please update the path of the image file on line 91 of the sample program to point to this image file.
Comment 5 Pooja 2009-02-04 23:14:03 UTC
The standalone junit to demonstrate the issue and the image file used are uploaded. 
Please update file path in line 91 of sample program to point to the image file attached.
If you comment line 46 where the width of the column is set to a very large value, the excel generated has the image placed properly. Uncomment it and the image in the excel is reversed.
Comment 6 Yegor Kozlov 2009-02-06 10:40:37 UTC
Nick's supposition is right, it is a signed vs unsiged 16 bit integer issue.

1. The following fragment (lines 64-66) is wrong:

                float cellWidth = convertPixelsToCharacters(columnWidths[c] * 256f);

                sheet.setColumnWidth((short) (columnIndex), (short) cellWidth);

If cellWidth > Short.MAX_VALUE then the casting to short produces a negative value.

2. setColumnWidth / getColumnWidth with short arguments are deprecated. 
Use
setColumnWidth(int columnIndex, int width) 
and 
int getColumnWidth(int columnIndex) 

In particular, getColumnWidth(short columnIndex)  return a short value. If column width measured in 1/256th units is in the interval [32767, 65536] 
then this method returns a negative value which is evidently incorrect.

3. The maximum column width for an individual cell in Excel is 255 characters. I changed the code to throw IllegalArgumentException if this limit is exceeded.

Regards,
Yegor
Comment 7 Josh Micich 2009-02-06 18:07:07 UTC
(In reply to comment #6)
> ...
> 3. The maximum column width for an individual cell in Excel is 255 characters.
> I changed the code to throw IllegalArgumentException if this limit is exceeded.
> ...

svn r741678