response.setContentType("application/vnd.ms-excel:UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=myOutputFile.csv");
// Excel does not recongize the UTF-8, add additional header (BOM) for excel
OutputStream outputStream = response.getOutputStream();
outputStream.write(0xEF);
outputStream.write(0xBB);
outputStream.write(0xBF);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
// Your method that generate the CSV content
writeSth(writer);
writer.flush();
writer.close();
response.setHeader("Content-Disposition", "attachment; filename=myOutputFile.csv");
// Excel does not recongize the UTF-8, add additional header (BOM) for excel
OutputStream outputStream = response.getOutputStream();
outputStream.write(0xEF);
outputStream.write(0xBB);
outputStream.write(0xBF);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
// Your method that generate the CSV content
writeSth(writer);
writer.flush();
writer.close();
No comments:
Post a Comment