Hi All
 
I am using POI 3.0 rc4
 
I get wrong column count when I read excel file I created.
 
I use the following method to get Column count:
 
public int getNumberOfColumns(int sheetNumber){
 HSSFRow row = getRow(sheetNumber,2);
 return row.getLastCellNum();
}
 
I always get 1 column less than what I have. If I have 6 columns I get only 5 
as return value.
However, when I open the excel file and make a smal change (any change like 
adjusting column width etc) and save it, the same getNumberOfColumns method 
returns correct columns.
Is there any solution for this problem. Please let me know.

I create excel file programatically
 
ExcelFile excel = new ExcelFile();
excel.createWorkBook();

I add rows like this:
 
public void addRow(int sheetNumber, String content){
  HSSFSheet sheet = (HSSFSheet)wb.getSheetAt(sheetNumber);
  HSSFRow row = sheet.createRow(currentRowNumberBeingAdded);
  currentRowNumberBeingAdded = currentRowNumberBeingAdded + 1;
  
  StringTokenizer st = new StringTokenizer(content,"~");
  int cellNumber = 0;
  while (st.hasMoreTokens()){
       HSSFCell cell = row.createCell((short)cellNumber);
       cell.setCellType(HSSFCell.CELL_TYPE_STRING);
       cell.setCellValue(st.nextToken());
       cellNumber = cellNumber + 1;
  }
  
 }

I save like this:
excel.saveWorkBook(destn);
 
I import these:
 
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
 
Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to