|
@@ -1,16 +1,22 @@
|
|
|
package com.ims.eval.util;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.ims.eval.entity.dto.request.EmployeeDTO;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
import java.beans.BeanInfo;
|
|
|
import java.beans.IntrospectionException;
|
|
|
import java.beans.Introspector;
|
|
|
import java.beans.PropertyDescriptor;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.Method;
|
|
@@ -29,11 +35,12 @@ import java.util.Map;
|
|
|
public class ExcelUtils {
|
|
|
|
|
|
|
|
|
- * workbook
|
|
|
+ * workbook
|
|
|
+ *
|
|
|
* @param titleList
|
|
|
* @return
|
|
|
*/
|
|
|
- public static HSSFWorkbook getWorkBook(List<String> titleList){
|
|
|
+ public static HSSFWorkbook getWorkBook(List<String> titleList) {
|
|
|
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
|
@@ -53,7 +60,7 @@ public class ExcelUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static <T> HSSFWorkbook getWorkBook(List<String> titleList , List<T> dataList) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
|
|
|
+ public static <T> HSSFWorkbook getWorkBook(List<String> titleList, List<T> dataList) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
|
|
|
if (CollectionUtils.isNotEmpty(dataList)) {
|
|
|
T t1 = dataList.get(0);
|
|
|
Class<?> t1Class = t1.getClass();
|
|
@@ -63,7 +70,7 @@ public class ExcelUtils {
|
|
|
}
|
|
|
Field[] fields = t1Class.getDeclaredFields();
|
|
|
if (fields != null && fields.length > 0) {
|
|
|
- Map<String , Integer> titleMap = new HashMap<>(titleList.size());
|
|
|
+ Map<String, Integer> titleMap = new HashMap<>(titleList.size());
|
|
|
|
|
|
int fieldExcelSize = 0;
|
|
|
for (Field field : fields) {
|
|
@@ -79,7 +86,7 @@ public class ExcelUtils {
|
|
|
int index = titleList.indexOf(name.trim());
|
|
|
if (index != -1) {
|
|
|
fieldExcelSize++;
|
|
|
- titleMap.put(fieldName , index);
|
|
|
+ titleMap.put(fieldName, index);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -126,6 +133,231 @@ public class ExcelUtils {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 绩效结果考核申报生成报表
|
|
|
+ *
|
|
|
+ * @param employees 员工类
|
|
|
+ * @param departmentName 部门名称
|
|
|
+ * @param month 申报月份
|
|
|
+ * @param level 申报等级
|
|
|
+ * @param leader 部门领导签字
|
|
|
+ * @param declarationReason 申报理由
|
|
|
+ * @param outputStream 输出流
|
|
|
+ * @throws IOException 异常
|
|
|
+ */
|
|
|
+ public static void createExcel(List<EmployeeDTO> employees, String departmentName, String month, String level, String leader, String declarationReason, OutputStream outputStream) throws IOException {
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet("Sheet1");
|
|
|
+
|
|
|
+
|
|
|
+ sheet.setColumnWidth(0, 256 * 10);
|
|
|
+ sheet.setColumnWidth(1, 256 * 25);
|
|
|
+ sheet.setColumnWidth(2, 256 * 20);
|
|
|
+ sheet.setColumnWidth(3, 256 * 18);
|
|
|
+
|
|
|
+
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(3, 3, 0, 3));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(4, 4, 2, 3));
|
|
|
+
|
|
|
+
|
|
|
+ Row titleRow = sheet.createRow(0);
|
|
|
+ titleRow.setHeightInPoints(Float.parseFloat("40"));
|
|
|
+ CellStyle titleStyle = createTitleStyle(workbook);
|
|
|
+ Cell titleCell = titleRow.createCell(0);
|
|
|
+ titleCell.setCellValue("公司本部部门及员工月度绩效考核结果申报表");
|
|
|
+ titleCell.setCellStyle(titleStyle);
|
|
|
+
|
|
|
+
|
|
|
+ Row departmentRow = sheet.createRow(1);
|
|
|
+ departmentRow.setHeightInPoints(Float.parseFloat("26"));
|
|
|
+ CellStyle departmentStyle = createBasicInfoStyle(workbook);
|
|
|
+ Cell departmentCell = departmentRow.createCell(0);
|
|
|
+ departmentCell.setCellValue("部门名称");
|
|
|
+ departmentCell.setCellStyle(departmentStyle);
|
|
|
+ Cell departmentValueCell = departmentRow.createCell(1);
|
|
|
+ departmentValueCell.setCellValue(departmentName);
|
|
|
+ departmentValueCell.setCellStyle(departmentStyle);
|
|
|
+ Cell monthCell = departmentRow.createCell(2);
|
|
|
+ monthCell.setCellValue("申报月份");
|
|
|
+ monthCell.setCellStyle(departmentStyle);
|
|
|
+ Cell monthValueCell = departmentRow.createCell(3);
|
|
|
+ monthValueCell.setCellValue(month + "月");
|
|
|
+ monthValueCell.setCellStyle(departmentStyle);
|
|
|
+
|
|
|
+
|
|
|
+ Row levelRow = sheet.createRow(2);
|
|
|
+ levelRow.setHeightInPoints(Float.parseFloat("26"));
|
|
|
+ CellStyle levelStyle = createBasicInfoStyle(workbook);
|
|
|
+ Cell levelCell = levelRow.createCell(0);
|
|
|
+ levelCell.setCellValue("申报等级");
|
|
|
+ levelCell.setCellStyle(levelStyle);
|
|
|
+ Cell levelValueCell = levelRow.createCell(1);
|
|
|
+ levelValueCell.setCellValue(level);
|
|
|
+ levelValueCell.setCellStyle(levelStyle);
|
|
|
+ Cell leaderCell = levelRow.createCell(2);
|
|
|
+ leaderCell.setCellValue("部门领导签字");
|
|
|
+ leaderCell.setCellStyle(levelStyle);
|
|
|
+ Cell leaderValueCell = levelRow.createCell(3);
|
|
|
+ leaderValueCell.setCellValue(leader);
|
|
|
+ leaderValueCell.setCellStyle(levelStyle);
|
|
|
+
|
|
|
+
|
|
|
+ Row declarationReasonRow = sheet.createRow(3);
|
|
|
+ declarationReasonRow.setHeightInPoints(Float.parseFloat("80"));
|
|
|
+ CellStyle declarationReasonStyle = createDeclarationReasonStyle(workbook, sheet);
|
|
|
+ Cell declarationReasonCell = declarationReasonRow.createCell(0);
|
|
|
+ declarationReasonCell.setCellValue(declarationReason);
|
|
|
+ declarationReasonCell.setCellStyle(declarationReasonStyle);
|
|
|
+
|
|
|
+
|
|
|
+ Row headerRow = sheet.createRow(4);
|
|
|
+ headerRow.setHeightInPoints(Float.parseFloat("30"));
|
|
|
+ CellStyle headerStyle = createHeaderStyle(workbook, sheet);
|
|
|
+ Cell indexHeader = headerRow.createCell(0);
|
|
|
+ indexHeader.setCellValue("序号");
|
|
|
+ indexHeader.setCellStyle(headerStyle);
|
|
|
+ Cell nameHeader = headerRow.createCell(1);
|
|
|
+ nameHeader.setCellValue("部门员工姓名");
|
|
|
+ nameHeader.setCellStyle(headerStyle);
|
|
|
+ Cell coefficientHeader = headerRow.createCell(2);
|
|
|
+ coefficientHeader.setCellValue("月度考核系数建议值");
|
|
|
+ coefficientHeader.setCellStyle(headerStyle);
|
|
|
+
|
|
|
+
|
|
|
+ int rowIndex = 5;
|
|
|
+ for (int i = 0; i < employees.size(); i++) {
|
|
|
+ Row row = sheet.createRow(rowIndex);
|
|
|
+ row.setHeightInPoints(Float.parseFloat("30"));
|
|
|
+ CellStyle cellStyle = createContentStyle(workbook, sheet, rowIndex);
|
|
|
+ Cell indexCell = row.createCell(0);
|
|
|
+ indexCell.setCellValue(i + 1);
|
|
|
+ indexCell.setCellStyle(cellStyle);
|
|
|
+ Cell nameCell = row.createCell(1);
|
|
|
+ nameCell.setCellValue(employees.get(i).getName());
|
|
|
+ nameCell.setCellStyle(cellStyle);
|
|
|
+ Cell coefficientCell = row.createCell(2);
|
|
|
+ coefficientCell.setCellValue(employees.get(i).getCoefficient());
|
|
|
+ coefficientCell.setCellStyle(cellStyle);
|
|
|
+ rowIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ workbook.write(outputStream);
|
|
|
+ workbook.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CellStyle createTitleStyle(Workbook workbook) {
|
|
|
+ CellStyle style = workbook.createCellStyle();
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 16);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setFont(font);
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CellStyle createBasicInfoStyle(Workbook workbook) {
|
|
|
+ CellStyle style = workbook.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 font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setFont(font);
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CellStyle createDeclarationReasonStyle(Workbook workbook, Sheet sheet) {
|
|
|
+ CellStyle style = workbook.createCellStyle();
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.TOP);
|
|
|
+ style.setAlignment(HorizontalAlignment.LEFT);
|
|
|
+ style.setWrapText(true);
|
|
|
+ style.setBorderTop(BorderStyle.THIN);
|
|
|
+ style.setBorderBottom(BorderStyle.THIN);
|
|
|
+ style.setBorderLeft(BorderStyle.THIN);
|
|
|
+ style.setBorderRight(BorderStyle.THIN);
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setFont(font);
|
|
|
+ for (int i = 3; i <= 3; i++) {
|
|
|
+ for (int j = 0; j <= 3; j++) {
|
|
|
+ Row mergedRow = sheet.getRow(i);
|
|
|
+ if (mergedRow == null) {
|
|
|
+ mergedRow = sheet.createRow(i);
|
|
|
+ }
|
|
|
+ Cell mergedCell = mergedRow.getCell(j);
|
|
|
+ if (mergedCell == null) {
|
|
|
+ mergedCell = mergedRow.createCell(j);
|
|
|
+ }
|
|
|
+ mergedCell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CellStyle createHeaderStyle(Workbook workbook, Sheet sheet) {
|
|
|
+ CellStyle style = workbook.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 font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setFont(font);
|
|
|
+ for (int i = 4; i <= 4; i++) {
|
|
|
+ for (int j = 2; j <= 3; j++) {
|
|
|
+ Row mergedRow = sheet.getRow(i);
|
|
|
+ if (mergedRow == null) {
|
|
|
+ mergedRow = sheet.createRow(i);
|
|
|
+ }
|
|
|
+ Cell mergedCell = mergedRow.getCell(j);
|
|
|
+ if (mergedCell == null) {
|
|
|
+ mergedCell = mergedRow.createCell(j);
|
|
|
+ }
|
|
|
+ mergedCell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CellStyle createContentStyle(Workbook workbook, Sheet sheet, int rowIndex) {
|
|
|
+ CellStyle style = workbook.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 font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ style.setFont(font);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 2, 3));
|
|
|
+ for (int i = rowIndex; i <= rowIndex; i++) {
|
|
|
+ for (int j = 2; j <= 3; j++) {
|
|
|
+ Row mergedRow = sheet.getRow(i);
|
|
|
+ if (mergedRow == null) {
|
|
|
+ mergedRow = sheet.createRow(i);
|
|
|
+ }
|
|
|
+ Cell mergedCell = mergedRow.getCell(j);
|
|
|
+ if (mergedCell == null) {
|
|
|
+ mergedCell = mergedRow.createCell(j);
|
|
|
+ }
|
|
|
+ mergedCell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return style;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|