不使用 Java 写入新的 xls sheet

Not writing to new xls sheet using Java

我有一个 java 应用程序,它将 sql 语句输出从数据库写入 excel 文件 (xls) 因此,当它达到 xls 的有限行数(大约 65000)时,它会写入一个新的 sheet.

这是之前完成的,它能够写入第二个 sheet,但是当添加新的 sheet(sheet4) 时它不起作用。

我正在使用 JXL 库,我得到的错误是超过最大行数,所以两个 sheet 已满但是当添加第三个时它没有写入

下面是代码。

rs5 只是一个 sql 语句。


WritableSheet sheet2 = workbook.getSheet("ServiceSummary");
                WritableSheet sheet3 = workbook.getSheet("ServiceSummary2");
                WritableSheet sheet4 = workbook.getSheet("ServiceSummary3"); // added third sheet to handle more rows
 
                       
                     // Added sheet4 and if else statement to handle max row exception 65000
                        
                        System.out.println("number of rows in xls" + pos );
                       
                        
                        
                        if (pos > 130000)
                        {
                              System.out.println("third sheet for ServiceSummary3");
                               while(rs5.next()){
                                     sheet4.addCell(new Label(0,1+(counter), customerAccount, arial10format));
                                     sheet4.addCell(new Label(1,1+(counter), rs5.getString(1), arial10format));
                                     sheet4.addCell(new Label(2,1+(counter), rs5.getString(2), arial10format));
                                     sheet4.addCell(new Label(3,1+(counter), rs5.getString(3), arial10format));
                                     sheet4.addCell(new Label(4,1+(counter), rs5.getString(4), arial10format));
                                     sheet4.addCell(new Label(5,1+(counter), rs5.getString(5), arial10format));
                                     sheet4.addCell(new Label(6,1+(counter), rs5.getString(6), arial10format));
                                     sheet4.addCell(new Label(7,1+(counter), rs5.getString(7), arial10format));
                                 try{sheet4.addCell(new Number(8,1+(counter), Double.parseDouble(rs5.getString(8)), arial10format));}catch(Exception e){sheet4.addCell(new Label(8,1+(counter), rs5.getString(8), arial10format));}
                                 try{sheet4.addCell(new Number(9,1+(counter), Double.parseDouble(rs5.getString(9)), arial10format));}catch(Exception e){sheet4.addCell(new Label(9,1+(counter), rs5.getString(9), arial10format));}
                                 try{sheet4.addCell(new Number(10,1+(counter), Double.parseDouble(rs5.getString(10)), arial10format));}catch(Exception e){sheet4.addCell(new Label(10,1+(counter), rs5.getString(10), arial10format));}
                                 counter ++;
                                 pos++;
                             }
                             
                        }
                       
                        else if (pos >= 65000)
                        {
                               
                               while(rs5.next()){
                                 sheet3.addCell(new Label(0,1+(counter), customerAccount, arial10format));
                                 sheet3.addCell(new Label(1,1+(counter), rs5.getString(1), arial10format));
                                 sheet3.addCell(new Label(2,1+(counter), rs5.getString(2), arial10format));
                                 sheet3.addCell(new Label(3,1+(counter), rs5.getString(3), arial10format));
                                 sheet3.addCell(new Label(4,1+(counter), rs5.getString(4), arial10format));
                                 sheet3.addCell(new Label(5,1+(counter), rs5.getString(5), arial10format));
                                 sheet3.addCell(new Label(6,1+(counter), rs5.getString(6), arial10format));
                                 sheet3.addCell(new Label(7,1+(counter), rs5.getString(7), arial10format));
                                 try{sheet3.addCell(new Number(8,1+(counter), Double.parseDouble(rs5.getString(8)), arial10format));}catch(Exception e){sheet3.addCell(new Label(8,1+(counter), rs5.getString(8), arial10format));}
                                 try{sheet3.addCell(new Number(9,1+(counter), Double.parseDouble(rs5.getString(9)), arial10format));}catch(Exception e){sheet3.addCell(new Label(9,1+(counter), rs5.getString(9), arial10format));}
                                 try{sheet3.addCell(new Number(10,1+(counter), Double.parseDouble(rs5.getString(10)), arial10format));}catch(Exception e){sheet3.addCell(new Label(10,1+(counter), rs5.getString(10), arial10format));}
                                 counter ++;
                                 pos++;
                             }
                             
                        }
                       
                        else
                         
                        {
                        
                        while(rs5.next()){
                            sheet2.addCell(new Label(0,1+(pos), customerAccount, arial10format));
                            sheet2.addCell(new Label(1,1+(pos), rs5.getString(1), arial10format));
                            sheet2.addCell(new Label(2,1+(pos), rs5.getString(2), arial10format));
                            sheet2.addCell(new Label(3,1+(pos), rs5.getString(3), arial10format));
                            sheet2.addCell(new Label(4,1+(pos), rs5.getString(4), arial10format));
                            sheet2.addCell(new Label(5,1+(pos), rs5.getString(5), arial10format));
                            sheet2.addCell(new Label(6,1+(pos), rs5.getString(6), arial10format));
                            sheet2.addCell(new Label(7,1+(pos), rs5.getString(7), arial10format));
                            try{sheet2.addCell(new Number(8,1+(pos), Double.parseDouble(rs5.getString(8)), arial10format));}catch(Exception e){sheet2.addCell(new Label(8,1+(pos), rs5.getString(8), arial10format));}
                            try{sheet2.addCell(new Number(9,1+(pos), Double.parseDouble(rs5.getString(9)), arial10format));}catch(Exception e){sheet2.addCell(new Label(9,1+(pos), rs5.getString(9), arial10format));}
                            try{sheet2.addCell(new Number(10,1+(pos), Double.parseDouble(rs5.getString(10)), arial10format));}catch(Exception e){sheet2.addCell(new Label(10,1+(pos), rs5.getString(10), arial10format));}
                            pos++;
                        }}
                      
                        rs5.close();
                        rs5 = null;
                    }
                }

开始第 3 次 sheet 时,您需要将计数器重置为 0。现在 sheet 3 将从第 65000 行开始并向下移动到 65535