{"type":"doc","content":[{"type":"paragraph","attrs":{"id":"39379077-f4f8-472b-90ff-5a3ddcc0d0a4","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"问题"},{"type":"hardBreak","attrs":{"id":"352fdd17-d91c-4429-860b-7bc922a0746f"}},{"type":"text","text":"底稿交稿前要统一排版:加页眉“被审计单位”、页脚“第X页/共Y页”、冻结首行、设打印区域和列宽。几百张表手工点很累。用 openpyxl 批量设置。"}]},{"type":"paragraph","attrs":{"id":"c8d27e5c-3fe0-4a1e-af2e-1e64c806d3c5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"示例代码"}]},{"type":"paragraph","attrs":{"id":"62520b3c-2225-429b-91c5-6e4a2005527d","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"textStyle","attrs":{"color":"","background":""}}],"text":"plaintext"}]},{"type":"codeBlock","attrs":{"id":"eae73934-d137-4d2f-9bc1-441153d587f7","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":"","languageByAi":"javascript"},"content":[{"type":"text","text":"import openpyxl\n\ndef format_sheet(ws, unit_name):\n ws.freeze_panes = \"A2\"\n ws.print_title_rows = \"1:1\"\n ws.page_setup.orientation = \"landscape\"\n ws.page_setup.fitToWidth = 1\n ws.page_margins.left = 0.5\n ws.page_margins.right = 0.5\n ws.header_center = unit_name\n ws.oddFooter.center = \"第 &P 页 / 共 &N 页\"\n ws.sheet_properties.pageSetUpPr.fitToPage = True\n for col in ws.columns:\n ws.column_dimensions[col[0].column_letter].width = 16\n return ws\n\nwb = openpyxl.load_workbook(\"wp.xlsx\")\nfor ws in wb.worksheets:\n format_sheet(ws, \"XX有限公司\")\nwb.save(\"wp_formatted.xlsx\")\n"}]},{"type":"paragraph","attrs":{"id":"fa1b3e10-bcb1-4cac-8889-f04389b602ac","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"关键点"}]},{"type":"bulletList","attrs":{"id":"a810c24a-bcd3-4867-9b03-fbcd35b62aa0","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"9a6473b8-e197-46ef-a36b-36e02996bca6"},"content":[{"type":"paragraph","attrs":{"id":"bc97b145-00fa-482c-9a4d-c796699b447d","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"freeze_panes=\"A2\" 冻结首行;print_title_rows 让每页重复表头。"}]}]},{"type":"listItem","attrs":{"id":"067c69d5-4d59-4499-bb08-d1b27770a59e"},"content":[{"type":"paragraph","attrs":{"id":"689f2613-8993-458f-9ac3-b7ce617c3048","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"页脚 &P/&N 是 Excel 内置页码域,打印自动编号,别手填。"}]}]},{"type":"listItem","attrs":{"id":"9f7c6d31-08a3-4b3e-92f5-b1087580c2ef"},"content":[{"type":"paragraph","attrs":{"id":"a5fecc9c-229f-4a7f-a0a8-61decd8214a7","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"fitToWidth=1 + pageSetUpPr.fitToPage=True 让宽表缩到一页宽,避免打印被截断。"}]}]}]},{"type":"paragraph","attrs":{"id":"f4d9fd35-2b87-46c4-875e-af1661d2f22f","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"小结"},{"type":"hardBreak","attrs":{"id":"19413bb9-c421-43da-8dd3-4eb97aac4850"}},{"type":"text","text":"排版是重复劳动,openpyxl 一个循环全所底稿统一格式,交稿即规范。"}]},{"type":"horizontalRule","attrs":{"id":"f791f2a6-bfdf-43c6-a655-782483a6c79f","isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"f563fa53-6a50-4d35-a534-6db6db44e368","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"你所底稿排版最乱的是页脚页码还是列宽?评论区交流。"}]},{"type":"paragraph","attrs":{"id":"6696e2cf-2a46-4a54-ad51-20159c7b0789","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"如果有用,点赞收藏关注,留下审计难题。下期预告:多 Excel 工作簿批量合并与汇总。"}]},{"type":"paragraph","attrs":{"id":"e1bf4a3d-587c-408b-b2b5-44fe19f62249","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"会计师事务所的一名注册会计师"}]}]}