When the data volume is large and exceeds 65536, the following error occurs during export:
Jxl. write. biff. RowsExceededException: The maximum number of rows permitted on a worksheet been exceeded
(Explanation: jxl. write. biff. RowsExceededException: the maximum number of rows allowed in the worksheet has exceeded)
Therefore, my solution is to export multiple work tables.
Public static void outputExcelData () throws IOException, WriteException {
/** Save the value to the List */
List result = new ArrayList ();
User user = new User ();
User. setId ("1 ");
User. setName ("yfli ");
Result. add (user );
User user2 = new User ();
User2.setId ("1 ");
User2.setName ("zhangjie ");
Result. add (user2 );
User user3 = new User ();
User3.setId ("1 ");
User3.setName ("lzhang ");
Result. add (user3 );
String fileName = "F :\\ sfData.xls ";
// First, use the Workbook class factory method to create a writeable Workbook object.
WritableWorkbook wwb = Workbook. createWorkbook (new File (fileName ));
File dbfFile = new File (fileName );
If (! DbfFile. exists () | dbfFile. isDirectory ()){
DbfFile. createNewFile ();
}
Int totle = result. size (); // gets the size of the List set.
Int mus = 2; // a maximum of 2 data records can be stored in a worksheet in an excel worksheet)
Int avg = totle/mus;
For (int I = 0; I <avg + 1; I ++ ){
WritableSheet ws = wwb. createSheet ("list" + (I + 1), I); // create a writable Worksheet
// Add a header
Ws. addCell (new Label (0, 0, "Serial Number "));
Ws. addCell (new Label (1, 0, "name "));
Int num = I * mus;
Int index = 0;
For (int m = num; m <result. size (); m ++ ){
If (index = mus) {// when determining index = mus, the current for loop exists.
Break;
}
User use = (User) result. get (m );
// Add the generated cells to the worksheet
// (Note that in Excel, the first parameter table represents the column and the second parameter represents the row)
Ws. addCell (new Label (0, index + 1, use. getId ()));
Ws. addCell (new Label (1, index + 1, use. getName ()));
Index ++;
}
}
Wwb. write (); // write data to the file from the memory
Wwb. close (); // close the resource and release the memory.
}