我正在从我的矢量创建一张excel表,其中有127923条记录,当我尝试输入记录时,我会遇到异常。
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)
我知道因为excel表不允许超过65536条记录,但是我的代码我试图创建一个新的表单,每次我达到60000标记,但它不起作用。任何人都可以告诉我,我做错了什么。这是我的代码。
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();
}
答案 0 :(得分:7)
您可以将循环代码替换为:
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());
}