I have a button ,when I click it, I want to download a csv file. When my csv file has data, 'big apple.'. There is no problem generating it.
But when i have data like big , apple.
with a comma, The file fails to get generated. How do i get my csv file generated with special characters?
window.location.href = '/coaGlCsv?coaId='+coaType+'';
@RequestMapping(value = "/coaGlCsv", method = RequestMethod.GET)
@ResponseBody
public void getCsv(HttpServletRequest request, HttpServletResponse response,
@RequestParam("coaId") String coaId) {
System.out.println("Generate excel");
response.setContentType("text/csv");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + reportName);
PrintWriter out = response.getWriter();
out.println("date","name");
out.println("12-07-2019","big apple.");
}
What do you mean
file fails to get generated
Can you download file from the server? Does server throw an exception? If so - provide it in your question.
Double quotes can solve your problem with data with a comma. Take a look at csv format Use "big , apple"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.