title: Optimal Column Width OpenOffice Calc
body: <p>I'm entering data from a CSV file into a OpenOffice spreadsheet. </p>
  
  <p>This code gets the a new sheet in a spreadsheet:</p>
  
  <pre><code>Public Spreadsheet getSpreadsheet(int sheetIndex, XComponent xComp) 
  { 
    XSpreadsheet xSheets = ((XSpreadsheetDocument)xComp).getSheets();
    XIndexAccess xSheetIA = (XIndexAccess)xSheets;
    XSpreadsheet XSheet = (XSpreadsheet)xSheetsA.getByIndex(sheetIndex).Value; 
    return XSheet;
  }
  </code></pre>
  
  <p>I then have method that enters a list into a cell range one cell at a time. I want to be able to automatically set the column size for these cells. which is something like </p>
  
  <pre><code>string final DataCell; 
  Xspreadsheet newSheet = getSpreadsheet(sheetIndex, xComp);
  int numberOfRecords = ( int numberOfColumns * int numberOfRows); 
  for(cellNumber = 0; cellNumber &lt; numberOfrecords; cellNumber++)
  {
    XCell tableData = newSheet.getCellbyPosition(columnValue, rowValue);
    ((XText)tableData).setString(finalDataCell);
    column Value++; 
    if(columnValue &gt; = numberOfColumns)
    {
      rowVal++ column = 0; 
    } 
  }
  </code></pre>
  
  <p>After googling i have found the function: </p>
  
  <p><code>columns.OptimalWidth = True</code> on <a href="http://forum.openoffice.org/en/forum/viewtopic.php?f=20&amp;t=31292" rel="nofollow">http://forum.openoffice.org/en/forum/viewtopic.php?f=20&amp;t=31292</a></p>
  
  <p>but im unsure on how to use this. Could anyone explain this further or think of another way to have the cell autofit? </p>