TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
使用postman测试下载xls文件,下载的文件名出现中文乱码
- public void exportTeam(AdminInfo adminInfo, SelectTeamDTO dto, HttpServletRequest request, HttpServletResponse response) {
-
- //导出时取消分页
- dto.setPageSize(Integer.MAX_VALUE);
- dto.setPageIndex(1);
-
- //查询数据
- BasePageResponse<SelectTeamVO> teamList = teamManageService.selectTeamPage(adminInfo, dto.getTeamName(), dto.getPageIndex(), dto.getPageSize());
- List<SelectTeamVO> records = teamList.getRecords();
- List<SelectTeamVO> vos = new ArrayList<>();
-
- //设置属性
- records.forEach(p -> {
- SelectTeamVO vo = new SelectTeamVO();
- BeanUtils.copyProperties(p, vo);
- vos.add(vo);
- });
-
- String sheetName = ExportSheetNameEnum.team_sheet;
- String fileName = sheetName + ".xls";
- String[] title = ExportTitleEnum.teamList_title;
-
- String[][] values = new String[vos.size()][title.length];
- for (int i = 0; i < vos.size(); i++) {
- values[i] = new String[title.length];
- SelectTeamVO vo = vos.get(i);
- values[i][0] = vo.getTeamName();
- values[i][1] = vo.getTeamType();
- values[i][2] = vo.getProjectName();
- values[i][3] = vo.getLeaderName();
- values[i][4] = vo.getTeamTypeNo();
- }
-
- //初始化表格设置
- Map<String, Object> map = ExcelUtil.exportFirstSet(sheetName, title);
- HSSFRow row = (HSSFRow) map.get("HSSFRow");
- HSSFSheet sheet = (HSSFSheet) map.get("HSSFSheet");
- HSSFWorkbook wb = (HSSFWorkbook) map.get("HSSFWorkbook");
- //创建内容
- for (int i = 0; i < values.length; i++) {
- row = sheet.createRow(i + 1);
- for (int j = 0; j < values[i].length; j++) {
- row.createCell(j).setCellValue(values[i][j]);
- }
- }
- //设置样式
- ExcelUtil.setHeightWidth(values, null, null, row, sheet);
- //响应到客户端
- try {
- ExcelUtil.setResponseHeader(response, request, fileName);
- OutputStream os = response.getOutputStream();
- wb.write(os);
- os.flush();
- os.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
复制代码
|
|