我使用apache poi
将数据写入excel文件,如下所示
String filename="f:/"+mdy+"MonthlyReport.xls";
HSSFWorkbook hwb=new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("MonthlyReport");
HSSFRow rowhead= sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("MONTH_YEAR ");
rowhead.createCell((short) 1).setCellValue("NO_OF_TICKETS ");
rowhead.createCell((short) 2).setCellValue("TOTAL_AMOUNT");
rowhead.createCell((short) 3).setCellValue("NO_OF_AGENTS");
rowhead.createCell((short) 4).setCellValue("AVERAGE_PRICE");
rowhead.createCell((short) 5).setCellValue("PER_DAY_TICKETS");
rowhead.createCell((short) 6).setCellValue("PER_AGENT_TICKETS");
PreparedStatement ps=cn.prepareStatement("select * from MONTHLYREPORTS");
ResultSet rs=ps.executeQuery();
int i=1;
while(rs.next()){
HSSFRow row= sheet.createRow((short)i);
row.createCell((short) 0).setCellValue(rs.getString(1));
row.createCell((short) 1).setCellValue(rs.getInt(2));
row.createCell((short) 2).setCellValue(rs.getInt(3));
row.createCell((short) 3).setCellValue(rs.getInt(4));
row.createCell((short) 4).setCellValue(rs.getInt(5));
row.createCell((short) 5).setCellValue(rs.getInt(6));
row.createCell((short) 6).setCellValue(rs.getInt(7));
i++;
}
FileOutputStream fileOut = new FileOutputStream( filename);
hwb.write(fileOut);
fileOut.close();
我不想将文件另存为
FileOutputStream fileOut = new FileOutputStream( filename);
hwb.write(fileOut);
我想自动打开文件并要求用户保存在自己的路径中。 如何实现它,请帮助我。