|
@@ -7,14 +7,11 @@ import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.aspose.cells.*;
|
|
import com.aspose.cells.*;
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.rongwei.bscommon.sys.config.api.ResponseVO;
|
|
import com.rongwei.bscommon.sys.config.api.ResponseVO;
|
|
import com.rongwei.bscommon.sys.dao.LuckysheetDao;
|
|
import com.rongwei.bscommon.sys.dao.LuckysheetDao;
|
|
import com.rongwei.bscommon.sys.feign.LuckySheetService;
|
|
import com.rongwei.bscommon.sys.feign.LuckySheetService;
|
|
import com.rongwei.bscommon.sys.service.*;
|
|
import com.rongwei.bscommon.sys.service.*;
|
|
-import com.rongwei.bscommon.sys.utils.JsonUtil;
|
|
|
|
import com.rongwei.bscommon.sys.utils.LuckySheet4SummaryHelp;
|
|
import com.rongwei.bscommon.sys.utils.LuckySheet4SummaryHelp;
|
|
import com.rongwei.bscommon.sys.utils.ProjectSummaryExcelHelp;
|
|
import com.rongwei.bscommon.sys.utils.ProjectSummaryExcelHelp;
|
|
import com.rongwei.bscommon.sys.utils.XlsSheetUtil;
|
|
import com.rongwei.bscommon.sys.utils.XlsSheetUtil;
|
|
@@ -87,7 +84,12 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
private ZhcxProjectManageDao zhcxProjectManageDao;
|
|
private ZhcxProjectManageDao zhcxProjectManageDao;
|
|
@Autowired
|
|
@Autowired
|
|
private LuckySheetService luckySheetFeignService;
|
|
private LuckySheetService luckySheetFeignService;
|
|
-
|
|
|
|
|
|
+ private static final Color[] COLORS = {Color.fromArgb(255, 255, 204),
|
|
|
|
+ Color.fromArgb(210, 242, 210),
|
|
|
|
+ Color.fromArgb(255, 252, 213, 180),
|
|
|
|
+ Color.fromArgb(255, 255, 102, 0),
|
|
|
|
+ Color.fromArgb(255, 51, 153, 102),
|
|
|
|
+ Color.fromArgb(255, 255, 0, 0)};
|
|
/**
|
|
/**
|
|
* 生成汇总文件
|
|
* 生成汇总文件
|
|
*
|
|
*
|
|
@@ -402,7 +404,17 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
map.put("projname", dto.getFileName());
|
|
map.put("projname", dto.getFileName());
|
|
|
|
|
|
//导出
|
|
//导出
|
|
- int result = exportRectifyReportDataBySheet(workbook, worksheet, map, response);
|
|
|
|
|
|
+ int result = exportRectifyReportDataBySheet(workbook, worksheet, map);
|
|
|
|
+ try {
|
|
|
|
+ response.addHeader("Pargam", "no-cache");
|
|
|
|
+ response.addHeader("Cache-Control", "no-cache");
|
|
|
|
+ response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=整改清单.xlsx");
|
|
|
|
+ workbook.save(response.getOutputStream(), SaveFormat.XLSX);
|
|
|
|
+ workbook.dispose();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
if(result == 0){
|
|
if(result == 0){
|
|
throw new CustomException("导出失败");
|
|
throw new CustomException("导出失败");
|
|
}
|
|
}
|
|
@@ -417,7 +429,7 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
* @param response
|
|
* @param response
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- private int exportRectifyReportDataBySheet(Workbook workbook, Worksheet worksheet, Map<String, Object> map, HttpServletResponse response) {
|
|
|
|
|
|
+ private int exportRectifyReportDataBySheet(Workbook workbook, Worksheet worksheet, Map<String, Object> map) {
|
|
R r = this.getRectifyReportData(map);
|
|
R r = this.getRectifyReportData(map);
|
|
Object depttypeobj = map.getOrDefault("depttype", "施工部门");
|
|
Object depttypeobj = map.getOrDefault("depttype", "施工部门");
|
|
Object projnameobj = map.get("projname");
|
|
Object projnameobj = map.get("projname");
|
|
@@ -428,158 +440,225 @@ public class ZhcxProjectManageServiceImpl extends ServiceImpl<ZhcxProjectManageD
|
|
String projName = (String) projnameobj;
|
|
String projName = (String) projnameobj;
|
|
RectifyReportDto data = (RectifyReportDto) r.getData();
|
|
RectifyReportDto data = (RectifyReportDto) r.getData();
|
|
if (data != null) {
|
|
if (data != null) {
|
|
- try {
|
|
|
|
-
|
|
|
|
-// Workbook workbook = new Workbook();
|
|
|
|
-// WorksheetCollection worksheets = workbook.getWorksheets();
|
|
|
|
-// Worksheet worksheet = worksheets.get(0);
|
|
|
|
- Cells cells = worksheet.getCells();
|
|
|
|
- cells.setRowHeight(0, 40);
|
|
|
|
- cells.setColumnWidth(0, 20);
|
|
|
|
- cells.setColumnWidth(1, 20);
|
|
|
|
- List<String> noList = data.getNoList();
|
|
|
|
-
|
|
|
|
- // 设置列头
|
|
|
|
- cells.merge(1, 0, 2, 1);
|
|
|
|
- cells.merge(1, 1, 2, 1);
|
|
|
|
- Resource resource = new ClassPathResource("/img/zpmc.png");
|
|
|
|
- InputStream inputStream = resource.getInputStream();
|
|
|
|
-
|
|
|
|
- int pictureIndex = worksheet.getPictures().add(0, 0, inputStream);
|
|
|
|
- Picture picture = worksheet.getPictures().get(pictureIndex);
|
|
|
|
- double cellWidth = worksheet.getCells().getColumnWidthPixel(0);
|
|
|
|
- double cellHeight = worksheet.getCells().getRowHeightPixel(0);
|
|
|
|
-
|
|
|
|
- // 获取图片的宽高
|
|
|
|
- int pictureWidth = picture.getWidth();
|
|
|
|
- int pictureHeight = picture.getHeight();
|
|
|
|
-
|
|
|
|
- // 计算图片在单元格中的偏移量
|
|
|
|
- int offsetX = (int) ((cellWidth - pictureWidth));
|
|
|
|
- int offsetY = (int) ((cellHeight - pictureHeight));
|
|
|
|
-
|
|
|
|
- // 确保图片在单元格内居中
|
|
|
|
- picture.setLeft(offsetX);
|
|
|
|
- picture.setTop(offsetY);
|
|
|
|
-
|
|
|
|
- // 将单元格宽度和高度调整为适合图片的大小
|
|
|
|
- worksheet.getCells().setColumnWidthPixel(0, Math.max(pictureWidth, (int) cellWidth));
|
|
|
|
- worksheet.getCells().setRowHeightPixel(0, Math.max(pictureHeight, (int) cellHeight));
|
|
|
|
-
|
|
|
|
- cells.get(0, 1).putValue("QA");
|
|
|
|
- cells.get(0, 2).putValue(projName + "项目整改汇总文字版");
|
|
|
|
- cells.get(1, 0).putValue("一级部门");
|
|
|
|
- cells.get(1, 1).putValue(deptType);
|
|
|
|
-
|
|
|
|
- // 设置颜色列表
|
|
|
|
- Color[] colors = {Color.fromArgb(210, 242, 210), Color.fromArgb(255, 255, 204)};
|
|
|
|
-
|
|
|
|
- int colIndex = 2;
|
|
|
|
- int colorIndex = 0;
|
|
|
|
- for (String no : noList) {
|
|
|
|
- cells.merge(1, colIndex, 1, 6);
|
|
|
|
- cells.get(1, colIndex).putValue(no);
|
|
|
|
- cells.get(2, colIndex).putValue("整改总数");
|
|
|
|
- cells.get(2, colIndex + 1).putValue("完成率1");
|
|
|
|
- cells.get(2, colIndex + 2).putValue("完成率2");
|
|
|
|
- cells.get(2, colIndex + 3).putValue("关闭");
|
|
|
|
- cells.get(2, colIndex + 4).putValue("未完成");
|
|
|
|
- cells.get(2, colIndex + 5).putValue("待确认");
|
|
|
|
-
|
|
|
|
- // 设置颜色
|
|
|
|
- for (int i = 1; i <= 2; i++) {
|
|
|
|
- for (int j = colIndex; j < colIndex + 6; j++) {
|
|
|
|
- Style cellStyle = cells.get(i, j).getStyle();
|
|
|
|
- cellStyle.setForegroundColor(colors[colorIndex % 2]);
|
|
|
|
- cellStyle.setPattern(BackgroundType.SOLID);
|
|
|
|
- cells.get(i, j).setStyle(cellStyle);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ Cells cells = worksheet.getCells();
|
|
|
|
+
|
|
|
|
+ // 设置固定列头
|
|
|
|
+ setFrozenHeader(deptType, projName, cells);
|
|
|
|
+ //插入图片
|
|
|
|
+ insertPic(worksheet, cells);
|
|
|
|
+
|
|
|
|
+ // 设置颜色列表 //0机号1颜色、1机号2颜色、2汇总部门颜色、3车间颜色,4基地外颜色,5合计颜色
|
|
|
|
+ List<String> noList = data.getNoList();
|
|
|
|
+ //设置动态列
|
|
|
|
+ setTrendsHeader(cells, noList);
|
|
|
|
+
|
|
|
|
+ // 填充数据
|
|
|
|
+ int rowIndex = 3;
|
|
|
|
+ int colIndex = 2;
|
|
|
|
+ for (RectifyDto row : data.getData()) {
|
|
|
|
+ //填充数据组织颜色
|
|
|
|
+ fillDataOrgColor(cells, rowIndex, row);
|
|
|
|
+ colIndex = 2;
|
|
|
|
+ //填充数据颜色 返回索引
|
|
|
|
+ colIndex = fillDataColor(cells,colIndex, noList, rowIndex, row);
|
|
|
|
+ rowIndex++;
|
|
|
|
+ }
|
|
|
|
|
|
- colIndex += 6;
|
|
|
|
- colorIndex++;
|
|
|
|
|
|
+ // 设置公共样式
|
|
|
|
+ Style commonStyle = workbook.createStyle();
|
|
|
|
+ commonStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
|
|
|
|
+ commonStyle.setVerticalAlignment(TextAlignmentType.CENTER);
|
|
|
|
+ commonStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+ commonStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+ commonStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+ commonStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+
|
|
|
|
+ // 应用公共样式
|
|
|
|
+ for (int i = 0; i < colIndex; i++) {
|
|
|
|
+ for (int x = 0; x < rowIndex; x++) {
|
|
|
|
+ Style cellStyle = cells.get(x, i).getStyle();
|
|
|
|
+ commonStyle.setPattern(BackgroundType.SOLID);
|
|
|
|
+ commonStyle.setForegroundColor(cellStyle.getForegroundColor());
|
|
|
|
+ commonStyle.getFont().setColor(cellStyle.getFont().getColor());
|
|
|
|
+ cells.get(x, i).setStyle(commonStyle);
|
|
}
|
|
}
|
|
- cells.merge(0, 2, 1, noList.size() * 6);
|
|
|
|
-
|
|
|
|
- // 填充数据
|
|
|
|
- int rowIndex = 3;
|
|
|
|
- for (RectifyDto row : data.getData()) {
|
|
|
|
- cells.get(rowIndex, 0).putValue(row.getFirstdeptname());
|
|
|
|
- cells.get(rowIndex, 1).putValue(row.getDeptname());
|
|
|
|
-
|
|
|
|
- List<RectifyMachineDto> innerDataList = row.getData();
|
|
|
|
- colIndex = 2;
|
|
|
|
- colorIndex = 0;
|
|
|
|
- for (String no : noList) {
|
|
|
|
- RectifyMachineDto rectifyMachineDto = innerDataList.stream()
|
|
|
|
- .filter(innerRow -> no.equals(innerRow.getNo()))
|
|
|
|
- .findFirst()
|
|
|
|
- .orElse(null);
|
|
|
|
- if (rectifyMachineDto != null) {
|
|
|
|
- cells.get(rowIndex, colIndex).putValue(rectifyMachineDto.getTotalCount());
|
|
|
|
- cells.get(rowIndex, colIndex + 1).putValue(rectifyMachineDto.getFinishRateOne());
|
|
|
|
- cells.get(rowIndex, colIndex + 2).putValue(rectifyMachineDto.getFinishRateTwo());
|
|
|
|
- cells.get(rowIndex, colIndex + 3).putValue(rectifyMachineDto.getClosedCount());
|
|
|
|
- cells.get(rowIndex, colIndex + 4).putValue(rectifyMachineDto.getUnfinishedCount());
|
|
|
|
- cells.get(rowIndex, colIndex + 5).putValue(rectifyMachineDto.getTbcCount());
|
|
|
|
- // 设置颜色
|
|
|
|
- for (int j = colIndex; j < colIndex + 6; j++) {
|
|
|
|
- Style cellStyle = workbook.createStyle();
|
|
|
|
- cellStyle.setForegroundColor(colors[colorIndex % 2]);
|
|
|
|
- cellStyle.setPattern(BackgroundType.SOLID);
|
|
|
|
- cells.get(rowIndex, j).setStyle(cellStyle);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- colIndex += 6;
|
|
|
|
- colorIndex++;
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 一级部门和deptType列样式
|
|
|
|
+ Style headerStyle = workbook.createStyle();
|
|
|
|
+ headerStyle.getFont().setBold(true);
|
|
|
|
+ headerStyle.getFont().setSize(20);
|
|
|
|
+ headerStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
|
|
|
|
+ headerStyle.setVerticalAlignment(TextAlignmentType.CENTER);
|
|
|
|
+ headerStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+ headerStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+ headerStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+ headerStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
+ cells.get(0, 1).setStyle(headerStyle);
|
|
|
|
+ cells.get(0, 2).setStyle(headerStyle);
|
|
|
|
+ }
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private int fillDataColor(Cells cells, int colIndex, List<String> noList, int rowIndex, RectifyDto row) {
|
|
|
|
+ int colorIndex = 0;
|
|
|
|
+ List<RectifyMachineDto> innerDataList = row.getData();
|
|
|
|
+ for (String no : noList) {
|
|
|
|
+ RectifyMachineDto rectifyMachineDto = innerDataList.stream()
|
|
|
|
+ .filter(innerRow -> no.equals(innerRow.getNo()))
|
|
|
|
+ .findFirst()
|
|
|
|
+ .orElse(null);
|
|
|
|
+ if (rectifyMachineDto != null) {
|
|
|
|
+ cells.get(rowIndex, colIndex).putValue(rectifyMachineDto.getTotalCount());
|
|
|
|
+ cells.get(rowIndex, colIndex + 1).putValue(rectifyMachineDto.getFinishRateOne());
|
|
|
|
+ cells.get(rowIndex, colIndex + 2).putValue(rectifyMachineDto.getFinishRateTwo());
|
|
|
|
+ cells.get(rowIndex, colIndex + 3).putValue(rectifyMachineDto.getClosedCount());
|
|
|
|
+ cells.get(rowIndex, colIndex + 4).putValue(rectifyMachineDto.getUnfinishedCount());
|
|
|
|
+ cells.get(rowIndex, colIndex + 5).putValue(rectifyMachineDto.getTbcCount());
|
|
|
|
+ // 设置颜色
|
|
|
|
+ for (int j = colIndex; j < colIndex + 6; j++) {
|
|
|
|
+ Style cellStyle = cells.get(rowIndex, j).getStyle();
|
|
|
|
+ if (StringUtils.isNotBlank(row.getDeptid())) {
|
|
|
|
+ cellStyle.setForegroundColor(COLORS[colorIndex % 2]);
|
|
|
|
+ }else if(StringUtils.isBlank(row.getDeptid())
|
|
|
|
+ && StringUtils.isBlank(row.getFirstdeptid())
|
|
|
|
+ && StringUtils.isBlank(row.getFirstdeptname())){
|
|
|
|
+ //合计颜色
|
|
|
|
+ cellStyle.setForegroundColor(COLORS[5]);
|
|
|
|
+ }else{
|
|
|
|
+ cellStyle.setForegroundColor(COLORS[2]);
|
|
}
|
|
}
|
|
- rowIndex++;
|
|
|
|
|
|
+ cellStyle.setPattern(BackgroundType.SOLID);
|
|
|
|
+ cells.get(rowIndex, j).setStyle(cellStyle);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ colIndex += 6;
|
|
|
|
+ colorIndex++;
|
|
|
|
+ }
|
|
|
|
+ return colIndex;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 填充数据颜色
|
|
|
|
+ * @param cells
|
|
|
|
+ * @param rowIndex
|
|
|
|
+ * @param row
|
|
|
|
+ */
|
|
|
|
+ private void fillDataOrgColor(Cells cells, int rowIndex, RectifyDto row) {
|
|
|
|
+ cells.get(rowIndex, 0).putValue(row.getFirstdeptname());
|
|
|
|
+ if (StringUtils.isNotBlank(row.getDeptname())) {
|
|
|
|
+ cells.get(rowIndex, 1).putValue(row.getDeptname());
|
|
|
|
+ }else{
|
|
|
|
+ cells.get(rowIndex, 1).putValue(row.getFirstdeptname());
|
|
|
|
+ }
|
|
|
|
+ Style style = cells.get(rowIndex, 1).getStyle();
|
|
|
|
+ style.setPattern(BackgroundType.SOLID);
|
|
|
|
+ //车间颜色
|
|
|
|
+ if(StringUtils.isNotBlank(row.getDeptid()) && StringUtils.isNotBlank(row.getFirstdeptid())){
|
|
|
|
+ style.setForegroundColor(COLORS[3]);
|
|
|
|
+ }else if(StringUtils.isNotBlank(row.getDeptid()) && StringUtils.isBlank(row.getFirstdeptid())){
|
|
|
|
+ //基地外颜色
|
|
|
|
+ style.setForegroundColor(COLORS[4]);
|
|
|
|
+ }else if(StringUtils.isBlank(row.getDeptid()) && StringUtils.isBlank(row.getFirstdeptid())
|
|
|
|
+ && StringUtils.isBlank(row.getFirstdeptname())){
|
|
|
|
+ //合计颜色
|
|
|
|
+ style.setForegroundColor(COLORS[5]);
|
|
|
|
+ }else{
|
|
|
|
+ //部门汇总颜色
|
|
|
|
+ style.setForegroundColor(COLORS[2]);
|
|
|
|
+ }
|
|
|
|
+ cells.get(rowIndex, 1).setStyle(style);
|
|
|
|
+ }
|
|
|
|
|
|
- // 设置公共样式
|
|
|
|
- Style commonStyle = workbook.createStyle();
|
|
|
|
- commonStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
|
|
|
|
- commonStyle.setVerticalAlignment(TextAlignmentType.CENTER);
|
|
|
|
- commonStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
- commonStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
- commonStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
- commonStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
-
|
|
|
|
- // 应用公共样式
|
|
|
|
- for (int i = 0; i < colIndex; i++) {
|
|
|
|
- for (int x = 0; x < rowIndex; x++) {
|
|
|
|
- Style cellStyle = cells.get(x, i).getStyle();
|
|
|
|
- commonStyle.setPattern(BackgroundType.SOLID);
|
|
|
|
- commonStyle.setForegroundColor(cellStyle.getForegroundColor());
|
|
|
|
- cells.get(x, i).setStyle(commonStyle);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 设置动态列
|
|
|
|
+ * @param cells
|
|
|
|
+ * @param noList
|
|
|
|
+ * @param colIndex
|
|
|
|
+ * @param colorIndex
|
|
|
|
+ */
|
|
|
|
+ private void setTrendsHeader(Cells cells, List<String> noList) {
|
|
|
|
+ int colIndex = 2;
|
|
|
|
+ int colorIndex = 0;
|
|
|
|
+ for (String no : noList) {
|
|
|
|
+ cells.merge(1, colIndex, 1, 6);
|
|
|
|
+ cells.get(1, colIndex).putValue(no);
|
|
|
|
+ cells.get(2, colIndex).putValue("整改总数");
|
|
|
|
+ cells.get(2, colIndex + 1).putValue("关闭率");
|
|
|
|
+ cells.get(2, colIndex + 2).putValue("待关闭率");
|
|
|
|
+ cells.get(2, colIndex + 3).putValue("关闭");
|
|
|
|
+ cells.get(2, colIndex + 4).putValue("未完成");
|
|
|
|
+ cells.get(2, colIndex + 5).putValue("待确认");
|
|
|
|
+
|
|
|
|
+ // 设置颜色
|
|
|
|
+ for (int i = 1; i <= 2; i++) {
|
|
|
|
+ for (int j = colIndex; j < colIndex + 6; j++) {
|
|
|
|
+ Style cellStyle = cells.get(i, j).getStyle();
|
|
|
|
+ // "关闭率" 和 "待关闭率"设置字体颜色为红色
|
|
|
|
+ if (j == colIndex + 1 || j == colIndex + 2) {
|
|
|
|
+ cellStyle.getFont().setColor(COLORS[5]);
|
|
}
|
|
}
|
|
|
|
+ cellStyle.setForegroundColor(COLORS[colorIndex % 2]);
|
|
|
|
+ cellStyle.setPattern(BackgroundType.SOLID);
|
|
|
|
+ cells.get(i, j).setStyle(cellStyle);
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 一级部门和deptType列样式
|
|
|
|
- Style headerStyle = workbook.createStyle();
|
|
|
|
- headerStyle.getFont().setBold(true);
|
|
|
|
- headerStyle.getFont().setSize(20);
|
|
|
|
- headerStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
|
|
|
|
- headerStyle.setVerticalAlignment(TextAlignmentType.CENTER);
|
|
|
|
- headerStyle.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
- headerStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
- headerStyle.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
- headerStyle.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
|
|
|
|
-
|
|
|
|
- cells.get(0, 1).setStyle(headerStyle);
|
|
|
|
- cells.get(0, 2).setStyle(headerStyle);
|
|
|
|
-
|
|
|
|
- response.addHeader("Pargam", "no-cache");
|
|
|
|
- response.addHeader("Cache-Control", "no-cache");
|
|
|
|
- response.setContentType("application/octet-stream;charset=ISO8859-1");
|
|
|
|
- response.setHeader("Content-Disposition", "attachment;filename=整改清单.xlsx");
|
|
|
|
- workbook.save(response.getOutputStream(), SaveFormat.XLSX);
|
|
|
|
- workbook.dispose();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("整改清单导出报错", e);
|
|
|
|
}
|
|
}
|
|
|
|
+ colIndex += 6;
|
|
|
|
+ colorIndex++;
|
|
|
|
+ }
|
|
|
|
+ cells.merge(0, 2, 1, noList.size() * 6);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 固定列头
|
|
|
|
+ * @param deptType
|
|
|
|
+ * @param projName
|
|
|
|
+ * @param cells
|
|
|
|
+ */
|
|
|
|
+ private void setFrozenHeader(String deptType, String projName, Cells cells) {
|
|
|
|
+ cells.merge(1, 0, 2, 1);
|
|
|
|
+ cells.merge(1, 1, 2, 1);
|
|
|
|
+ cells.get(0, 1).putValue("QA");
|
|
|
|
+ cells.get(0, 2).putValue(projName + "项目整改汇总文字版");
|
|
|
|
+ cells.get(1, 0).putValue("一级部门");
|
|
|
|
+ cells.get(1, 1).putValue(deptType);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 插入图片
|
|
|
|
+ * @param worksheet
|
|
|
|
+ * @param cells
|
|
|
|
+ */
|
|
|
|
+ private void insertPic(Worksheet worksheet, Cells cells) {
|
|
|
|
+ cells.setRowHeight(0, 40);
|
|
|
|
+ cells.setColumnWidth(0, 20);
|
|
|
|
+ cells.setColumnWidth(1, 20);
|
|
|
|
+ Resource resource = new ClassPathResource("/img/zpmc.png");
|
|
|
|
+ try (InputStream inputStream = resource.getInputStream()) {
|
|
|
|
+
|
|
|
|
+ int pictureIndex = worksheet.getPictures().add(0, 0, inputStream);
|
|
|
|
+ Picture picture = worksheet.getPictures().get(pictureIndex);
|
|
|
|
+ double cellWidth = worksheet.getCells().getColumnWidthPixel(0);
|
|
|
|
+ double cellHeight = worksheet.getCells().getRowHeightPixel(0);
|
|
|
|
+
|
|
|
|
+ // 获取图片的宽高
|
|
|
|
+ int pictureWidth = picture.getWidth();
|
|
|
|
+ int pictureHeight = picture.getHeight();
|
|
|
|
+
|
|
|
|
+ // 计算图片在单元格中的偏移量
|
|
|
|
+ int offsetX = (int) ((cellWidth - pictureWidth));
|
|
|
|
+ int offsetY = (int) ((cellHeight - pictureHeight));
|
|
|
|
+
|
|
|
|
+ // 确保图片在单元格内居中
|
|
|
|
+ picture.setLeft(offsetX);
|
|
|
|
+ picture.setTop(offsetY);
|
|
|
|
+
|
|
|
|
+ // 将单元格宽度和高度调整为适合图片的大小
|
|
|
|
+ worksheet.getCells().setColumnWidthPixel(0, Math.max(pictureWidth, (int) cellWidth));
|
|
|
|
+ worksheet.getCells().setRowHeightPixel(0, Math.max(pictureHeight, (int) cellHeight));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("整改清单导出报错", e);
|
|
}
|
|
}
|
|
- return 1;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|