poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mehner, Björn" <Bjoern.Meh...@epos-cs.de>
Subject AW: Bug in Sheet.getColumnWidth?
Date Tue, 03 Feb 2004 18:28:06 GMT


> Column widths are done in units of 1/256th of a character width
> (http://jakarta.apache.org/poi/apidocs/org/apache/poi/hssf/use
> rmodel/HSSFShe
> et.html#getColumnWidth(short)).  This is why you got 950 for 
> column 5.  The
> size of 10 is what is returned when the column is the default 
> with (to get
> the actual width call getDefaultColumnWidth).  Also, if you 
> was to change
> the font size used in the column and kept the width in excel 
> the same, the
> size returned would be different (because of the character 
> width).  There
> has been some work and looking into a way to come up with a formula to
> convert from the units used internally in the file and the units excel
> displays.  

To get it right: If the width is 10 this is just a kind of symbol for
"You idiot, this is the default width! You used the wrong method to get
this value?" Why does it not just return null? Or -1? Or why does the
method not call getDefaultColumnWidth on its own when it detects the
default? This is quite misleading. I was jolly happy all the time to get
such nice and easy to handle numbers. This seems to be my mistake and
cause of all my problems.

Thanks for the hint. So we can summarize: Problem was between my ears
sort of :-). Although you must admit this behavior of the method is a
bit strange.

> I'm a little confused when you say that "All following columns of WB2,
> Sheet1, Column5 have the same size".  Are you saying that all 
> the cells for
> column 5 are the same width which is going to be the case 
> because they are
> all in the same column and cannot vary widths (you cannot do 
> it in excel
> either).  

No, I have meant it as "following columns" not cells. But I looked
deeper into it and it seems I have been wrong. Must have missed the one
different number in many columns in the first place. It works correct.
Sorry.

Thanks again for your help and bye!

bye

Björn Mehner

> 
> when I call getColumnWidth(i) on two of my Excels I get confusing
> numbers out of it. Here a example:
> 
> Workbook1, Sheet1, Column0 returns in Excel a width of 10,71 or 80 px.
> HSSFSheet.getColumnWidth(0) says this column is size 10.
> 
> Workbook2, Sheet1, Column5 returns in Excel a width of 1,71 or 17px.
> HSSFSheet.getColumnWidth(5) demands this column has a size of 950(!!!)
> 
> The second column is definitive smaller than that one in the first
> workbook (I can see it and Excel says so, too), but HSSF varies a lot
> with its calculation. 
> If I reduce the size of WB2, Sheet1, Column5 HSSF also calculates a
> lower number, but still a lot bigger than it should be. 
> 
> Next thing I notice is this: All following columns of WB2, Sheet1,
> Column5 have the same size. If I reduce the width of a later 
> column and
> try to read all widths they do not differ: all are 950. Whats wrong
> here?
> 
> I attached the Excel files I am talking of. I removed all the data in
> the sheets, but some merged cells and formats etc. are still there, so
> they might look a little bit odd. But I wanted to preserve as much of
> the formatting as possible. I also attached the relevant code snippet.
> Please have a look at it.
> 
> I want to know, if this is a bug, so I can make a bug report or if the
> problem just exists between my own ears :-).
> 
> Thanks in advance for your help.
> 
> bye 
> 
> Björn Mehner
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-user-help@jakarta.apache.org
> 
> 

Mime
View raw message