摘要:使用java寫入EXCEL與CSV
使用java寫入EXCEL與CSV
//方法一:透過hssf寫入內容至fos
HSSFWorkbook wb = new HSSFWorkbook();
createSheet1(wb, typeId);
FileOutputStream fos = new FileOutputStream("file.xls");
wb.write(fos);
fos.flush();
fos.close();
//方法二:fos寫入內容至file
FileOutputStream fos = new FileOutputStream("file.csv");
fos.write("內容".getBytes());
fos.flush();
fos.close();
//Spring 回傳Resource
public @ResponseBody Resource fullCsv(@PathVariable String typeId) throws IOException {
//透過方法一或二傳入file
File file = new File(filenm);
Resource fileResource = new FileSystemResource(file);
Resource resource = new DownloadableResource(fileResource, filenm);
return resource;
}