0
我能夠使用apache poi創建excel文件,但我將如何讓用戶下載將在服務器上創建的excel文件?我如何使用戶能夠下載服務器上創建的excel文件
public String export(UserDetails user) throws Exception {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
List<UserDetails> lstUserDetail = getUserDetailList();
for (short RowNum=1; RowNum<lstUserDetail.size();RowNum++){
HSSFRow row = sheet.createRow(RowNum);
UserDetails userDetail = lstUserDetail.get(RowNum);
HSSFCell cell1 = row.createCell((short)0);
HSSFCell cell2 = row.createCell((short)1);
HSSFCell cell3 = row.createCell((short)2);
HSSFCell cell4 = row.createCell((short)3);
cell2.setCellValue(userDetail.getStrUserName());
cell3.setCellValue(userDetail.getStrEMail());
cell4.setCellValue(userDetail.getStrUserPhone());
cell5.setCellValue(userDetail.getStrUserAddress());
}
FileOutputStream fileOut = new FileOutputStream("E:\\workbook.xls");
wb.write(fileOut);
fileOut.close();
return null;
}
但是當代碼將在服務器上進行部署,我不知道該文件的位置....「E:\\ workbook.xls」是我在我的硬盤上的位置...如果我不知道創建文件的位置,我該怎麼辦? – user2550165
PLZ幫助我關於以上? – user2550165