| | |
| | | import com.xiaopeng.maintenance.service.IXpShiftService; |
| | | import com.xiaopeng.maintenance.vo.*; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.hssf.util.HSSFColor; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.net.URLEncoder; |
| | | import java.time.DayOfWeek; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | |
| | | LocalDate parse1 = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | int dayOfMonth = parse1.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); |
| | | HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); |
| | | HSSFCellStyle cellStyle = hssfWorkbook.createCellStyle(); |
| | | cellStyle.setAlignment(HorizontalAlignment.CENTER); |
| | | cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | HSSFSheet hssfSheet = hssfWorkbook.createSheet(); |
| | | hssfSheet.setColumnWidth(0, 6 * 256); |
| | | hssfSheet.setDefaultRowHeightInPoints(20f); |
| | | |
| | | HSSFCellStyle cellStyle1 = hssfWorkbook.createCellStyle(); |
| | | cellStyle1.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.index); |
| | | cellStyle1.setAlignment(HorizontalAlignment.CENTER); |
| | | cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | |
| | | //添加第一行标题 |
| | | HSSFRow hssfRow = hssfSheet.createRow(0); |
| | |
| | | //设置表头样式,合并单元格 |
| | | CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0); |
| | | hssfSheet.addMergedRegion(region); |
| | | region = new CellRangeAddress(0, 1, dayOfMonth + 1, totalCell); |
| | | region = new CellRangeAddress(0, 1, dayOfMonth + 1, totalCell - 1); |
| | | hssfSheet.addMergedRegion(region); |
| | | |
| | | |
| | | //设置单元格数据 |
| | | for (int i = 0; i < totalCell; i++) { |
| | | HSSFCell cell = hssfRow.createCell(i); |
| | | cell.setCellStyle(cellStyle1); |
| | | if(0 == i){ |
| | | cell.setCellValue("车队"); |
| | | }else if(i <= dayOfMonth){ |
| | |
| | | //设置单元格数据 |
| | | for (int i = 0; i < totalCell; i++) { |
| | | HSSFCell cell = hssfRow1.createCell(i); |
| | | cell.setCellStyle(cellStyle1); |
| | | if(i > 0 && i <= dayOfMonth){ |
| | | LocalDate parse = LocalDate.parse(month + "-" + String.format("%02d", i), DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | String week = ""; |
| | |
| | | int rowNum = 2; |
| | | for (SchedulingDetailDto schedulingDetailDto : schedulingDetailDtos) { |
| | | HSSFRow row = hssfSheet.createRow(rowNum); |
| | | row.createCell(0).setCellValue(schedulingDetailDto.getFleetName()); |
| | | HSSFCell cell = row.createCell(0); |
| | | cell.setCellStyle(cellStyle); |
| | | cell.setCellValue(schedulingDetailDto.getFleetName()); |
| | | |
| | | String days = schedulingDetailDto.getDays(); |
| | | if (StringUtils.isNotBlank(days)) { |
| | |
| | | } |
| | | } |
| | | |
| | | row.createCell(i).setCellValue(shiftName); |
| | | HSSFCell cell1 = row.createCell(i); |
| | | cell1.setCellValue(shiftName); |
| | | } |
| | | |
| | | for (int i = 0; i < xpShifts.size(); i++) { |
| | | String shiftName = xpShifts.get(i).getShiftName(); |
| | | long allDay = list.stream().filter(s -> s.contains(shiftName)).count(); |
| | | row.createCell(dayOfMonth + 1 + i).setCellValue(allDay + allDay); |
| | | HSSFCell cell1 = row.createCell(dayOfMonth + 1 + i); |
| | | cell1.setCellStyle(cellStyle); |
| | | cell1.setCellValue(shiftName + " " + allDay); |
| | | } |
| | | } |
| | | rowNum++; |
| | | } |
| | | |
| | | try { |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("排班计划管理.xls", "UTF-8")); |
| | | ServletOutputStream outputStream = response.getOutputStream(); |
| | | hssfWorkbook.write(outputStream); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |