11-21-添加对应方法2
This commit is contained in:
@ -471,7 +471,7 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
/**
|
/**
|
||||||
* 构建模板完整结构(添加自动调整行高)
|
* 构建模板完整结构(添加自动调整行高)
|
||||||
*/
|
*/
|
||||||
private void buildTemplateFullStructure(Sheet sheet, Workbook workbook,HseSafetyWeeklyReport report,Integer weekOfYear) {
|
private void buildTemplateFullStructure(Sheet sheet, Workbook workbook,HseSafetyWeeklyReport report,Integer weekOfYear) {
|
||||||
// 创建所有需要的样式
|
// 创建所有需要的样式
|
||||||
CellStyle titleStyle = createTitleCellStyle(workbook);
|
CellStyle titleStyle = createTitleCellStyle(workbook);
|
||||||
CellStyle headerStyle = createHeaderCellStyle(workbook);
|
CellStyle headerStyle = createHeaderCellStyle(workbook);
|
||||||
@ -526,7 +526,10 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
// 15. 确保所有单元格都有边框
|
// 15. 确保所有单元格都有边框
|
||||||
ensureAllCellsHaveBorders(sheet, workbook);
|
ensureAllCellsHaveBorders(sheet, workbook);
|
||||||
|
|
||||||
// 16. 自动调整行高以适应内容
|
// 16. 为施工进度和设备材料表格的I列添加条件格式化数据条
|
||||||
|
addPercentageFillForProgressTable(sheet, workbook);
|
||||||
|
|
||||||
|
// 17. 自动调整行高以适应内容
|
||||||
autoAdjustRowHeights(sheet);
|
autoAdjustRowHeights(sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -890,11 +893,11 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 施工进度统计表(第11-18行)- 修正数据赋值问题
|
* 施工进度统计表(第11-18行)- 修正数据赋值问题,确保I列是数值格式
|
||||||
*/
|
*/
|
||||||
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,
|
||||||
CellStyle tableHeaderStyle) {
|
CellStyle tableHeaderStyle) {
|
||||||
// 表头行(第11行)
|
// 表头行(第11行)
|
||||||
Row headerRow = sheet.createRow(startRow);
|
Row headerRow = sheet.createRow(startRow);
|
||||||
|
|
||||||
@ -934,15 +937,18 @@ 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);
|
||||||
@ -953,9 +959,22 @@ 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) {
|
||||||
cell.setCellValue(progressData[i][j]);
|
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.setCellStyle(contentStyle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cell.setCellValue(progressData[i][j]);
|
||||||
|
cell.setCellStyle(contentStyle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cell.setCellStyle(contentStyle);
|
||||||
}
|
}
|
||||||
cell.setCellStyle(contentStyle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置J,K列(下周计划完成)- 使用数据数组的第8个元素
|
// 设置J,K列(下周计划完成)- 使用数据数组的第8个元素
|
||||||
@ -992,11 +1011,11 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备材料表格(第19-23行)- 修正数据赋值问题
|
* 设备材料表格(第19-23行)- 修正数据赋值问题,确保I列是数值格式
|
||||||
*/
|
*/
|
||||||
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,
|
||||||
CellStyle tableHeaderStyle) {
|
CellStyle tableHeaderStyle) {
|
||||||
// 表头行(第19行)
|
// 表头行(第19行)
|
||||||
Row headerRow = sheet.createRow(startRow);
|
Row headerRow = sheet.createRow(startRow);
|
||||||
|
|
||||||
@ -1036,12 +1055,15 @@ 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);
|
||||||
@ -1052,9 +1074,22 @@ 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) {
|
||||||
cell.setCellValue(materialData[i][j]);
|
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.setCellStyle(contentStyle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cell.setCellValue(materialData[i][j]);
|
||||||
|
cell.setCellStyle(contentStyle);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cell.setCellStyle(contentStyle);
|
||||||
}
|
}
|
||||||
cell.setCellStyle(contentStyle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置J,K列(计划到货日期)- 使用数据数组的第8个元素
|
// 设置J,K列(计划到货日期)- 使用数据数组的第8个元素
|
||||||
@ -1627,4 +1662,27 @@ public class HseSafetyWeeklyReportServiceImpl extends ServiceImpl<HseSafetyWeekl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建数值格式样式
|
||||||
|
*/
|
||||||
|
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