您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EXCEL_EXPORT_STANDARD.md 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Excel export standard (FPSMS backend)
  2. This document mirrors the **visual and formatting rules** used on the frontend for `.xlsx` exports.
  3. **It does not run automatically:** backend code paths (JasperReports XLSX export, Apache POI, etc.) are separate from the Next.js `xlsx-js-style` pipeline. Apply these rules **manually** when implementing or changing server-side Excel so outputs stay consistent with the UI standard.
  4. **Frontend reference (implementation details):**
  5. `FPSMS-frontend/src/app/(main)/chart/_components/EXCEL_EXPORT_STANDARD.md`
  6. ---
  7. ## When backend Excel is used
  8. Typical cases:
  9. - JasperReports templates configured for **XLSX** output (`JRXlsxExporter` or similar).
  10. - **Apache POI** (`XSSFWorkbook`, `SXSSFWorkbook`) building sheets in Kotlin/Java services (e.g. production schedule export, BOM, item templates).
  11. Reports that return **JSON only** and let the **browser** build the file (e.g. GRN `rep-014`) are **not** covered here — those follow the frontend doc.
  12. ---
  13. ## Rules to mirror (parity with frontend)
  14. | Element | Target |
  15. |--------|--------|
  16. | **Header row** | Bold, black text; fill **light grey** `#D9D9D9` (RGB); vertical center; for header text use horizontal **center** + wrap unless the column is numeric (see below). |
  17. | **Money / amount columns** | Excel number format **`#,##0.00`** (thousands separator, 2 decimals). **Right-align** header and data. |
  18. | **Quantity columns** | **Right-align** header and data (no fixed decimal rule on frontend; match business need). |
  19. | **Column width** | At least readable for bilingual headers; frontend uses `max(12, headerLength + 4)` character width — approximate in POI with `setColumnWidth`. |
  20. ### Column detection (naming)
  21. Align with frontend header keywords so exports **feel** the same:
  22. - **Money:** headers containing `金額`, `單價`, `Amount`, `Unit Price`, `Total Amount` (including bilingual labels like `Amount / 金額`).
  23. - **Quantity:** headers containing `Qty`, `數量`, `Demand`.
  24. ---
  25. ## Apache POI (sketch)
  26. - Create `CellStyle` for header: `setFillForegroundColor` (indexed or XSSFColor for `#D9D9D9`), `setFillPattern`, **bold** font, alignment.
  27. - Data format for money: `DataFormat` → `"#,##0.00"` on numeric cells.
  28. - `setAlignment(HorizontalAlignment.RIGHT)` for amount/qty columns (and header cells in those columns if desired).
  29. ---
  30. ## JasperReports
  31. - Apply styles in the report template (fonts, background, borders) and numeric **pattern** for amount fields equivalent to `#,##0.00` where supported.
  32. - Verify in Excel output: Jasper’s XLSX styling capabilities differ slightly from POI — test the generated file.
  33. ---
  34. ## Checklist for new backend Excel features
  35. 1. Confirm whether the report is **backend-only** Excel or **JSON + frontend** Excel — only the latter uses the TypeScript standard automatically.
  36. 2. For backend-only, apply header fill, money format, and alignment per the table above.
  37. 3. Keep naming of column titles consistent with the keywords in **Column detection** when possible.
  38. ---
  39. *Aligned with frontend `EXCEL_EXPORT_STANDARD.md` (grey `#D9D9D9`, `#,##0.00` for amounts, right-align numeric columns).*