|
|
|
@ -3293,12 +3293,14 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
Cell cell62 = row6.createCell(4); |
|
|
|
cell62.setCellValue(inspectionReport.getInspectionTaskName()); |
|
|
|
cell62.setCellStyle(colStyle2); |
|
|
|
autoFitRowHeight(sheet, 4, 4, colStyle2); |
|
|
|
Cell cell63 = row6.createCell(8); |
|
|
|
cell63.setCellValue(MessageUtils.get("巡视统计")); |
|
|
|
cell63.setCellStyle(colStyle2); |
|
|
|
Cell cell64 = row6.createCell(12); |
|
|
|
cell64.setCellValue(inspectionReport.getPatrolStatistics()); |
|
|
|
cell64.setCellStyle(colStyle2); |
|
|
|
autoFitRowHeight(sheet, 4, 12, colStyle2); |
|
|
|
|
|
|
|
for (int i = 0; i < 15; ++i) { |
|
|
|
if (i != 0 && i != 4 && i != 8 && i != 12) { |
|
|
|
@ -3743,6 +3745,53 @@ public class PatrolTaskResultMainController extends BaseController { |
|
|
|
return outputStream.toByteArray(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 自适应行高(手动计算) |
|
|
|
* @param sheet |
|
|
|
* @param rowNum 行号 |
|
|
|
* @param cellNum 列号 |
|
|
|
* @param style 样式 |
|
|
|
*/ |
|
|
|
public void autoFitRowHeight(Sheet sheet, int rowNum, int cellNum, CellStyle style) { |
|
|
|
Row row = sheet.getRow(rowNum); |
|
|
|
if (row == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
Cell cell = row.getCell(cellNum); |
|
|
|
if (cell == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
String text = cell.getStringCellValue(); |
|
|
|
if (text == null || text.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
int columnWidth = sheet.getColumnWidth(0); |
|
|
|
double widthInChars = columnWidth / 256.0; |
|
|
|
|
|
|
|
// 获取字体 |
|
|
|
Font font = sheet.getWorkbook().getFontAt(style.getFontIndex()); |
|
|
|
double fontHeightInPoints = font.getFontHeightInPoints(); |
|
|
|
// 计算每行可容纳字符数(近似公式) |
|
|
|
// 粗略估计 |
|
|
|
double charsPerLine = widthInChars * 1.0; |
|
|
|
|
|
|
|
// 按换行符分割 + 按列宽折行 |
|
|
|
String[] lines = text.split("\n"); |
|
|
|
int totalLines = 0; |
|
|
|
|
|
|
|
for (String line : lines) { |
|
|
|
int lineChars = line.length(); |
|
|
|
int linesNeeded = (int) Math.ceil(lineChars / charsPerLine); |
|
|
|
totalLines += Math.max(1, linesNeeded); |
|
|
|
} |
|
|
|
|
|
|
|
// 设置行高(1 行 ≈ 15 磅,POI 用 points) |
|
|
|
double rowHeightInPoints = totalLines * fontHeightInPoints; |
|
|
|
row.setHeightInPoints((float) Math.max(rowHeightInPoints, row.getHeightInPoints())); |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping({"/test"}) |
|
|
|
public AjaxResult test(int count) { |
|
|
|
String strs = "menglei/2.jpg,menglei/1123.jpg"; |
|
|
|
|