我试图使用Apache POI将报告以xlsx
格式导出。以下是用于的代码。
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);
}
总行数仅为200000。但是在处理时,我收到无效行号错误。这里是输出。
im here
im here1
im here2
java.lang.IllegalArgumentException: Invalid row number (-32768) outside allowable range (0..1048575)
最佳答案
短裤(您要投射到的)可以代表的最高值是32,767,之后它会折回到-32768。
XSSFSheet.createRow使用int
,因此您无需强制转换您的电话号码。