这是我的代码片段
try{
response.setHeader("Content-Disposition", "attachment;filename=someName.xls");
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(1);
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("Rajesh Kumar ");
row.createCell((short)3).setCellValue(true);
FileOutputStream fileOut = new FileOutputStream("C:/Excels/workbook.xls");
wb.write(fileOut);
fileOut.close();
response.getOutputStream().flush();
} catch ( Exception ex ) {
ex.printStackTrace();
}
上面的代码片段在硬盘上成功创建了文件。但是,每当打开 excel 表时,它是空白的?
是什么原因 ?什么可以解决?