11-21-还原
This commit is contained in:
@ -12,7 +12,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.usermodel.*;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.dromara.common.core.constant.HttpStatus;
|
import org.dromara.common.core.constant.HttpStatus;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.utils.ObjectUtils;
|
import org.dromara.common.core.utils.ObjectUtils;
|
||||||
@ -526,10 +526,7 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
// 15. 确保所有单元格都有边框
|
// 15. 确保所有单元格都有边框
|
||||||
ensureAllCellsHaveBorders(sheet, workbook);
|
ensureAllCellsHaveBorders(sheet, workbook);
|
||||||
|
|
||||||
// 16. 为施工进度和设备材料表格的I列添加条件格式化数据条
|
// 16. 自动调整行高以适应内容
|
||||||
addPercentageFillForProgressTable(sheet, workbook);
|
|
||||||
|
|
||||||
// 17. 自动调整行高以适应内容
|
|
||||||
autoAdjustRowHeights(sheet);
|
autoAdjustRowHeights(sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -893,7 +890,7 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 施工进度统计表(第11-18行)- 修正数据赋值问题,确保I列是数值格式
|
* 施工进度统计表(第11-18行)- 修正数据赋值问题
|
||||||
*/
|
*/
|
||||||
private void createConstructionProgressTable(Sheet sheet, Workbook workbook, int startRow,
|
private void createConstructionProgressTable(Sheet sheet, Workbook workbook, int startRow,
|
||||||
CellStyle headerStyle, CellStyle contentStyle,
|
CellStyle headerStyle, CellStyle contentStyle,
|
||||||
@ -937,18 +934,15 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
|
|
||||||
// 数据行(第12-18行,共7行)- 修正数据位置和赋值
|
// 数据行(第12-18行,共7行)- 修正数据位置和赋值
|
||||||
String[][] progressData = {
|
String[][] progressData = {
|
||||||
{"基础", "光伏区", "个", "164728", "3955", "104434", "63.4", "6000", "设计值为根据7.18日最新电子版图纸统计,包含未开工的五工区,总设计容量约为357.5Mpw。"},
|
{"基础", "光伏区", "个", "164728", "3955", "104434", "63.4%", "6000", "设计值为根据7.18日最新电子版图纸统计,包含未开工的五工区,总设计容量约为357.5Mpw。"},
|
||||||
{"支架", "", "组", "20591", "644", "6412", "31.1", "1050", ""},
|
{"支架", "", "组", "20591", "644", "6412", "31.1%", "1050", ""},
|
||||||
{"组件", "", "组", "20591", "409", "4902", "23.8", "850", ""},
|
{"组件", "", "组", "20591", "409", "4902", "23.8%", "850", ""},
|
||||||
{"清表", "", "亩", "4517", "0", "4104", "90.8", "100", ""},
|
{"清表", "", "亩", "4517", "0", "4104", "90.8%", "100", ""},
|
||||||
{"塔基", "线路工程", "", "", "", "", "", "", ""},
|
{"塔基", "线路工程", "", "", "", "", "", "", ""},
|
||||||
{"组塔", "", "", "", "", "", "", "", ""},
|
{"组塔", "", "", "", "", "", "", "", ""},
|
||||||
{"放线", "", "", "", "", "", "", "", ""}
|
{"放线", "", "", "", "", "", "", "", ""}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 创建数值格式样式
|
|
||||||
CellStyle numberStyle = createNumberCellStyle(workbook);
|
|
||||||
|
|
||||||
for (int i = 0; i < progressData.length; i++) {
|
for (int i = 0; i < progressData.length; i++) {
|
||||||
Row row = sheet.createRow(startRow + 1 + i);
|
Row row = sheet.createRow(startRow + 1 + i);
|
||||||
row.setHeightInPoints(20);
|
row.setHeightInPoints(20);
|
||||||
@ -959,23 +953,10 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
for (int j = 0; j < 7; j++) { // 只设置前7列数据(C-I列)
|
for (int j = 0; j < 7; j++) { // 只设置前7列数据(C-I列)
|
||||||
Cell cell = row.createCell(j + 2); // C列开始
|
Cell cell = row.createCell(j + 2); // C列开始
|
||||||
if (j < progressData[i].length) {
|
if (j < progressData[i].length) {
|
||||||
if (j == 6) { // I列(累计完成率)- 设置为数值
|
|
||||||
try {
|
|
||||||
double value = Double.parseDouble(progressData[i][j]);
|
|
||||||
cell.setCellValue(value);
|
|
||||||
cell.setCellStyle(numberStyle);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
cell.setCellValue(progressData[i][j]);
|
cell.setCellValue(progressData[i][j]);
|
||||||
cell.setCellStyle(contentStyle);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cell.setCellValue(progressData[i][j]);
|
|
||||||
cell.setCellStyle(contentStyle);
|
cell.setCellStyle(contentStyle);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cell.setCellStyle(contentStyle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置J,K列(下周计划完成)- 使用数据数组的第8个元素
|
// 设置J,K列(下周计划完成)- 使用数据数组的第8个元素
|
||||||
Cell jkCell = row.createCell(9); // J列
|
Cell jkCell = row.createCell(9); // J列
|
||||||
@ -1011,7 +992,7 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备材料表格(第19-23行)- 修正数据赋值问题,确保I列是数值格式
|
* 设备材料表格(第19-23行)- 修正数据赋值问题
|
||||||
*/
|
*/
|
||||||
private void createEquipmentMaterialTable(Sheet sheet, Workbook workbook, int startRow,
|
private void createEquipmentMaterialTable(Sheet sheet, Workbook workbook, int startRow,
|
||||||
CellStyle headerStyle, CellStyle contentStyle,
|
CellStyle headerStyle, CellStyle contentStyle,
|
||||||
@ -1055,15 +1036,12 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
|
|
||||||
// 数据行 - 从第20行开始(共4行数据)- 修正数据位置和赋值
|
// 数据行 - 从第20行开始(共4行数据)- 修正数据位置和赋值
|
||||||
String[][] materialData = {
|
String[][] materialData = {
|
||||||
{"檩条、斜撑", "", "根", "131728", "3752", "106745", "81.0", "", ""},
|
{"檩条、斜撑", "", "根", "131728", "3752", "106745", "81.0%", "", ""},
|
||||||
{"立杆", "", "根", "133841", "5549", "53372", "39.9", "", ""},
|
{"立杆", "", "根", "133841", "5549", "53372", "39.9%", "", ""},
|
||||||
{"光伏组件", "", "块", "576548", "25880", "177360", "30.8", "", ""},
|
{"光伏组件", "", "块", "576548", "25880", "177360", "30.8%", "", ""},
|
||||||
{"预埋件", "", "套", "164728", "0", "113000", "68.6", "", ""}
|
{"预埋件", "", "套", "164728", "0", "113000", "68.6%", "", ""}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 创建数值格式样式
|
|
||||||
CellStyle numberStyle = createNumberCellStyle(workbook);
|
|
||||||
|
|
||||||
for (int i = 0; i < materialData.length; i++) {
|
for (int i = 0; i < materialData.length; i++) {
|
||||||
Row row = sheet.createRow(startRow + 1 + i);
|
Row row = sheet.createRow(startRow + 1 + i);
|
||||||
row.setHeightInPoints(20);
|
row.setHeightInPoints(20);
|
||||||
@ -1074,23 +1052,10 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
for (int j = 0; j < 7; j++) { // 只设置前7列数据(C-I列)
|
for (int j = 0; j < 7; j++) { // 只设置前7列数据(C-I列)
|
||||||
Cell cell = row.createCell(j + 2); // C列开始
|
Cell cell = row.createCell(j + 2); // C列开始
|
||||||
if (j < materialData[i].length) {
|
if (j < materialData[i].length) {
|
||||||
if (j == 6) { // I列(累计到货率)- 设置为数值
|
|
||||||
try {
|
|
||||||
double value = Double.parseDouble(materialData[i][j]);
|
|
||||||
cell.setCellValue(value);
|
|
||||||
cell.setCellStyle(numberStyle);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
cell.setCellValue(materialData[i][j]);
|
cell.setCellValue(materialData[i][j]);
|
||||||
cell.setCellStyle(contentStyle);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cell.setCellValue(materialData[i][j]);
|
|
||||||
cell.setCellStyle(contentStyle);
|
cell.setCellStyle(contentStyle);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cell.setCellStyle(contentStyle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置J,K列(计划到货日期)- 使用数据数组的第8个元素
|
// 设置J,K列(计划到货日期)- 使用数据数组的第8个元素
|
||||||
Cell jkCell = row.createCell(9); // J列
|
Cell jkCell = row.createCell(9); // J列
|
||||||
@ -1519,170 +1484,4 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 为施工进度统计表(第12-18行)和设备材料表格(第20-23行)的I列添加条件格式化数据条
|
|
||||||
*/
|
|
||||||
private void addPercentageFillForProgressTable(Sheet sheet, Workbook workbook) {
|
|
||||||
if (sheet instanceof XSSFSheet) {
|
|
||||||
// 使用XSSF的条件格式化(.xlsx格式)
|
|
||||||
addDataBarsConditionalFormatting((XSSFSheet) sheet);
|
|
||||||
} else {
|
|
||||||
// 使用HSSF的条件格式化(.xls格式)
|
|
||||||
addColorScaleConditionalFormatting(sheet, workbook);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为XSSFSheet添加数据条条件格式化(.xlsx格式)
|
|
||||||
*/
|
|
||||||
private void addDataBarsConditionalFormatting(XSSFSheet sheet) {
|
|
||||||
try {
|
|
||||||
XSSFSheetConditionalFormatting conditionalFormatting = sheet.getSheetConditionalFormatting();
|
|
||||||
|
|
||||||
// 施工进度统计表:I12-I18
|
|
||||||
CellRangeAddress[] progressRanges = new CellRangeAddress[] {
|
|
||||||
new CellRangeAddress(11, 17, 8, 8) // I12-I18
|
|
||||||
};
|
|
||||||
|
|
||||||
// 设备材料表格:I20-I23
|
|
||||||
CellRangeAddress[] materialRanges = new CellRangeAddress[] {
|
|
||||||
new CellRangeAddress(19, 22, 8, 8) // I20-I23
|
|
||||||
};
|
|
||||||
|
|
||||||
// 创建数据条规则 - 使用正确的API
|
|
||||||
XSSFConditionalFormattingRule dataBarRule = conditionalFormatting.createConditionalFormattingRule(
|
|
||||||
org.apache.poi.ss.usermodel.ComparisonOperator.NO_COMPARISON,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
// 获取数据条格式化对象并设置颜色
|
|
||||||
XSSFDataBarFormatting dataBarFormatting = dataBarRule.getDataBarFormatting();
|
|
||||||
|
|
||||||
// 设置数据条颜色为红色
|
|
||||||
XSSFColor redColor = new XSSFColor(new java.awt.Color(255, 0, 0), new DefaultIndexedColorMap());
|
|
||||||
dataBarFormatting.setColor(redColor);
|
|
||||||
|
|
||||||
// 设置最小值和最大值(自动检测)
|
|
||||||
dataBarFormatting.getMinThreshold().setRangeType(org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType.MIN);
|
|
||||||
dataBarFormatting.getMaxThreshold().setRangeType(org.apache.poi.ss.usermodel.ConditionalFormattingThreshold.RangeType.MAX);
|
|
||||||
|
|
||||||
// 应用数据条规则到施工进度表
|
|
||||||
conditionalFormatting.addConditionalFormatting(progressRanges, dataBarRule);
|
|
||||||
|
|
||||||
// 应用数据条规则到设备材料表
|
|
||||||
conditionalFormatting.addConditionalFormatting(materialRanges, dataBarRule);
|
|
||||||
|
|
||||||
System.out.println("数据条条件格式化已成功应用");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("创建数据条条件格式化失败: " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
// 降级到颜色刻度方案
|
|
||||||
addColorScaleConditionalFormatting(sheet, sheet.getWorkbook());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为HSSFSheet添加颜色刻度条件格式化(.xls格式)
|
|
||||||
*/
|
|
||||||
private void addColorScaleConditionalFormatting(Sheet sheet, Workbook workbook) {
|
|
||||||
try {
|
|
||||||
// 施工进度统计表:I12-I18
|
|
||||||
CellRangeAddress progressRange = new CellRangeAddress(11, 17, 8, 8);
|
|
||||||
|
|
||||||
// 设备材料表格:I20-I23
|
|
||||||
CellRangeAddress materialRange = new CellRangeAddress(19, 22, 8, 8);
|
|
||||||
|
|
||||||
// 创建条件格式化规则
|
|
||||||
SheetConditionalFormatting conditionalFormatting = sheet.getSheetConditionalFormatting();
|
|
||||||
|
|
||||||
// 创建颜色刻度规则(三色刻度:白-粉-红)
|
|
||||||
ConditionalFormattingRule rule = conditionalFormatting.createConditionalFormattingColorScaleRule();
|
|
||||||
|
|
||||||
// 应用规则
|
|
||||||
ConditionalFormattingRule[] rules = new ConditionalFormattingRule[]{rule};
|
|
||||||
CellRangeAddress[] ranges = new CellRangeAddress[]{progressRange, materialRange};
|
|
||||||
|
|
||||||
conditionalFormatting.addConditionalFormatting(ranges, rules);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("创建颜色刻度条件格式化失败: " + e.getMessage());
|
|
||||||
// 最终降级方案:使用简单的条件格式化
|
|
||||||
addSimpleConditionalFormatting(sheet, workbook);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简单的条件格式化降级方案
|
|
||||||
*/
|
|
||||||
private void addSimpleConditionalFormatting(Sheet sheet, Workbook workbook) {
|
|
||||||
try {
|
|
||||||
SheetConditionalFormatting conditionalFormatting = sheet.getSheetConditionalFormatting();
|
|
||||||
|
|
||||||
// 定义条件格式化规则
|
|
||||||
// 规则1: 0-30% - 浅红色
|
|
||||||
ConditionalFormattingRule rule1 = conditionalFormatting.createConditionalFormattingRule(
|
|
||||||
"AND(ISNUMBER(I1), I1<=30)");
|
|
||||||
PatternFormatting fill1 = rule1.createPatternFormatting();
|
|
||||||
fill1.setFillBackgroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
|
|
||||||
fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
|
|
||||||
|
|
||||||
// 规则2: 31-60% - 中等红色
|
|
||||||
ConditionalFormattingRule rule2 = conditionalFormatting.createConditionalFormattingRule(
|
|
||||||
"AND(ISNUMBER(I1), I1>30, I1<=60)");
|
|
||||||
PatternFormatting fill2 = rule2.createPatternFormatting();
|
|
||||||
fill2.setFillBackgroundColor(IndexedColors.ORANGE.getIndex());
|
|
||||||
fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
|
|
||||||
|
|
||||||
// 规则3: 61-100% - 深红色
|
|
||||||
ConditionalFormattingRule rule3 = conditionalFormatting.createConditionalFormattingRule(
|
|
||||||
"AND(ISNUMBER(I1), I1>60)");
|
|
||||||
PatternFormatting fill3 = rule3.createPatternFormatting();
|
|
||||||
fill3.setFillBackgroundColor(IndexedColors.RED.getIndex());
|
|
||||||
fill3.setFillPattern(PatternFormatting.SOLID_FOREGROUND);
|
|
||||||
|
|
||||||
// 应用规则到两个区域
|
|
||||||
ConditionalFormattingRule[] rules = new ConditionalFormattingRule[]{rule1, rule2, rule3};
|
|
||||||
|
|
||||||
// 施工进度统计表
|
|
||||||
CellRangeAddress[] progressRanges = new CellRangeAddress[] {
|
|
||||||
new CellRangeAddress(11, 17, 8, 8)
|
|
||||||
};
|
|
||||||
conditionalFormatting.addConditionalFormatting(progressRanges, rules);
|
|
||||||
|
|
||||||
// 设备材料表格
|
|
||||||
CellRangeAddress[] materialRanges = new CellRangeAddress[] {
|
|
||||||
new CellRangeAddress(19, 22, 8, 8)
|
|
||||||
};
|
|
||||||
conditionalFormatting.addConditionalFormatting(materialRanges, rules);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.err.println("创建简单条件格式化失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建数值格式样式
|
|
||||||
*/
|
|
||||||
private CellStyle createNumberCellStyle(Workbook workbook) {
|
|
||||||
CellStyle style = workbook.createCellStyle();
|
|
||||||
Font font = workbook.createFont();
|
|
||||||
font.setFontName("宋体");
|
|
||||||
font.setFontHeightInPoints((short)10);
|
|
||||||
style.setFont(font);
|
|
||||||
style.setAlignment(HorizontalAlignment.CENTER);
|
|
||||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
||||||
style.setBorderTop(BorderStyle.THIN);
|
|
||||||
style.setBorderBottom(BorderStyle.THIN);
|
|
||||||
style.setBorderLeft(BorderStyle.THIN);
|
|
||||||
style.setBorderRight(BorderStyle.THIN);
|
|
||||||
|
|
||||||
// 设置数值格式为百分比
|
|
||||||
DataFormat format = workbook.createDataFormat();
|
|
||||||
style.setDataFormat(format.getFormat("0.0%"));
|
|
||||||
|
|
||||||
return style;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user