fix(b09-print): 인쇄 미리보기 좌측 하단 두 줄(가로 넘침 없음) · 엑셀 시트 인쇄 설정 = PDF 방향 · A4 · 폭 1쪽 · 머리 줄 반복 (302-5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QfHKQs7J3hQELKMWQMUJEy
This commit is contained in:
2026-10-13 08:24:05 +09:00
co-authored by Claude Opus 5.5
parent 13ba1fe298
commit d4ad0d6685
5 changed files with 102 additions and 5 deletions
+19 -1
View File
@@ -8,7 +8,7 @@
POST /api/projects/{id}/print/table-xlsx {title, sheets:[{name, grid}]}
grid(`B09_Draft_Print_Table.sheetGrid`) → 엑셀 — 시트 = 차례대로 · 이름 31자 ·
금지 글자 바꿈 · 머리 굵게 · 병합 · 테두리 · 숫자 = 숫자 칸(열 소수 서식) ·
레벨 = 들여쓰기 · 열 폭
레벨 = 들여쓰기 · 열 폭 · 인쇄 = 시트 방향 · A4 · 폭 1쪽 · 머리 줄 반복
`B09_Estimation_Router` 가 draft/*_Router.py 의 router 를 끼워 넣음
(같은 머리 · 같은 권한 = 회사 · 프로젝트).
@@ -199,6 +199,22 @@ def number_format(decimals: int | None) -> str:
return "#,##0" + ("." + "0" * decimals if decimals else "")
def print_setup(ws: Any, orientation: str, head_rows: int) -> None:
"""인쇄 설정(302-5) — PDF 와 같은 방향 · A4 · 폭 1쪽 맞춤 · 머리 줄 쪽마다 · 여백 ≈ PDF."""
from openpyxl.worksheet.page import PageMargins
ws.page_setup.orientation = orientation
ws.page_setup.paperSize = ws.PAPERSIZE_A4
ws.page_setup.fitToWidth = 1
ws.page_setup.fitToHeight = 0
ws.sheet_properties.pageSetUpPr.fitToPage = True
ws.page_margins = PageMargins(left=0.4, right=0.4, top=0.4, bottom=0.55, header=0.2, footer=0.2)
if head_rows:
ws.print_title_rows = f"1:{head_rows}"
ws.oddHeader.left.text = "&A" # 시트 이름
ws.oddFooter.center.text = "&P / &N" # 쪽 번호
def build_xlsx(sheets: list[dict[str, Any]]) -> bytes:
"""grid 시트들 → 엑셀 바이트(차례 그대로)."""
from openpyxl import Workbook
@@ -255,6 +271,7 @@ def build_xlsx(sheets: list[dict[str, Any]]) -> bytes:
ws.cell(top + 1 + m["r"], m["c"] + 1).alignment = Alignment(vertical="center")
if top:
ws.freeze_panes = ws.cell(top + 1, (g.get("frozen") or 0) + 1)
print_setup(ws, sheet.get("orientation") or "portrait", top)
out = io.BytesIO()
wb.save(out)
return out.getvalue()
@@ -292,6 +309,7 @@ class PdfSheet(BaseModel):
class XlsxSheet(BaseModel):
name: str = Field(max_length=200)
orientation: Literal["portrait", "landscape"] = "portrait"
grid: dict[str, Any]