response.setContentType("application/csv;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
OutputStream os = null;
try {
// String ids = request.getParameter("ids");
// List<ReportInfo> reportInfos =
// hkBillService.exportHKCustomerInfo(ids);
List<ReportInfo> reportInfos = hkBillService.exportHKCustomerInfo();
// 拼装文件名:当前时间.xls
String fileName = new String("customerInfo.csv".getBytes(), "ISO-8859-1");
// 获取excel生成的路径包括文件名
response.addHeader("Content-Disposition",
"attachment;filename=" + java.net.URLEncoder.encode(fileName, "utf-8"));
PrintWriter responseWriter = response.getWriter();
responseWriter.write(0xFEFF);
CSVWriter writer = new CSVWriter(responseWriter);
writer.writeNext(totalDataHeader);
for (ReportInfo detail : reportInfos) {
writer.writeNext(setDetialDataToExcel(detail)); //写入String数组
}
writer.close();
} catch (Exception e) {
log.error(e);
return "ERR";
} finally {
// 别忘记关闭流
if (null != os) {
try {
os.close();
} catch (IOException e) {
log.error(e.getMessage());
}
}
}
return null;
转载请注明原文地址: https://ju.6miu.com/read-9542.html