微软excel打开csv文件乱码,wps和txt不乱码,java后台解决

/**
* 下载CSV文件
*/
@RequestMapping(value = “/dlcsv/{jobLogId}”, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> downloadCSVFile(@PathVariable Long jobLogId, Model model) throws Exception {
JobLog jobLog = jobLogService.selectById(jobLogId);
JobConf jobConf=jobConfService.selectOne(new EntityWrapper().eq(“job_id”,jobLog.getJobId()));
byte[] file=jobConf.getFilePath();//获取byte数组就是所需内容
/*String csvCon = new String(file,“GBK”);
byte[] file1=csvCon.getBytes(“GBK”);
*/
//下载逻辑还有一个js文件

    String csvContext = new String(file,"gb2312");
    //System.out.println(csvContext);
    String fileName = "origin_data.csv";

    Map<String, String> retmap = new HashMap<>();
    retmap.put("fileContent", "\uFEFF"+csvContext);//解决代码加这一行
   // retmap.put("fileContent", csvContext);
    retmap.put("fileName", fileName);

    return retmap;
}

猜你喜欢

转载自blog.csdn.net/weixin_43190879/article/details/85339236
今日推荐