Showing
9 changed files
with
96 additions
and
1 deletions
xingyun-sc/src/main/java/com/lframework/xingyun/sc/controller/order/PurchaseOrderInfoController.java
| ... | ... | @@ -480,6 +480,8 @@ public class PurchaseOrderInfoController extends DefaultBaseController { |
| 480 | 480 | processTemplate(workbook, dataMap); |
| 481 | 481 | |
| 482 | 482 | if ("PDF".equals(exportType)) { |
| 483 | + ExcelUtil.adjustVerticalTitleForPdf(workbook, sheet, "具体质量要求", true); | |
| 484 | + ExcelUtil.adjustVerticalTitleForPdf(workbook, sheet, "生产工艺", false); | |
| 483 | 485 | ResponseUtil.setPDFResponseHead(response, data.getOrderNo() + "-订货单打印.pdf"); |
| 484 | 486 | |
| 485 | 487 | // === 写入临时 .xlsx 文件 === | ... | ... |
| ... | ... | @@ -270,6 +270,8 @@ public class BusinessDataExportHandler implements ExportHandler { |
| 270 | 270 | |
| 271 | 271 | String createTime = orderInfo.getCreateTime().format(dateTimeFormatter); |
| 272 | 272 | if ("PDF".equals(queryVo.getExportFileType())) { |
| 273 | + ExcelUtil.adjustVerticalTitleForPdf(workbook, sheet, "具体质量要求", true); | |
| 274 | + ExcelUtil.adjustVerticalTitleForPdf(workbook, sheet, "生产工艺", false); | |
| 273 | 275 | // 输出PDF |
| 274 | 276 | File tempExcel = File.createTempFile("purchase_order_" + orderInfo.getOrderNo(), ".xlsx"); |
| 275 | 277 | try (FileOutputStream fos = new FileOutputStream(tempExcel)) { | ... | ... |
| ... | ... | @@ -278,4 +278,92 @@ public class ExcelUtil { |
| 278 | 278 | } |
| 279 | 279 | return pdfFile; |
| 280 | 280 | } |
| 281 | + | |
| 282 | + public static void adjustVerticalTitleForPdf(Workbook workbook, Sheet sheet, String text, boolean mergedCell) { | |
| 283 | + for (Row row : sheet) { | |
| 284 | + for (Cell cell : row) { | |
| 285 | + if (cell == null || cell.getCellTypeEnum() != CellType.STRING) { | |
| 286 | + continue; | |
| 287 | + } | |
| 288 | + String cellValue = normalizeCellText(cell.getStringCellValue()); | |
| 289 | + if (!normalizeCellText(text).equals(cellValue)) { | |
| 290 | + continue; | |
| 291 | + } | |
| 292 | + | |
| 293 | + cell.setCellValue(buildVerticalText(text)); | |
| 294 | + | |
| 295 | + CellStyle baseStyle = cell.getCellStyle(); | |
| 296 | + CellStyle pdfStyle = workbook.createCellStyle(); | |
| 297 | + if (baseStyle != null) { | |
| 298 | + pdfStyle.cloneStyleFrom(baseStyle); | |
| 299 | + } | |
| 300 | + pdfStyle.setAlignment(HorizontalAlignment.CENTER); | |
| 301 | + pdfStyle.setVerticalAlignment(VerticalAlignment.CENTER); | |
| 302 | + pdfStyle.setWrapText(true); | |
| 303 | + pdfStyle.setRotation((short) 0); | |
| 304 | + pdfStyle.setIndention((short) 0); | |
| 305 | + | |
| 306 | + if (mergedCell) { | |
| 307 | + CellRangeAddress mergedRegion = findMergedRegion(sheet, cell.getRowIndex(), cell.getColumnIndex()); | |
| 308 | + if (mergedRegion != null) { | |
| 309 | + for (int r = mergedRegion.getFirstRow(); r <= mergedRegion.getLastRow(); r++) { | |
| 310 | + Row currentRow = sheet.getRow(r); | |
| 311 | + if (currentRow == null) { | |
| 312 | + currentRow = sheet.createRow(r); | |
| 313 | + } | |
| 314 | + for (int c = mergedRegion.getFirstColumn(); c <= mergedRegion.getLastColumn(); c++) { | |
| 315 | + Cell currentCell = currentRow.getCell(c); | |
| 316 | + if (currentCell == null) { | |
| 317 | + currentCell = currentRow.createCell(c); | |
| 318 | + } | |
| 319 | + currentCell.setCellStyle(pdfStyle); | |
| 320 | + } | |
| 321 | + } | |
| 322 | + } else { | |
| 323 | + cell.setCellStyle(pdfStyle); | |
| 324 | + } | |
| 325 | + } else { | |
| 326 | + cell.setCellStyle(pdfStyle); | |
| 327 | + } | |
| 328 | + return; | |
| 329 | + } | |
| 330 | + } | |
| 331 | + } | |
| 332 | + | |
| 333 | + private static String buildVerticalText(String text) { | |
| 334 | + StringBuilder builder = new StringBuilder(); | |
| 335 | + for (int i = 0; i < text.length(); i++) { | |
| 336 | + if (i > 0) { | |
| 337 | + builder.append("\n"); | |
| 338 | + } | |
| 339 | + builder.append(text.charAt(i)); | |
| 340 | + } | |
| 341 | + return builder.toString(); | |
| 342 | + } | |
| 343 | + | |
| 344 | + private static String normalizeCellText(String text) { | |
| 345 | + if (text == null) { | |
| 346 | + return ""; | |
| 347 | + } | |
| 348 | + return text.replace("\r", "") | |
| 349 | + .replace("\n", "") | |
| 350 | + .replace(" ", "") | |
| 351 | + .trim(); | |
| 352 | + } | |
| 353 | + | |
| 354 | + private static CellRangeAddress findMergedRegion(Sheet sheet, int rowIndex, int colIndex) { | |
| 355 | + for (int i = 0; i < sheet.getNumMergedRegions(); i++) { | |
| 356 | + CellRangeAddress region = sheet.getMergedRegion(i); | |
| 357 | + if (region == null) { | |
| 358 | + continue; | |
| 359 | + } | |
| 360 | + if (rowIndex >= region.getFirstRow() | |
| 361 | + && rowIndex <= region.getLastRow() | |
| 362 | + && colIndex >= region.getFirstColumn() | |
| 363 | + && colIndex <= region.getLastColumn()) { | |
| 364 | + return region; | |
| 365 | + } | |
| 366 | + } | |
| 367 | + return null; | |
| 368 | + } | |
| 281 | 369 | } | ... | ... |
| ... | ... | @@ -106,7 +106,7 @@ public class LatexFormulaExcelExporterUtil { |
| 106 | 106 | actual = actual + "\\phantom{" + phantom + "}"; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - return "\\mathbf{" + actual + "}"; | |
| 109 | + return "\\mathbf{\\mathrm{" + actual + "}}"; | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | private static String buildLatexLine(List<FormulaComponent> componentList, int startIndex, int endIndexExclusive) { |
| ... | ... | @@ -192,6 +192,8 @@ public class LatexFormulaExcelExporterUtil { |
| 192 | 192 | g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
| 193 | 193 | g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); |
| 194 | 194 | g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); |
| 195 | + java.awt.Font renderFont = new java.awt.Font("宋体", java.awt.Font.BOLD, fontSize); | |
| 196 | + g2.setFont(renderFont); | |
| 195 | 197 | |
| 196 | 198 | // 绘制白色背景 |
| 197 | 199 | g2.setColor(Color.WHITE); |
| ... | ... | @@ -202,6 +204,7 @@ public class LatexFormulaExcelExporterUtil { |
| 202 | 204 | |
| 203 | 205 | // 绘制公式 |
| 204 | 206 | JLabel label = new JLabel(); |
| 207 | + label.setFont(renderFont); | |
| 205 | 208 | label.setForeground(Color.BLACK); |
| 206 | 209 | icon.paintIcon(label, g2, 0, 0); |
| 207 | 210 | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type