Column widths are done in units of 1/256th of a character width (http://jakarta.apache.org/poi/apidocs/org/apache/poi/hssf/usermodel/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.
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). Shawn -----Original Message----- From: "Mehner, Bj�rn" [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 03, 2004 11:37 AM To: POI Users List (E-Mail) Subject: Bug in Sheet.getColumnWidth? Hi there everybody, 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
