[英]Spring boot : download csv file data with special character
I have a button ,when I click it, I want to download a csv file.我有一个按钮,当我点击它时,我想下载一个 csv 文件。 When my csv file has data, 'big apple.'.当我的 csv 文件有数据时,“大苹果”。 There is no problem generating it.生成它没有问题。
But when i have data like big , apple.
但是当我有像big , apple.
这样的数据时big , apple.
with a comma, The file fails to get generated.使用逗号,文件无法生成。 How do i get my csv file generated with special characters?如何使用特殊字符生成我的 csv 文件?
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"
看看 csv 格式使用"big , apple"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.