Commit b473858c by 伍思炜

Excel文件下载

parent f32f8e99
...@@ -137,10 +137,6 @@ public class ExportService extends BaseController { ...@@ -137,10 +137,6 @@ public class ExportService extends BaseController {
userId = Integer.parseInt(map.get("userId").toString()); userId = Integer.parseInt(map.get("userId").toString());
} }
List<Integer> userIds = (List<Integer>) map.get("userIds"); List<Integer> userIds = (List<Integer>) map.get("userIds");
EntityWrapper<Order> wrapper = new EntityWrapper(); EntityWrapper<Order> wrapper = new EntityWrapper();
...@@ -235,10 +231,21 @@ public class ExportService extends BaseController { ...@@ -235,10 +231,21 @@ public class ExportService extends BaseController {
columns.add("parent_name"); columns.add("parent_name");
columns.add("student_number"); columns.add("student_number");
columns.add("class_number"); columns.add("class_number");
ServletOutputStream os = null;
XSSFWorkbook workbook = new XSSFWorkbook(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
String formatPath = format.format(new Date());
String filePath = FilePath.IMPORTPATH.getValue()+formatPath;
String fileName = "订单"+new Date().getTime()+".xls";
String filePath1 = FilePath.IMPORTPATH.getValue()+formatPath+"/"+fileName;
File dir = new File(filePath);
if (!dir.exists()) {
dir.mkdirs();
}
FileOutputStream os = null;
XSSFWorkbook workbook = null;
try { try {
workbook = new XSSFWorkbook(); workbook = new XSSFWorkbook();
os = new FileOutputStream(filePath1);
//创建工作表 //创建工作表
XSSFSheet sheet = workbook.createSheet("订单清单"); XSSFSheet sheet = workbook.createSheet("订单清单");
//添加表头 //添加表头
...@@ -305,13 +312,14 @@ public class ExportService extends BaseController { ...@@ -305,13 +312,14 @@ public class ExportService extends BaseController {
} }
} }
} }
HttpServletResponse response = getHttpServletResponse();
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream");
os = response.getOutputStream();
workbook.write(os); workbook.write(os);
os.flush(); ExportExcel exportExcel = new ExportExcel();
exportExcel.setCreateTime(new Date());
exportExcel.setCreateUser(Integer.parseInt(map.get("userId").toString()));
exportExcel.setCreateName(map.get("userName").toString());
exportExcel.setExportUrl(filePath1);
exportExcel.setFileName(fileName);
exportExcelMapper.insert(exportExcel);
} catch (Exception e) { } catch (Exception e) {
log.error("文件出错!" + e.getMessage(), e); log.error("文件出错!" + e.getMessage(), e);
} finally { } finally {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment