Java JXL exception with largest row
•
Java
I am creating an excel table from my vector, which contains 127923 records. When I try to enter records, I will encounter exceptions
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)
I know because excel does not allow more than 65536 records, but my code I try to create a new form every time I reach 60000 tags, but it doesn't work Anyone can tell me what I did wrong This 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,bean.getTaxonomyDescription()); } workbook.write(); workbook.close(); }
Solution
You can replace the loop code with the following code:
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,bean.getDescription()); column++; addLabel(sheet,bean.getTaxonomyDescription()); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码