|
|
@@ -994,6 +994,9 @@ public class ExcelUtil<T>
|
|
|
return cell;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 设置单元格信息
|
|
|
*
|
|
|
@@ -1840,15 +1843,22 @@ public class ExcelUtil<T>
|
|
|
public void exportProjectMonthClockExcel(HttpServletResponse response,List<Map<String, Object>> listData, String projectName, String departmentName, String companyName,
|
|
|
Integer year,Integer month) {
|
|
|
title=StringUtils.format("{}年{}月工时记录表",year,month);
|
|
|
- sheetName="导出表格";
|
|
|
+ sheetName="tab1";
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
response.setCharacterEncoding("utf-8");
|
|
|
this.wb = new SXSSFWorkbook(500);
|
|
|
this.sheet = wb.createSheet();
|
|
|
wb.setSheetName(0, sheetName);
|
|
|
+ this.styles = createProjectStyles(wb);
|
|
|
+ sheet.setColumnWidth(0, 16*256);
|
|
|
+ Map<String, Object> stringObjectMap = listData.get(0);
|
|
|
+ List<Map<String, Object>> map = (List<Map<String, Object>>) stringObjectMap.get("data");
|
|
|
try
|
|
|
{
|
|
|
-// writeSheet();
|
|
|
+ addTitle(map.size());
|
|
|
+ addSubHead(map.size(),projectName,departmentName,companyName);
|
|
|
+ addTable(map);
|
|
|
+ addTableDuration(listData);
|
|
|
wb.write(response.getOutputStream());
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
@@ -1861,4 +1871,196 @@ public class ExcelUtil<T>
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private void addTableDuration(List<Map<String, Object>> map) {
|
|
|
+ int index=0;
|
|
|
+ for (Map<String, Object> stringObjectMap : map) {
|
|
|
+ int start=rownum;
|
|
|
+ Row row = sheet.createRow(rownum++);
|
|
|
+ Cell nameCell = row.createCell(index++);
|
|
|
+ nameCell.setCellStyle(styles.get("data"));
|
|
|
+ nameCell.setCellValue(stringObjectMap.get("name").toString());
|
|
|
+ Cell typeCell = row.createCell(index++);
|
|
|
+ typeCell.setCellStyle(styles.get("data"));
|
|
|
+ typeCell.setCellValue("研发工时");
|
|
|
+ List<Map<String, Object>> map2 = (List<Map<String, Object>>) stringObjectMap.get("data");
|
|
|
+ for (Map<String, Object> objectMap : map2) {
|
|
|
+ Cell cell = row.createCell(index++);
|
|
|
+ if (objectMap.get("projectDuration")!=null){
|
|
|
+ BigDecimal projectDuration = (BigDecimal) objectMap.get("projectDuration");
|
|
|
+ cell.setCellValue(projectDuration.stripTrailingZeros().toPlainString());
|
|
|
+ cell.setCellStyle(styles.get("data"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Cell projectDuration = row.createCell(index++);
|
|
|
+ BigDecimal projectDuration1 = (BigDecimal) stringObjectMap.get("projectDuration");
|
|
|
+ projectDuration.setCellValue(projectDuration1.stripTrailingZeros().toPlainString());
|
|
|
+ projectDuration.setCellStyle(styles.get("data"));
|
|
|
+ Cell projectProportion = row.createCell(index);
|
|
|
+ BigDecimal proportion = (BigDecimal) stringObjectMap.get("projectProportion");
|
|
|
+ proportion = proportion.multiply(new BigDecimal(100));
|
|
|
+ projectProportion.setCellValue(proportion.stripTrailingZeros().toPlainString()+"%");
|
|
|
+ projectProportion.setCellStyle(styles.get("data"));
|
|
|
+ Row row2 = sheet.createRow(rownum++);
|
|
|
+ index=0;
|
|
|
+ Cell typeCell1 = row2.createCell(index++);
|
|
|
+ typeCell1.setCellStyle(styles.get("data"));
|
|
|
+ Cell typeCell2 = row2.createCell(index++);
|
|
|
+ typeCell2.setCellStyle(styles.get("data"));
|
|
|
+ typeCell2.setCellValue("非研发工时");
|
|
|
+ for (Map<String, Object> objectMap : map2) {
|
|
|
+ Cell Cell = row2.createCell(index++);
|
|
|
+ if (objectMap.get("notDuration")!=null){
|
|
|
+ BigDecimal notDuration = (BigDecimal) objectMap.get("notDuration");
|
|
|
+ Cell.setCellValue(notDuration.stripTrailingZeros().toPlainString());
|
|
|
+ Cell.setCellStyle(styles.get("data"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Cell notDuration = row2.createCell(index++);
|
|
|
+ BigDecimal notDuration1 = (BigDecimal) stringObjectMap.get("notDuration");
|
|
|
+ notDuration.setCellValue(notDuration1.stripTrailingZeros().toPlainString());
|
|
|
+ notDuration.setCellStyle(styles.get("data"));
|
|
|
+ Cell notProportion = row2.createCell(index);
|
|
|
+ BigDecimal notP = (BigDecimal) stringObjectMap.get("notProportion");
|
|
|
+ notP = notP.multiply(new BigDecimal(100));
|
|
|
+ notProportion.setCellValue(notP.stripTrailingZeros().toPlainString()+"%");
|
|
|
+ notProportion.setCellStyle(styles.get("data"));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(start, start+1, 0, 0));
|
|
|
+ index=0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addTable(List<Map<String, Object>> map) {
|
|
|
+ List<String> row1= new ArrayList<>();
|
|
|
+ List<String> row2= new ArrayList<>();
|
|
|
+
|
|
|
+ row1.add("姓名");
|
|
|
+ row1.add("星期");
|
|
|
+ row2.add("姓名");
|
|
|
+ row2.add("日期");
|
|
|
+ for (Map<String, Object> objectMap : map) {
|
|
|
+ row1.add(objectMap.get("week").toString());
|
|
|
+ row2.add(objectMap.get("date").toString());
|
|
|
+ }
|
|
|
+ row1.add("正常出勤");
|
|
|
+ row1.add("分摊率");
|
|
|
+ row2.add("工时");
|
|
|
+ row2.add("分摊率");
|
|
|
+ addRowTable(row1);
|
|
|
+ addRowTable(row2);
|
|
|
+ sheet.setColumnWidth(row1.size()-2, 14*256);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(2, 3, row1.size()-1, row1.size()-1));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addSubHead(int size, String projectName, String departmentName, String companyName) {
|
|
|
+ Row titleRow = sheet.createRow(rownum++);
|
|
|
+ titleRow.setHeightInPoints(20);
|
|
|
+ int titleLastCol=3+size;
|
|
|
+ for (int i = 0; i <=titleLastCol; i++){
|
|
|
+ Cell titleCell = titleRow.createCell(i);
|
|
|
+ CellStyle title1 = styles.get("subHead");
|
|
|
+ if (i==0){
|
|
|
+ String str= StringUtils.format("单位: {} " +
|
|
|
+ "所属部门: {} " +
|
|
|
+ "课题名称: {}",companyName,departmentName,projectName);
|
|
|
+ titleCell.setCellValue(str);
|
|
|
+ }
|
|
|
+ titleCell.setCellStyle(title1);
|
|
|
+ }
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), 0, titleLastCol));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void addTitle(Integer size) {
|
|
|
+ Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
|
|
|
+ titleRow.setHeightInPoints(30);
|
|
|
+ int titleLastCol=3+size;
|
|
|
+ for (int i = 0; i <=titleLastCol; i++){
|
|
|
+ Cell titleCell = titleRow.createCell(i);
|
|
|
+ if (i==0){
|
|
|
+ titleCell.setCellValue(title);
|
|
|
+ }
|
|
|
+ titleCell.setCellStyle(styles.get("title"));
|
|
|
+ }
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), 0, titleLastCol));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addRowTable(List<String> row) {
|
|
|
+ Row RowTable = sheet.createRow( rownum++ );
|
|
|
+ RowTable.setHeightInPoints(20);
|
|
|
+ int index = 0;
|
|
|
+ for (String s : row) {
|
|
|
+ Cell Cell = RowTable.createCell(index);
|
|
|
+ CellStyle title1 = styles.get("subHead");
|
|
|
+ Font titleFont = wb.createFont();
|
|
|
+ titleFont.setFontHeightInPoints((short) 12);
|
|
|
+ title1.setFont(titleFont);
|
|
|
+ Cell.setCellStyle(title1);
|
|
|
+ Cell.setCellValue(s);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, CellStyle> createProjectStyles(Workbook wb) {
|
|
|
+ // 写入各条记录,每条记录对应excel表中的一行
|
|
|
+ Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
|
|
|
+ CellStyle style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ Font titleFont = wb.createFont();
|
|
|
+ titleFont.setFontName("Arial");
|
|
|
+ titleFont.setFontHeightInPoints((short) 16);
|
|
|
+ titleFont.setBold(true);
|
|
|
+ style.setFont(titleFont);
|
|
|
+ styles.put("title", style);
|
|
|
+
|
|
|
+ style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ Font subHeadFont = wb.createFont();
|
|
|
+ subHeadFont.setFontName("Arial");
|
|
|
+ subHeadFont.setFontHeightInPoints((short) 14);
|
|
|
+ subHeadFont.setBold(true);
|
|
|
+ style.setFont(titleFont);
|
|
|
+ styles.put("subHead", style);
|
|
|
+
|
|
|
+ style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
|
|
|
+ Font dataFont = wb.createFont();
|
|
|
+ dataFont.setFontName("Arial");
|
|
|
+ dataFont.setFontHeightInPoints((short) 10);
|
|
|
+ style.setFont(dataFont);
|
|
|
+ styles.put("data", style);
|
|
|
+
|
|
|
+ style = wb.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ Font totalFont = wb.createFont();
|
|
|
+ totalFont.setFontName("Arial");
|
|
|
+ totalFont.setFontHeightInPoints((short) 10);
|
|
|
+ style.setFont(totalFont);
|
|
|
+ styles.put("total", style);
|
|
|
+ return styles;
|
|
|
+ }
|
|
|
}
|