我試圖使用Apache POI將報告導出爲xlsx
格式。以下是用於的代碼。無效的行號(-32768)超出允許範圍(0..1048575)
public static void main(String[]args){
try{
XSSFWorkbook wb=new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("new sheet");
XSSFRow rowhead= sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("column1");
rowhead.createCell((short) 1).setCellValue("column2");
rowhead.createCell((short) 2).setCellValue("column3");
rowhead.createCell((short) 3).setCellValue("column4");
rowhead.createCell((short) 4).setCellValue("column5");
System.out.println("im here");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:...,....);
Statement st=con.createStatement();
System.out.println("im here1");
ResultSet rs=st.executeQuery("SELECT * FROM table3 ");
System.out.println("im here2");
int i=1;
while(rs.next()){
XSSFRow row= sheet.createRow((short)i);
row.createCell((short) 0).setCellValue(rs.getString("column1"));
row.createCell((short) 1).setCellValue(rs.getString("column2"));
row.createCell((short) 2).setCellValue(rs.getString("column3"));
row.createCell((short) 3).setCellValue(rs.getString("column4"));
row.createCell((short) 4).setCellValue(rs.getString("column5"));
i++;
}
FileOutputStream fileOut = new FileOutputStream(new File("E:/report.xlsx"));
wb.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
} catch (Exception ex) {
System.out.println(ex);
}
總行數只有20萬。但是,當處理,我收到無效的行號error.Here是輸出。
im here
im here1
im here2
java.lang.IllegalArgumentException: Invalid row number (-32768) outside allowable range (0..1048575)
錯誤已經一去不復返了。現在'線程中的異常'主要「java.lang.OutOfMemoryError:Java堆空間」 - 我有我的'JAVA_OPTS = -Xms64m -Xmx516m -XX:MaxPermSize = 1024m' – NaaN
@tailorBird增加可用內存量然後 – awksp
感謝所有。我們可以使用'SXSSF'(Streaming Usermodel API)。 – NaaN