public R<Boolean> exportCsv(HttpServletResponse response, @RequestBody DrQueryDto queryDto) throws Exception { Integer countyId = queryDto.getCountyId(); String yearAnnual = queryDto.getYearAnnual(); String url = "E:\\" + queryDto.getCountyName() + "\\"; String urlCounty = "E:\\" + queryDto.getCountyName(); File fileCounty = new File(urlCounty); if (!fileCounty.exists()) { fileCounty.mkdir(); } File fi = new File(url); if (!fi.exists()) { fi.mkdir(); } Map<String, List<String[]>> exportData = workService.exportCSV(countyId, yearAnnual); Set<String> keySet = exportData.keySet(); for (String s : keySet) { String csvFileName = s + ".csv"; File file = new File(url + csvFileName); if (!file.exists()) { file.createNewFile(); } CSVWriter csvWriter = new CSVWriter(new FileWriter(url + csvFileName)); String[] title = {"name", "value"}; // 添加第一行到CSV文件 csvWriter.writeNext(title,false); List<String[]> list = exportData.get(s); if (CollectionUtils.isNotEmpty(list)) { for (int i = 0; i < list.size(); i++) {
//false:格式不包含双引号,true:包含双引号 默认值为false
csvWriter.writeNext(list.get(i),false); } } csvWriter.close(); } return R.ok(true); }
标签:文件,false,String,queryDto,导出,File,new,csv,csvWriter From: https://www.cnblogs.com/myself1012/p/18026616