3

我正在从包含 127923 条记录的向量创建一个 excel 表,当我尝试输入记录时,我遇到了以下异常。

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();

}
4

1 回答 1

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());
}
于 2012-12-01T10:15:10.353 回答