I am creating an excel sheet from my vector which have 127923 records and when I am trying to entering the records I am getting following exception.
jxl.write.biff.RowsExceededException: The maximum number of rows permitted on a worksheet been exceeded
at jxl.write.biff.WritableSheetImpl.getRowRecord(WritableSheetImpl.java:1214)
at jxl.write.biff.WritableSheetImpl.addCell(WritableSheetImpl.java:1151)
at com.ibm.database.excel.WriteExcel.addLabel(WriteExcel.java:176)
at com.ibm.database.excel.WriteExcel.write(WriteExcel.java:76)
at com.ibm.database.excel.FileGenerator.generateExcel(FileGenerator.java:13)
at com.ibm.database.taxoreader.TaxonomyReader.main(TaxonomyReader.java:46)
and I know because excel sheet does not allow more than 65536 records, but I my code I am trying to create a new sheet everytime I hit 60000 mark but It is not working. Could any one suggest me what am I doing wrong. Here is my code.
public void write (Vector list) throws IOException, WriteException{
int k=0,row=0,column=0;
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
// Define the cell format
times = new WritableCellFormat(times10pt);
// Lets automatically wrap the cells
times.setWrap(true);
TaxonomyBean bean= null;
File file = new File("Test.xls");
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
WritableSheet sheet= workbook.createSheet(""+k,k);
for(int i=0,j=0;i<list.size();i++,j++){
if(j==60000){
k=k+1;
workbook.createSheet(""+k, k);
j=0;
}
sheet = workbook.getSheet(k);
bean=(TaxonomyBean)list.elementAt(i);
column=0;row=i;
System.out.println("adding "+bean.getDescription()+" at "+j+" in "+k+" and i "+i);
addLabel(sheet, column, row, bean.getDescription());
column++;
addLabel(sheet, column, row, bean.getTaxonomyDescription());
}
workbook.write();
workbook.close();
}
You can replace your loop code with that :
for(int i = 0;i < list.size();i++)
{
if(i % 60000 == 0)
{
k++;
workbook.createSheet("" + k,k);
}
sheet = workbook.getSheet(k);
bean = (TaxonomyBean)list.elementAt(i);
column = 0;
row = i % 60000;
addLabel(sheet, column, row, bean.getDescription());
column++;
addLabel(sheet, column, row, bean.getTaxonomyDescription());
}