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
private int getMergedCellsWidth(int rowNumber, int cellNumber)
    {
      Region region = null;
      short fromIndex = (short)cellNumber;
      short toIndex = (short)cellNumber;
      int width = 0;

      int mergedRegionsCount = sheet.getNumMergedRegions();
      // iterate over all regions. Cell can only be in one of them. If we
      // found a region containing this cell we can abort the iteration.
      for (int i = 0; i < mergedRegionsCount; i++) 
      {
        region = sheet.getMergedRegionAt(i);
        if (region.contains(rowNumber + rowOffset, (short)cellNumber))
        {
          fromIndex = region.getColumnFrom();
          toIndex = region.getColumnTo();
          break;
        }
      }

      if (logWriteHandler.isDebugEnabled()) logWriteHandler.debug("Region stretches 
from column " + fromIndex + " to " + toIndex);

      for (short i = fromIndex; i <= toIndex; i++)
      {
        int columnwidth = sheet.getColumnWidth(i);
        if (logWriteHandler.isDebugEnabled()) logWriteHandler.debug("ColumnWidth of 
column " + i + " is " + columnwidth);
        width = width + columnwidth;
        if (logWriteHandler.isDebugEnabled()) logWriteHandler.debug("RegionWidth up to 
now is " + width);
      }
      if (logWriteHandler.isInfoEnabled()) logWriteHandler.info("RegionWidth is " + 
width);
      return width;
    } // end of getMergedCellsWidth()

Attachment: Angebot_de.xls
Description: MS-Excel spreadsheet

Attachment: Leer.xls
Description: MS-Excel spreadsheet

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to