|
@@ -0,0 +1,419 @@
|
|
|
+package restcontroller.webmanage.sale.salestarget;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.YosException;
|
|
|
+import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
+
|
|
|
+public class enterpriseexcel {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2022-07-14 17:41:39
|
|
|
+ * 设置表格宽度(导入模板)
|
|
|
+ **/
|
|
|
+ public static void setBatchDetailSheetColumn1(XSSFSheet sheet) {
|
|
|
+ sheet.setDefaultRowHeight((short) 600);
|
|
|
+ short width = 3500;
|
|
|
+ sheet.setColumnWidth((short) 0, 4000);
|
|
|
+ sheet.setColumnWidth((short) 1, 4000);
|
|
|
+ for (int i = 1; i < 20; i++) {
|
|
|
+ sheet.setColumnWidth((short) i, width);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2022-07-14 17:41:39
|
|
|
+ * 设置表格宽度(返回错误Excel的样式)
|
|
|
+ **/
|
|
|
+ public static void setBatchDetailSheetColumn2(XSSFSheet sheet) {
|
|
|
+ sheet.setDefaultRowHeight((short) 600);
|
|
|
+ short width = 3000;
|
|
|
+ sheet.setColumnWidth((short) 0, 4000);
|
|
|
+ sheet.setColumnWidth((short) 1, 4000);
|
|
|
+ for (int i = 1; i < 18; i++) {
|
|
|
+ sheet.setColumnWidth((short) i, width);
|
|
|
+ }
|
|
|
+ sheet.setColumnWidth((short) 20, width * 2);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2022-07-14 17:42:03
|
|
|
+ * 设置表头
|
|
|
+ * cellStyle1 中文提示信息样式
|
|
|
+ * cellStyle2 标题提示信息样式
|
|
|
+ * cellStyle3 正文提示信息样式
|
|
|
+ **/
|
|
|
+ public static void batchDetail(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFCellStyle cellStyle3, XSSFWorkbook workbook) {
|
|
|
+// HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
|
|
|
+// bcs.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
+// bcs.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
+// bcs.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
+// bcs.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
+// bcs.setWrapText(true);
|
|
|
+
|
|
|
+
|
|
|
+ XSSFRow row = null;
|
|
|
+ XSSFCell cell = null;
|
|
|
+
|
|
|
+ cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
+ cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
+ cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
+ cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
+ cellStyle1.setWrapText(true);
|
|
|
+
|
|
|
+ cellStyle2.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
+ cellStyle2.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
+ cellStyle2.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
+ cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
+ cellStyle2.setWrapText(true);
|
|
|
+ /*第一行*/
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 17));//2.申请年度单位
|
|
|
+
|
|
|
+ /*第一行塞值*/
|
|
|
+ row = sheet.createRow(0);
|
|
|
+ cell = row.createCell(0);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
|
|
|
+
|
|
|
+ /*第二行塞值*/
|
|
|
+ row = sheet.createRow(1);
|
|
|
+
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("经销商编码");
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("年度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("1季度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("2季度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("3季度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("4季度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 1; i < 13; i++) {
|
|
|
+ cell = row.createCell(i + 5);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue(i + "月(基本)");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /*第三行塞值*/
|
|
|
+ row = sheet.createRow(2);
|
|
|
+
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue("名称");
|
|
|
+
|
|
|
+ for (int i = 1; i < 18; i++) {
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue("0");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2022-07-14 17:42:03
|
|
|
+ * 设置表头
|
|
|
+ **/
|
|
|
+ public static void batchDetailErr(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFWorkbook workbook) {
|
|
|
+// HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
|
|
|
+// bcs.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
+// bcs.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
+// bcs.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
+// bcs.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
+// bcs.setWrapText(true);
|
|
|
+
|
|
|
+
|
|
|
+ XSSFRow row = null;
|
|
|
+ XSSFCell cell = null;
|
|
|
+
|
|
|
+ cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
+ cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
+ cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
+ cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
+ cellStyle1.setWrapText(true);
|
|
|
+
|
|
|
+ /*第一行*/
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 18));//2.提示信息
|
|
|
+
|
|
|
+ /*第一行塞值*/
|
|
|
+ row = sheet.createRow(0);
|
|
|
+ cell = row.createCell(0);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
|
|
|
+
|
|
|
+
|
|
|
+ /*第二行塞值*/
|
|
|
+ row = sheet.createRow(1);
|
|
|
+
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("经销商编码(必填)");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("年度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("1季度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("2季度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("3季度(基本)");
|
|
|
+
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("4季度(基本)");
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 1; i < 13; i++) {
|
|
|
+ cell = row.createCell( i + 5);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue(i + "月(基本)");
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = row.createCell(18);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("错误信息");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setBatchDetailSheetColumn3(XSSFSheet sheet) {
|
|
|
+ sheet.setDefaultRowHeight((short) 700);
|
|
|
+ short width = 3500;
|
|
|
+ sheet.setColumnWidth((short) 0, 4000);
|
|
|
+ sheet.setColumnWidth((short) 1, 4000);
|
|
|
+ for (int i = 1; i < 19; i++) {
|
|
|
+ sheet.setColumnWidth((short) i, width);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void batchDetailExport(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFCellStyle cellStyle3, XSSFWorkbook workbook, JSONArray dataArrays) throws YosException {
|
|
|
+
|
|
|
+ XSSFRow row = null;
|
|
|
+ XSSFCell cell = null;
|
|
|
+
|
|
|
+ cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
|
|
|
+ cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
|
|
|
+ cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
|
|
|
+ cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
|
|
|
+ cellStyle1.setWrapText(true);
|
|
|
+ //下边框
|
|
|
+ cellStyle2.setBorderBottom(BorderStyle.THIN);
|
|
|
+ //左边框
|
|
|
+ cellStyle2.setBorderLeft(BorderStyle.THIN);
|
|
|
+ //上边框
|
|
|
+ cellStyle2.setBorderTop(BorderStyle.THIN);
|
|
|
+ //右边框
|
|
|
+ cellStyle2.setBorderRight(BorderStyle.THIN);
|
|
|
+ cellStyle2.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle2.setWrapText(true);
|
|
|
+
|
|
|
+ cellStyle3.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ cellStyle3.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle3.setWrapText(true);
|
|
|
+
|
|
|
+ XSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ // 创建一个字体
|
|
|
+ XSSFFont fontRed = workbook.createFont();
|
|
|
+ fontRed.setColor((short) 0xa); // 字体颜色
|
|
|
+ XSSFFont fontGreen = workbook.createFont();
|
|
|
+ fontGreen.setColor((short) 0xb); // 字体颜色
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setWrapText(true);
|
|
|
+
|
|
|
+
|
|
|
+ //第一行
|
|
|
+ row = sheet.createRow(0);
|
|
|
+ String[] title = {"部门", "人员", "职位", "目标/实际"};
|
|
|
+ for (int i = 0; i < title.length; i++) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, i, i));
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue(title[i]);
|
|
|
+ }
|
|
|
+ String[] title2 =
|
|
|
+ {
|
|
|
+ "年度(万元)",
|
|
|
+ "第一季度(万元)", "一月(万元)", "二月(万元)", "三月(万元)",
|
|
|
+ "第二季度(万元)", "四月(万元)", "五月(万元)", "六月(万元)",
|
|
|
+ "第三季度(万元)", "七月(万元)", "八月(万元)", "九月(万元)",
|
|
|
+ "第四季度(万元)", "十月(万元)", "十一月(万元)", "十二月(万元)"
|
|
|
+ };
|
|
|
+ for (int i = 0; i < title2.length; i++) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 2 * i + 4, 2 * i + 5));
|
|
|
+ cell = row.createCell(2 * i + 4);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue(title2[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //第二行
|
|
|
+ row = sheet.createRow(1);
|
|
|
+ for (int i = 0; i < 38; i++) {
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ if (i >= 4) {
|
|
|
+ cell.setCellValue("基本");
|
|
|
+ if (i % 2 == 1) {
|
|
|
+ cell.setCellValue("挑战");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int rownum = 2;
|
|
|
+ for (Object data : dataArrays) {
|
|
|
+ JSONObject dataRow = (JSONObject) data;
|
|
|
+ //目标
|
|
|
+ row = sheet.createRow(rownum);
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rownum, rownum + 1, 0, 0));
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue(dataRow.getString("depfullname"));
|
|
|
+
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rownum, rownum + 1, 1, 1));
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue(dataRow.containsKey("name") ? dataRow.getString("name") : "");
|
|
|
+
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rownum, rownum + 1, 2, 2));
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue(dataRow.containsKey("position") ? dataRow.getString("position") : "");
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue("目标");
|
|
|
+
|
|
|
+ String[] keys =
|
|
|
+ {
|
|
|
+ "y1l", "y1h",
|
|
|
+ "s1l", "s1h",
|
|
|
+ "m1l", "m1h", "m2l", "m2h", "m3l", "m3h",
|
|
|
+ "s2l", "s2h",
|
|
|
+ "m4l", "m4h", "m5l", "m5h", "m6l", "m6h",
|
|
|
+ "s3l", "s3h",
|
|
|
+ "m7l", "m7h", "m8l", "m8h", "m9l", "m9h",
|
|
|
+ "s4l", "s4h",
|
|
|
+ "m10l", "m10h", "m11l", "m11h", "m12l", "m12h",
|
|
|
+ };
|
|
|
+
|
|
|
+ for (int i = 4; i < 38; i++) {
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue(dataRow.getString(keys[i - 4]));
|
|
|
+
|
|
|
+ }
|
|
|
+ /*第三行塞值*/
|
|
|
+ row = sheet.createRow(rownum + 1);
|
|
|
+
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellStyle(cellStyle3);
|
|
|
+ cell.setCellValue("实际");
|
|
|
+
|
|
|
+ String[] keys2 =
|
|
|
+ {
|
|
|
+ "y1a", "y1a",
|
|
|
+ "s1a", "s1a",
|
|
|
+ "m1a", "m1a", "m2a", "m2a", "m3a", "m3a",
|
|
|
+ "s2a", "s2a",
|
|
|
+ "m4a", "m4a", "m5a", "m5a", "m6a", "m6a",
|
|
|
+ "s3a", "s3a",
|
|
|
+ "m7a", "m7a", "m8a", "m8a", "m9a", "m9a",
|
|
|
+ "s4a", "s4a",
|
|
|
+ "m10a", "m10a", "m11a", "m11a", "m12a", "m12a",
|
|
|
+ };
|
|
|
+ String[] keys3 =
|
|
|
+ {
|
|
|
+ "y1pl", "y1ph",
|
|
|
+ "s1pl", "s1ph",
|
|
|
+ "m1pl", "m1ph", "m2pl", "m2ph", "m3pl", "m3ph",
|
|
|
+ "s2pl", "s2ph",
|
|
|
+ "m4pl", "m4ph", "m5pl", "m5ph", "m6pl", "m6ph",
|
|
|
+ "s3pl", "s3ph",
|
|
|
+ "m7pl", "m7ph", "m8pl", "m8ph", "m9pl", "m9ph",
|
|
|
+ "s4pl", "s4ph",
|
|
|
+ "m10pl", "m10ph", "m11pl", "m11ph", "m12pl", "m12ph",
|
|
|
+ };
|
|
|
+
|
|
|
+ for (int i = 4; i < 38; i++) {
|
|
|
+ cell = row.createCell(i);
|
|
|
+ String text1 = dataRow.getString(keys2[i - 4]);
|
|
|
+ String text2 = dataRow.getString(keys3[i - 4]);
|
|
|
+ String text = text1 + "\r\n" + "(" + text2 + "%)";
|
|
|
+ XSSFRichTextString hrt = workbook.getCreationHelper().createRichTextString(text);
|
|
|
+ if (text2.contains("-")) {
|
|
|
+ hrt.applyFont(text1.length() + 2, text.length(), fontGreen);
|
|
|
+ } else if (text2.equals("0")) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ hrt.applyFont(text1.length() + 2, text.length(), fontRed);
|
|
|
+ }
|
|
|
+
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ cell.setCellValue(hrt);
|
|
|
+
|
|
|
+ }
|
|
|
+ rownum = rownum + 2;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|