title: Apache POI Width calculations
body: <p>I'm having problems getting the exact size I want with my calculations for columnWidth and my calculated row height because I don't understand the documentation.</p>
  
  <p>In terms of columnWidth, I am using the line of code <code>sheet.setColumnWidth(int columnIndex, int width);</code> but I don't understand how to properly calculate width. I get that it says:</p>
  
  <pre><code>width = Truncate([{Number of Visible Characters} * {Maximum Digit Width} + {5 pixel padding}]/{Maximum Digit Width}*256)/256
  </code></pre>
  
  <p>So I have an exact Excel sheet example of what I want to create and when I highlight a column and select column width it tells me it is <code>9.67 (94 pixels)</code>. So what does this mean? How do I plug this into my equation to get the value of width I want?</p>
  
  <p>The other problem I am having is that I'm using code I found elsewhere (even on SO) to dynamically calculate row height. But my problem is I don't understand what <code>mergedCellWidth</code> in the below code should be in the line that says <code>nextPos = measurer.nextOffset(mergedCellWidth)</code>. I can't seem to get this value quite right and it's messing up how many lines it thinks there should be and therefore my row height isn't right.</p>
  
  <pre><code>java.awt.Font currFont = new java.awt.Font("Calibri", 0, 11);
  AttributedString attrStr = new AttributedString(record.getDescription());
  attrStr.addAttribute(TextAttribute.FONT, currFont);
  
  // Use LineBreakMeasurer to count number of lines needed for the text
  FontRenderContext frc = new FontRenderContext(null, true, true);
  LineBreakMeasurer measurer = new LineBreakMeasurer(attrStr.getIterator(), frc);
  int nextPos = 0;
  int lineCnt = 0;
  
  while (measurer.getPosition() &lt; record.getDescription().length()) {
      System.out.println(measurer.getPosition());
      nextPos = measurer.nextOffset(mergedCellWidth); // mergedCellWidth is the max width of each line
      lineCnt++;
      measurer.setPosition(nextPos);
      System.out.println(measurer.getPosition());
  }
  
  row.setHeight((short)(row.getHeight() * lineCnt));
  </code></pre>
  
  <p>I think in my case examples would be the best answer for me. Thanks!</p>