|
|
@@ -0,0 +1,663 @@
|
|
|
+package restcontroller.webmanage.sale.salestarget_cucu;
|
|
|
+
|
|
|
+
|
|
|
+import common.data.Rows;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.usermodel.Font;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
+
|
|
|
+import java.awt.*;
|
|
|
+import java.awt.Color;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+public class ExportExcel {
|
|
|
+ /**
|
|
|
+ * 设置标题单元样式
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static XSSFCellStyle createTitleCellStyle1(XSSFWorkbook workbook) {
|
|
|
+ XSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ XSSFFont font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ font.setFontName("微软雅黑");// 设置标题字体
|
|
|
+ cellStyle.setFont(font);
|
|
|
+ cellStyle.setWrapText(true); //自动换行
|
|
|
+ cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font);// 设置列标题样式
|
|
|
+ XSSFColor colorBlue = new XSSFColor(new Color(255, 255, 255));
|
|
|
+ cellStyle.setFillForegroundColor(colorBlue);
|
|
|
+ cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
|
|
|
+ return cellStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置中文提示信息样式
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static XSSFCellStyle createTitleCellStyle2(XSSFWorkbook workbook) {
|
|
|
+ XSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ XSSFFont font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ font.setFontName("微软雅黑");// 设置标题字体
|
|
|
+ cellStyle.setFont(font);
|
|
|
+ cellStyle.setWrapText(true); //自动换行
|
|
|
+ cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font);// 设置列标题样式
|
|
|
+ XSSFColor colorGrey = new XSSFColor(new Color(255, 255, 255));
|
|
|
+ cellStyle.setFillForegroundColor(colorGrey);
|
|
|
+ cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.LEFT); // 居左
|
|
|
+ return cellStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置正文单元样式
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static XSSFCellStyle createBodyCellStyle4(XSSFWorkbook workbook) {
|
|
|
+ XSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ XSSFFont font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setFontName("微软雅黑");// 设置标题字体
|
|
|
+ // font.setFontName(HSSFFont.FONT_ARIAL);// 设置标题字体
|
|
|
+ cellStyle.setFont(font);
|
|
|
+ cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ return cellStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static XSSFCellStyle createTitleCellStyle3(XSSFWorkbook workbook) {
|
|
|
+ XSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ XSSFFont font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.WHITE.getIndex());
|
|
|
+ font.setFontName("微软雅黑");// 设置标题字体
|
|
|
+ cellStyle.setFont(font);
|
|
|
+ cellStyle.setWrapText(true); //自动换行
|
|
|
+ cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font);// 设置列标题样式
|
|
|
+ XSSFColor colorBlue =new XSSFColor(new Color(255, 255, 255));
|
|
|
+ cellStyle.setFillForegroundColor(colorBlue);
|
|
|
+ cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
|
|
|
+ return cellStyle;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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,XSSFCellStyle cellStyle4, XSSFWorkbook workbook, Rows rows,long year,long month) {
|
|
|
+// 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);
|
|
|
+
|
|
|
+ cellStyle1.setDataFormat(workbook.createDataFormat().getFormat("TEXT"));
|
|
|
+ cellStyle2.setDataFormat(workbook.createDataFormat().getFormat("TEXT"));
|
|
|
+ cellStyle3.setDataFormat(workbook.createDataFormat().getFormat("TEXT"));
|
|
|
+ /*第一行*/
|
|
|
+ //sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 23));
|
|
|
+
|
|
|
+ /*第一行塞值*/
|
|
|
+ row = sheet.createRow(0);
|
|
|
+ cell = row.createCell(0);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("区域");
|
|
|
+
|
|
|
+ cell = row.createCell(1);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(2);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(3);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(4);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(5);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(6);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(7);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(8);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(9);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(10);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("月份 ("+year+"-"+month+")");
|
|
|
+
|
|
|
+ cell = row.createCell(11);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("季度(当前月所在季度)");
|
|
|
+
|
|
|
+ cell = row.createCell(12);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("季度(当前月所在季度)");
|
|
|
+
|
|
|
+ cell = row.createCell(13);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("季度(当前月所在季度)");
|
|
|
+
|
|
|
+ cell = row.createCell(14);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("季度(当前月所在季度)");
|
|
|
+
|
|
|
+ cell = row.createCell(15);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("季度(当前月所在季度)");
|
|
|
+
|
|
|
+ cell = row.createCell(16);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("季度(当前月所在季度)");
|
|
|
+
|
|
|
+ cell = row.createCell(17);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("季度(当前月所在季度)");
|
|
|
+
|
|
|
+ cell = row.createCell(18);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("总指标");
|
|
|
+
|
|
|
+ cell = row.createCell(19);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("总指标");
|
|
|
+
|
|
|
+ cell = row.createCell(20);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("总指标");
|
|
|
+
|
|
|
+ cell = row.createCell(21);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("总指标");
|
|
|
+
|
|
|
+ cell = row.createCell(22);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("总指标");
|
|
|
+
|
|
|
+ cell = row.createCell(23);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("总指标");
|
|
|
+
|
|
|
+ cell = row.createCell(24);// ID
|
|
|
+ cell.setCellStyle(cellStyle1);
|
|
|
+ cell.setCellValue("总指标");
|
|
|
+
|
|
|
+ /*第二行塞值*/
|
|
|
+ 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("回款完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("上月完成额超出部分");
|
|
|
+
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("GC工程完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("GC工程超出部分");
|
|
|
+
|
|
|
+ cell = row.createCell(6);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("整装工程完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(7);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("整装工程超出部分");
|
|
|
+
|
|
|
+ cell = row.createCell(8);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("完成额超出100%部分");
|
|
|
+
|
|
|
+ cell = row.createCell(9);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("实际完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(10);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("实际完成百分比");
|
|
|
+
|
|
|
+ cell = row.createCell(11);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("季度任务(万)");
|
|
|
+
|
|
|
+ cell = row.createCell(12);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("回款完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(13);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("上季完成额超出部分");
|
|
|
+
|
|
|
+ cell = row.createCell(14);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("GC工程完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(15);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("整装工程完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(16);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("季度完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(17);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("季度百分比");
|
|
|
+
|
|
|
+ cell = row.createCell(18);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("总任务(万)");
|
|
|
+
|
|
|
+ cell = row.createCell(19);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("回款完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(20);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("GC工程完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(21);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("整装工程完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(22);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("总完成额");
|
|
|
+
|
|
|
+ cell = row.createCell(23);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("百分比");
|
|
|
+
|
|
|
+ cell = row.createCell(24);
|
|
|
+ cell.setCellStyle(cellStyle2);
|
|
|
+ cell.setCellValue("距70%差额");
|
|
|
+ int a=2;
|
|
|
+ for(common.data.Row areaRow : rows){
|
|
|
+
|
|
|
+ /*第三行塞值*/
|
|
|
+ row = sheet.createRow(a);
|
|
|
+
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("areaname"));
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("rw_month"));
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("completedamount"));
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("previousexceed"));
|
|
|
+
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("gccompletedamount"));
|
|
|
+
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("gccompletedamountexceed"));
|
|
|
+
|
|
|
+ cell = row.createCell(6);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("zzcompletedamount"));
|
|
|
+
|
|
|
+ cell = row.createCell(7);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("zzcompletedamountexceed"));
|
|
|
+
|
|
|
+ cell = row.createCell(8);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("completedamountexceed100"));
|
|
|
+
|
|
|
+ cell = row.createCell(9);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("actualcompletedamount"));
|
|
|
+
|
|
|
+ cell = row.createCell(10);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("actualcompletedpercentage"));
|
|
|
+
|
|
|
+ cell = row.createCell(11);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("rw_quarter"));
|
|
|
+
|
|
|
+ cell = row.createCell(12);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("completedamount_quarter"));
|
|
|
+
|
|
|
+ cell = row.createCell(13);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("previousexceed_quarter"));
|
|
|
+
|
|
|
+ cell = row.createCell(14);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("gccompletedamount_quarter"));
|
|
|
+
|
|
|
+ cell = row.createCell(15);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("zzcompletedamount_quarter"));
|
|
|
+
|
|
|
+ cell = row.createCell(16);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("actualcompletedamount_quarter"));
|
|
|
+
|
|
|
+ cell = row.createCell(17);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("actualcompletedpercentage_quarter"));
|
|
|
+
|
|
|
+ cell = row.createCell(18);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("rw_total"));
|
|
|
+
|
|
|
+ cell = row.createCell(19);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("completedamount_total"));
|
|
|
+
|
|
|
+ cell = row.createCell(20);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("gccompletedamount_total"));
|
|
|
+
|
|
|
+ cell = row.createCell(21);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("zzcompletedamount_total"));
|
|
|
+
|
|
|
+ cell = row.createCell(22);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("actualcompletedamount_total"));
|
|
|
+
|
|
|
+ cell = row.createCell(23);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("actualcompletedpercentage_total"));
|
|
|
+
|
|
|
+ cell = row.createCell(24);
|
|
|
+ cell.setCellStyle(cellStyle4);
|
|
|
+ cell.setCellValue(areaRow.getString("differenceamount_total"));
|
|
|
+ a++;
|
|
|
+ }
|
|
|
+ //按范围合并单元格
|
|
|
+ for(int i = 0; i < 1; i++){
|
|
|
+ mergeSameCellContentColumn(sheet, 1, i);
|
|
|
+ }
|
|
|
+
|
|
|
+ mergeAndCenterRow(workbook, 0, 0);
|
|
|
+
|
|
|
+// for (int i = 1; i < 18; i++) {
|
|
|
+// cell = row.createCell(i);
|
|
|
+// cell.setCellStyle(cellStyle3);
|
|
|
+// cell.setCellValue("0");
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 < 20; i++) {
|
|
|
+ sheet.setColumnWidth((short) i, width);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 合并指定行中连续相同内容的单元格并居中
|
|
|
+ * @param workbook 工作簿
|
|
|
+ * @param sheetIndex 工作表索引
|
|
|
+ * @param rowIndex 要处理的行索引(0-based)
|
|
|
+ */
|
|
|
+ public static void mergeAndCenterRow(Workbook workbook, int sheetIndex, int rowIndex) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(sheetIndex);
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+
|
|
|
+ if (row == null) {
|
|
|
+ System.out.println("指定行不存在: " + rowIndex);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int lastCellNum = row.getLastCellNum();
|
|
|
+ if (lastCellNum < 1) return;
|
|
|
+
|
|
|
+ int startCol = 0;
|
|
|
+ int endCol = 0;
|
|
|
+ String prevValue = getCellValue(row, 0);
|
|
|
+
|
|
|
+ for (int i = 1; i < lastCellNum; i++) {
|
|
|
+ String currentValue = getCellValue(row, i);
|
|
|
+
|
|
|
+ if (currentValue != null && currentValue.equals(prevValue)) {
|
|
|
+ endCol = i;
|
|
|
+ } else {
|
|
|
+ if (endCol > startCol) {
|
|
|
+ // 合并水平方向(同一行,不同列)
|
|
|
+ mergeAndStyleHorizontal(workbook,sheet, rowIndex, startCol, endCol, prevValue);
|
|
|
+ }
|
|
|
+ startCol = i;
|
|
|
+ endCol = i;
|
|
|
+ prevValue = currentValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理最后一个区域
|
|
|
+ if (endCol > startCol) {
|
|
|
+ mergeAndStyleHorizontal(workbook,sheet, rowIndex, startCol, endCol, prevValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 水平合并单元格并设置居中样式
|
|
|
+ */
|
|
|
+ private static void mergeAndStyleHorizontal(Workbook workbook,Sheet sheet, int rowIndex,
|
|
|
+ int startCol, int endCol, String cellValue) {
|
|
|
+ // 创建水平合并区域
|
|
|
+ CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex, startCol, endCol);
|
|
|
+ sheet.addMergedRegion(region);
|
|
|
+
|
|
|
+ // 获取第一个单元格
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ Cell firstCell = row.getCell(startCol);
|
|
|
+
|
|
|
+ // 设置单元格值
|
|
|
+ if (firstCell == null) {
|
|
|
+ firstCell = row.createCell(startCol);
|
|
|
+ }
|
|
|
+ firstCell.setCellValue(cellValue);
|
|
|
+
|
|
|
+ // 创建居中样式
|
|
|
+ CellStyle centerStyle = sheet.getWorkbook().createCellStyle();
|
|
|
+ centerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ centerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+
|
|
|
+ // 设置边框
|
|
|
+ centerStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ centerStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ centerStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ centerStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ XSSFColor colorBlue = new XSSFColor(new Color(48, 84, 150));
|
|
|
+ centerStyle.setFillForegroundColor(colorBlue.getIndex());
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+ font.setColor(IndexedColors.BLACK.getIndex());
|
|
|
+ font.setFontName("微软雅黑");// 设置标题字体
|
|
|
+ centerStyle.setFont(font);
|
|
|
+ firstCell.setCellStyle(centerStyle);
|
|
|
+
|
|
|
+
|
|
|
+ // 清除合并区域内其他单元格的内容
|
|
|
+ for (int i = startCol + 1; i <= endCol; i++) {
|
|
|
+ Cell cell = row.getCell(i);
|
|
|
+ if (cell != null) {
|
|
|
+ cell.setCellValue("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取单元格字符串值
|
|
|
+ */
|
|
|
+ private static String getCellValue(Row row, int columnIndex) {
|
|
|
+ Cell cell = row.getCell(columnIndex);
|
|
|
+ if (cell == null) return null;
|
|
|
+
|
|
|
+ switch (cell.getCellType()) {
|
|
|
+ case STRING:
|
|
|
+ return cell.getStringCellValue().trim();
|
|
|
+ case NUMERIC:
|
|
|
+ if (DateUtil.isCellDateFormatted(cell)) {
|
|
|
+ return cell.getDateCellValue().toString();
|
|
|
+ }
|
|
|
+ return String.valueOf(cell.getNumericCellValue());
|
|
|
+ case BOOLEAN:
|
|
|
+ return String.valueOf(cell.getBooleanCellValue());
|
|
|
+ case FORMULA:
|
|
|
+ return cell.getCellFormula();
|
|
|
+ default:
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 合并指定Excel sheet页、指定列中连续相同内容的单元格
|
|
|
+ *
|
|
|
+ * @param sheet Excel sheet
|
|
|
+ * @param startRow 从第几行开始, startRow的值从1开始
|
|
|
+ * @param column 指定列
|
|
|
+ */
|
|
|
+ public static void mergeSameCellContentColumn(Sheet sheet, int startRow, int column) {
|
|
|
+ int totalRows = sheet.getLastRowNum();
|
|
|
+ int firstRow = 0;
|
|
|
+ int lastRow = 0;
|
|
|
+ // 上一次比较是否相同
|
|
|
+ boolean isPrevCompareSame = false;
|
|
|
+ String prevMergeAddress = null;
|
|
|
+ String currentMergeAddress;
|
|
|
+ // 从第几开始判断是否相同
|
|
|
+ if (totalRows >= startRow) {
|
|
|
+ for (int i = startRow; i <= totalRows; i++) {
|
|
|
+ String lastRowCellContent = sheet.getRow(i - 1).getCell(column).getStringCellValue();
|
|
|
+ String curRowCellContent = sheet.getRow(i).getCell(column).getStringCellValue();
|
|
|
+ if (curRowCellContent.equals(lastRowCellContent)) {
|
|
|
+ if (!isPrevCompareSame) {
|
|
|
+ firstRow = i - 1;
|
|
|
+ }
|
|
|
+ lastRow = i;
|
|
|
+ isPrevCompareSame = true;
|
|
|
+ } else {
|
|
|
+ isPrevCompareSame = false;
|
|
|
+ currentMergeAddress = firstRow + lastRow + column + column + "";
|
|
|
+ if (lastRow > firstRow && !Objects.equals(currentMergeAddress, prevMergeAddress)) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, column, column));
|
|
|
+ prevMergeAddress = currentMergeAddress;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 最后一行时判断是否有需要合并的行
|
|
|
+ if ((i == totalRows) && (lastRow > firstRow)) {
|
|
|
+ currentMergeAddress = firstRow + lastRow + column + column + "";
|
|
|
+ if (!Objects.equals(currentMergeAddress, prevMergeAddress)) {
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, column, column));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|