|
|
|
@ -2,22 +2,37 @@ package com.biutag.supervision.service; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.excel.write.handler.CellWriteHandler; |
|
|
|
import com.alibaba.excel.write.handler.CellWriteHandler; |
|
|
|
|
|
|
|
import com.alibaba.excel.write.handler.RowWriteHandler; |
|
|
|
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext; |
|
|
|
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext; |
|
|
|
|
|
|
|
import com.alibaba.excel.write.handler.context.RowWriteHandlerContext; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
import org.apache.poi.ss.usermodel.CellStyle; |
|
|
|
import org.apache.poi.ss.usermodel.Font; |
|
|
|
import org.apache.poi.ss.usermodel.Font; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment; |
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors; |
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors; |
|
|
|
import org.apache.poi.ss.usermodel.RichTextString; |
|
|
|
import org.apache.poi.ss.usermodel.RichTextString; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFColor; |
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFFont; |
|
|
|
|
|
|
|
|
|
|
|
public class ModifiedVerifyContentCellWriteHandler implements CellWriteHandler { |
|
|
|
public class ModifiedVerifyContentCellWriteHandler implements CellWriteHandler, RowWriteHandler { |
|
|
|
|
|
|
|
|
|
|
|
private static final int MODIFIED_VERIFY_CONTENT_COLUMN_INDEX = 6; |
|
|
|
private static final int MODIFIED_VERIFY_CONTENT_COLUMN_INDEX = 6; |
|
|
|
|
|
|
|
private static final int FINAL_WRITE_ORDER = 60000; |
|
|
|
|
|
|
|
private static final int ESTIMATED_CHARACTERS_PER_LINE = 55; |
|
|
|
|
|
|
|
private static final float ROW_HEIGHT_PER_LINE = 20F; |
|
|
|
|
|
|
|
|
|
|
|
private Font labelFont; |
|
|
|
private Font labelFont; |
|
|
|
private Font arrowFont; |
|
|
|
private Font arrowFont; |
|
|
|
private CellStyle wrappedStyle; |
|
|
|
private CellStyle wrappedStyle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public int order() { |
|
|
|
|
|
|
|
return FINAL_WRITE_ORDER; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void afterCellDispose(CellWriteHandlerContext context) { |
|
|
|
public void afterCellDispose(CellWriteHandlerContext context) { |
|
|
|
if (Boolean.TRUE.equals(context.getHead()) |
|
|
|
if (Boolean.TRUE.equals(context.getHead()) |
|
|
|
@ -35,21 +50,38 @@ public class ModifiedVerifyContentCellWriteHandler implements CellWriteHandler { |
|
|
|
String[] lines = content.split("\\n", -1); |
|
|
|
String[] lines = content.split("\\n", -1); |
|
|
|
int offset = 0; |
|
|
|
int offset = 0; |
|
|
|
for (String line : lines) { |
|
|
|
for (String line : lines) { |
|
|
|
int separatorIndex = line.indexOf(':'); |
|
|
|
int separatorIndex = line.indexOf('\uFF1A'); |
|
|
|
if (separatorIndex > 0) { |
|
|
|
if (separatorIndex > 0) { |
|
|
|
richText.applyFont(offset, offset + separatorIndex, getLabelFont(workbook)); |
|
|
|
richText.applyFont(offset, offset + separatorIndex, getLabelFont(workbook)); |
|
|
|
} |
|
|
|
} |
|
|
|
int arrowIndex = line.indexOf('→', separatorIndex + 1); |
|
|
|
int arrowIndex = line.indexOf('\u2192', separatorIndex + 1); |
|
|
|
if (arrowIndex >= 0) { |
|
|
|
if (arrowIndex >= 0) { |
|
|
|
richText.applyFont(offset + arrowIndex, offset + arrowIndex + 1, getArrowFont(workbook)); |
|
|
|
richText.applyFont(offset + arrowIndex, offset + arrowIndex + 1, getArrowFont(workbook)); |
|
|
|
} |
|
|
|
} |
|
|
|
offset += line.length() + 1; |
|
|
|
offset += line.length() + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
float requiredHeight = Math.max(cell.getRow().getHeightInPoints(), lines.length * 18F); |
|
|
|
|
|
|
|
cell.getRow().setHeightInPoints(requiredHeight); |
|
|
|
|
|
|
|
cell.setCellValue(richText); |
|
|
|
cell.setCellValue(richText); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void afterRowDispose(RowWriteHandlerContext context) { |
|
|
|
|
|
|
|
if (Boolean.TRUE.equals(context.getHead())) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Row row = context.getRow(); |
|
|
|
|
|
|
|
Cell contentCell = row.getCell(MODIFIED_VERIFY_CONTENT_COLUMN_INDEX); |
|
|
|
|
|
|
|
if (contentCell == null || StrUtil.isBlank(contentCell.getStringCellValue())) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String[] lines = contentCell.getStringCellValue().split("\\n", -1); |
|
|
|
|
|
|
|
int visualLineCount = 0; |
|
|
|
|
|
|
|
for (String line : lines) { |
|
|
|
|
|
|
|
visualLineCount += Math.max(1, (line.length() + ESTIMATED_CHARACTERS_PER_LINE - 1) |
|
|
|
|
|
|
|
/ ESTIMATED_CHARACTERS_PER_LINE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
row.setHeightInPoints(Math.max(row.getHeightInPoints(), visualLineCount * ROW_HEIGHT_PER_LINE)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Font getLabelFont(Workbook workbook) { |
|
|
|
private Font getLabelFont(Workbook workbook) { |
|
|
|
if (labelFont == null) { |
|
|
|
if (labelFont == null) { |
|
|
|
labelFont = workbook.createFont(); |
|
|
|
labelFont = workbook.createFont(); |
|
|
|
@ -63,7 +95,11 @@ public class ModifiedVerifyContentCellWriteHandler implements CellWriteHandler { |
|
|
|
if (arrowFont == null) { |
|
|
|
if (arrowFont == null) { |
|
|
|
arrowFont = workbook.createFont(); |
|
|
|
arrowFont = workbook.createFont(); |
|
|
|
arrowFont.setBold(true); |
|
|
|
arrowFont.setBold(true); |
|
|
|
arrowFont.setColor(IndexedColors.RED.getIndex()); |
|
|
|
if (arrowFont instanceof XSSFFont xssfFont) { |
|
|
|
|
|
|
|
xssfFont.setColor(new XSSFColor(new byte[]{(byte) 255, 0, 0}, null)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
arrowFont.setColor(IndexedColors.RED.getIndex()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return arrowFont; |
|
|
|
return arrowFont; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -73,7 +109,10 @@ public class ModifiedVerifyContentCellWriteHandler implements CellWriteHandler { |
|
|
|
wrappedStyle = workbook.createCellStyle(); |
|
|
|
wrappedStyle = workbook.createCellStyle(); |
|
|
|
wrappedStyle.cloneStyleFrom(cell.getCellStyle()); |
|
|
|
wrappedStyle.cloneStyleFrom(cell.getCellStyle()); |
|
|
|
wrappedStyle.setWrapText(true); |
|
|
|
wrappedStyle.setWrapText(true); |
|
|
|
|
|
|
|
wrappedStyle.setVerticalAlignment(VerticalAlignment.TOP); |
|
|
|
|
|
|
|
wrappedStyle.setAlignment(HorizontalAlignment.LEFT); |
|
|
|
} |
|
|
|
} |
|
|
|
cell.setCellStyle(wrappedStyle); |
|
|
|
cell.setCellStyle(wrappedStyle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|