[{"data":1,"prerenderedAt":2144},["ShallowReactive",2],{"doc:\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter":3,"surround:\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter":2109,"ancestors:\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter":2118,"children:\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter":2123,"related:\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter":2124},{"id":4,"title":5,"body":6,"dateModified":2076,"datePublished":2076,"description":2077,"extension":2078,"faq":2079,"keyword":2088,"kind":2089,"meta":2090,"navigation":121,"path":2099,"seo":2100,"slug":2102,"stem":2103,"topics":2104,"type":2107,"__hash__":2108},"docs\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter\u002Findex.md","Set Print Options, Headers and Footers with XlsxWriter",{"type":7,"value":8,"toc":2064},"minimark",[9,19,24,56,68,72,866,895,1024,1028,1039,1118,1136,1140,1180,1235,1263,1411,1415,1418,1711,1722,1876,1880,1906,1910,1964,1968,1999,2003,2009,2015,2021,2027,2031,2060],[10,11,12,13,18],"p",{},"A report that looks right on screen can print badly: columns spill onto a second sheet of paper, the header row appears only on page one, and nothing on page four says which report it belongs to or how many pages there are. Excel's page setup fixes all of this, and XlsxWriter exposes every part of it as worksheet methods, so a generated report can be correct for printing — and for PDF export, which uses the same settings — from the start. This page sets up a multi-page sales listing for printing: orientation, paper size and scaling, repeated header rows, print area, margins and centring, page breaks between regions, and headers and footers built from Excel's codes for page numbers, dates and the sheet name, with a logo. The result is exported to PDF with LibreOffice and read back to confirm what each page shows. It belongs to ",[14,15,17],"a",{"href":16},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002F","Building Excel Reports with xlsxwriter",".",[20,21,23],"h2",{"id":22},"prerequisites","Prerequisites",[25,26,31],"pre",{"className":27,"code":28,"language":29,"meta":30,"style":30},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install xlsxwriter pandas pdfplumber\n","bash","",[32,33,34],"code",{"__ignoreMap":30},[35,36,39,43,47,50,53],"span",{"class":37,"line":38},"line",1,[35,40,42],{"class":41},"sMTad","pip",[35,44,46],{"class":45},"srMev"," install",[35,48,49],{"class":45}," xlsxwriter",[35,51,52],{"class":45}," pandas",[35,54,55],{"class":45}," pdfplumber\n",[10,57,58,59,62,63,67],{},"LibreOffice (",[32,60,61],{},"soffice",") exports the workbook to PDF so the printed layout can be checked from Python; Excel's own ",[64,65,66],"em",{},"Save as PDF"," uses the same page setup. The example data is 120 sales lines across four regions, and a small logo image for the header.",[20,69,71],{"id":70},"step-1-data-and-the-basic-page-setup","Step 1 — Data and the basic page setup",[25,73,77],{"className":74,"code":75,"language":76,"meta":30,"style":30},"language-python shiki shiki-themes github-light github-dark-high-contrast","import numpy as np\nimport pandas as pd\nimport xlsxwriter\n\nrng = np.random.default_rng(3)\nregions = [\"East\", \"North\", \"South\", \"West\"]\nsales = pd.DataFrame({\"Region\": np.repeat(regions, 30), \"Order\": [f\"SO-{5000 + i}\" for i in range(120)],\n                      \"Customer\": [f\"Customer {i % 37:02d} Ltd\" for i in range(120)], \"Product\": rng.choice([\"Bolts\", \"Nuts\", \"Washers\", \"Rivets\", \"Brackets\"], 120),\n                      \"Qty\": rng.integers(5, 400, 120), \"Unit price\": rng.uniform(0.05, 9, 120).round(2),\n                      \"Discount\": rng.choice([0, 0.05, 0.1], 120), \"Rep\": rng.choice([\"A. Shah\", \"B. Lewis\", \"C. Ortiz\"], 120)})\nsales[\"Net\"] = (sales[\"Qty\"] * sales[\"Unit price\"] * (1 - sales[\"Discount\"])).round(2)\n\nwb = xlsxwriter.Workbook(\"sales_print.xlsx\")\nws = wb.add_worksheet(\"Sales Q3\")\nhead = wb.add_format({\"bold\": True, \"bg_color\": \"#DDEBF7\", \"border\": 1})\nmoney = wb.add_format({\"num_format\": \"#,##0.00\"})\nws.write_row(0, 0, sales.columns, head)\nfor r, row in enumerate(sales.itertuples(index=False), start=1):\n    ws.write_row(r, 0, row)\n    ws.write_number(r, 8, row.Net, money)\nws.set_column(\"A:B\", 9)\nws.set_column(\"C:C\", 18)\nws.set_column(\"D:H\", 10)\nws.set_column(\"I:I\", 11)\n\nws.set_landscape()\nws.set_paper(9)                      # 9 = A4; 1 = US Letter\nws.fit_to_pages(1, 0)                # one page wide, as many pages tall as needed\nws.repeat_rows(0)                    # print row 1 at the top of every page\nws.print_area(0, 0, len(sales), len(sales.columns) - 1)\nws.set_margins(left=0.5, right=0.5, top=0.9, bottom=0.8)\nws.center_horizontally()\n","python",[32,78,79,95,108,116,123,142,175,250,334,383,434,489,494,510,526,568,588,603,641,652,664,679,694,709,724,729,735,750,768,782,815,860],{"__ignoreMap":30},[35,80,81,85,89,92],{"class":37,"line":38},[35,82,84],{"class":83},"s-kum","import",[35,86,88],{"class":87},"skGVy"," numpy ",[35,90,91],{"class":83},"as",[35,93,94],{"class":87}," np\n",[35,96,98,100,103,105],{"class":37,"line":97},2,[35,99,84],{"class":83},[35,101,102],{"class":87}," pandas ",[35,104,91],{"class":83},[35,106,107],{"class":87}," pd\n",[35,109,111,113],{"class":37,"line":110},3,[35,112,84],{"class":83},[35,114,115],{"class":87}," xlsxwriter\n",[35,117,119],{"class":37,"line":118},4,[35,120,122],{"emptyLinePlaceholder":121},true,"\n",[35,124,126,129,132,135,139],{"class":37,"line":125},5,[35,127,128],{"class":87},"rng ",[35,130,131],{"class":83},"=",[35,133,134],{"class":87}," np.random.default_rng(",[35,136,138],{"class":137},"sP0c6","3",[35,140,141],{"class":87},")\n",[35,143,145,148,150,153,156,159,162,164,167,169,172],{"class":37,"line":144},6,[35,146,147],{"class":87},"regions ",[35,149,131],{"class":83},[35,151,152],{"class":87}," [",[35,154,155],{"class":45},"\"East\"",[35,157,158],{"class":87},", ",[35,160,161],{"class":45},"\"North\"",[35,163,158],{"class":87},[35,165,166],{"class":45},"\"South\"",[35,168,158],{"class":87},[35,170,171],{"class":45},"\"West\"",[35,173,174],{"class":87},"]\n",[35,176,178,181,183,186,189,192,195,198,201,204,207,210,214,217,220,223,226,229,232,235,238,241,244,247],{"class":37,"line":177},7,[35,179,180],{"class":87},"sales ",[35,182,131],{"class":83},[35,184,185],{"class":87}," pd.DataFrame({",[35,187,188],{"class":45},"\"Region\"",[35,190,191],{"class":87},": np.repeat(regions, ",[35,193,194],{"class":137},"30",[35,196,197],{"class":87},"), ",[35,199,200],{"class":45},"\"Order\"",[35,202,203],{"class":87},": [",[35,205,206],{"class":83},"f",[35,208,209],{"class":45},"\"SO-",[35,211,213],{"class":212},"sSjpA","{",[35,215,216],{"class":137},"5000",[35,218,219],{"class":83}," +",[35,221,222],{"class":87}," i",[35,224,225],{"class":212},"}",[35,227,228],{"class":45},"\"",[35,230,231],{"class":83}," for",[35,233,234],{"class":87}," i ",[35,236,237],{"class":83},"in",[35,239,240],{"class":137}," range",[35,242,243],{"class":87},"(",[35,245,246],{"class":137},"120",[35,248,249],{"class":87},")],\n",[35,251,253,256,258,260,263,265,268,271,274,277,279,282,284,286,288,290,292,294,297,300,303,306,308,311,313,316,318,321,323,326,329,331],{"class":37,"line":252},8,[35,254,255],{"class":45},"                      \"Customer\"",[35,257,203],{"class":87},[35,259,206],{"class":83},[35,261,262],{"class":45},"\"Customer ",[35,264,213],{"class":212},[35,266,267],{"class":87},"i ",[35,269,270],{"class":83},"%",[35,272,273],{"class":137}," 37",[35,275,276],{"class":83},":02d",[35,278,225],{"class":212},[35,280,281],{"class":45}," Ltd\"",[35,283,231],{"class":83},[35,285,234],{"class":87},[35,287,237],{"class":83},[35,289,240],{"class":137},[35,291,243],{"class":87},[35,293,246],{"class":137},[35,295,296],{"class":87},")], ",[35,298,299],{"class":45},"\"Product\"",[35,301,302],{"class":87},": rng.choice([",[35,304,305],{"class":45},"\"Bolts\"",[35,307,158],{"class":87},[35,309,310],{"class":45},"\"Nuts\"",[35,312,158],{"class":87},[35,314,315],{"class":45},"\"Washers\"",[35,317,158],{"class":87},[35,319,320],{"class":45},"\"Rivets\"",[35,322,158],{"class":87},[35,324,325],{"class":45},"\"Brackets\"",[35,327,328],{"class":87},"], ",[35,330,246],{"class":137},[35,332,333],{"class":87},"),\n",[35,335,337,340,343,346,348,351,353,355,357,360,363,366,368,371,373,375,378,381],{"class":37,"line":336},9,[35,338,339],{"class":45},"                      \"Qty\"",[35,341,342],{"class":87},": rng.integers(",[35,344,345],{"class":137},"5",[35,347,158],{"class":87},[35,349,350],{"class":137},"400",[35,352,158],{"class":87},[35,354,246],{"class":137},[35,356,197],{"class":87},[35,358,359],{"class":45},"\"Unit price\"",[35,361,362],{"class":87},": rng.uniform(",[35,364,365],{"class":137},"0.05",[35,367,158],{"class":87},[35,369,370],{"class":137},"9",[35,372,158],{"class":87},[35,374,246],{"class":137},[35,376,377],{"class":87},").round(",[35,379,380],{"class":137},"2",[35,382,333],{"class":87},[35,384,386,389,391,394,396,398,400,403,405,407,409,412,414,417,419,422,424,427,429,431],{"class":37,"line":385},10,[35,387,388],{"class":45},"                      \"Discount\"",[35,390,302],{"class":87},[35,392,393],{"class":137},"0",[35,395,158],{"class":87},[35,397,365],{"class":137},[35,399,158],{"class":87},[35,401,402],{"class":137},"0.1",[35,404,328],{"class":87},[35,406,246],{"class":137},[35,408,197],{"class":87},[35,410,411],{"class":45},"\"Rep\"",[35,413,302],{"class":87},[35,415,416],{"class":45},"\"A. Shah\"",[35,418,158],{"class":87},[35,420,421],{"class":45},"\"B. Lewis\"",[35,423,158],{"class":87},[35,425,426],{"class":45},"\"C. Ortiz\"",[35,428,328],{"class":87},[35,430,246],{"class":137},[35,432,433],{"class":87},")})\n",[35,435,437,440,443,446,448,451,454,456,459,462,464,466,468,471,474,477,479,482,485,487],{"class":37,"line":436},11,[35,438,439],{"class":87},"sales[",[35,441,442],{"class":45},"\"Net\"",[35,444,445],{"class":87},"] ",[35,447,131],{"class":83},[35,449,450],{"class":87}," (sales[",[35,452,453],{"class":45},"\"Qty\"",[35,455,445],{"class":87},[35,457,458],{"class":83},"*",[35,460,461],{"class":87}," sales[",[35,463,359],{"class":45},[35,465,445],{"class":87},[35,467,458],{"class":83},[35,469,470],{"class":87}," (",[35,472,473],{"class":137},"1",[35,475,476],{"class":83}," -",[35,478,461],{"class":87},[35,480,481],{"class":45},"\"Discount\"",[35,483,484],{"class":87},"])).round(",[35,486,380],{"class":137},[35,488,141],{"class":87},[35,490,492],{"class":37,"line":491},12,[35,493,122],{"emptyLinePlaceholder":121},[35,495,497,500,502,505,508],{"class":37,"line":496},13,[35,498,499],{"class":87},"wb ",[35,501,131],{"class":83},[35,503,504],{"class":87}," xlsxwriter.Workbook(",[35,506,507],{"class":45},"\"sales_print.xlsx\"",[35,509,141],{"class":87},[35,511,513,516,518,521,524],{"class":37,"line":512},14,[35,514,515],{"class":87},"ws ",[35,517,131],{"class":83},[35,519,520],{"class":87}," wb.add_worksheet(",[35,522,523],{"class":45},"\"Sales Q3\"",[35,525,141],{"class":87},[35,527,529,532,534,537,540,543,546,548,551,553,556,558,561,563,565],{"class":37,"line":528},15,[35,530,531],{"class":87},"head ",[35,533,131],{"class":83},[35,535,536],{"class":87}," wb.add_format({",[35,538,539],{"class":45},"\"bold\"",[35,541,542],{"class":87},": ",[35,544,545],{"class":137},"True",[35,547,158],{"class":87},[35,549,550],{"class":45},"\"bg_color\"",[35,552,542],{"class":87},[35,554,555],{"class":45},"\"#DDEBF7\"",[35,557,158],{"class":87},[35,559,560],{"class":45},"\"border\"",[35,562,542],{"class":87},[35,564,473],{"class":137},[35,566,567],{"class":87},"})\n",[35,569,571,574,576,578,581,583,586],{"class":37,"line":570},16,[35,572,573],{"class":87},"money ",[35,575,131],{"class":83},[35,577,536],{"class":87},[35,579,580],{"class":45},"\"num_format\"",[35,582,542],{"class":87},[35,584,585],{"class":45},"\"#,##0.00\"",[35,587,567],{"class":87},[35,589,591,594,596,598,600],{"class":37,"line":590},17,[35,592,593],{"class":87},"ws.write_row(",[35,595,393],{"class":137},[35,597,158],{"class":87},[35,599,393],{"class":137},[35,601,602],{"class":87},", sales.columns, head)\n",[35,604,606,609,612,614,617,620,624,626,629,631,634,636,638],{"class":37,"line":605},18,[35,607,608],{"class":83},"for",[35,610,611],{"class":87}," r, row ",[35,613,237],{"class":83},[35,615,616],{"class":137}," enumerate",[35,618,619],{"class":87},"(sales.itertuples(",[35,621,623],{"class":622},"sa561","index",[35,625,131],{"class":83},[35,627,628],{"class":137},"False",[35,630,197],{"class":87},[35,632,633],{"class":622},"start",[35,635,131],{"class":83},[35,637,473],{"class":137},[35,639,640],{"class":87},"):\n",[35,642,644,647,649],{"class":37,"line":643},19,[35,645,646],{"class":87},"    ws.write_row(r, ",[35,648,393],{"class":137},[35,650,651],{"class":87},", row)\n",[35,653,655,658,661],{"class":37,"line":654},20,[35,656,657],{"class":87},"    ws.write_number(r, ",[35,659,660],{"class":137},"8",[35,662,663],{"class":87},", row.Net, money)\n",[35,665,667,670,673,675,677],{"class":37,"line":666},21,[35,668,669],{"class":87},"ws.set_column(",[35,671,672],{"class":45},"\"A:B\"",[35,674,158],{"class":87},[35,676,370],{"class":137},[35,678,141],{"class":87},[35,680,682,684,687,689,692],{"class":37,"line":681},22,[35,683,669],{"class":87},[35,685,686],{"class":45},"\"C:C\"",[35,688,158],{"class":87},[35,690,691],{"class":137},"18",[35,693,141],{"class":87},[35,695,697,699,702,704,707],{"class":37,"line":696},23,[35,698,669],{"class":87},[35,700,701],{"class":45},"\"D:H\"",[35,703,158],{"class":87},[35,705,706],{"class":137},"10",[35,708,141],{"class":87},[35,710,712,714,717,719,722],{"class":37,"line":711},24,[35,713,669],{"class":87},[35,715,716],{"class":45},"\"I:I\"",[35,718,158],{"class":87},[35,720,721],{"class":137},"11",[35,723,141],{"class":87},[35,725,727],{"class":37,"line":726},25,[35,728,122],{"emptyLinePlaceholder":121},[35,730,732],{"class":37,"line":731},26,[35,733,734],{"class":87},"ws.set_landscape()\n",[35,736,738,741,743,746],{"class":37,"line":737},27,[35,739,740],{"class":87},"ws.set_paper(",[35,742,370],{"class":137},[35,744,745],{"class":87},")                      ",[35,747,749],{"class":748},"s-wDw","# 9 = A4; 1 = US Letter\n",[35,751,753,756,758,760,762,765],{"class":37,"line":752},28,[35,754,755],{"class":87},"ws.fit_to_pages(",[35,757,473],{"class":137},[35,759,158],{"class":87},[35,761,393],{"class":137},[35,763,764],{"class":87},")                ",[35,766,767],{"class":748},"# one page wide, as many pages tall as needed\n",[35,769,771,774,776,779],{"class":37,"line":770},29,[35,772,773],{"class":87},"ws.repeat_rows(",[35,775,393],{"class":137},[35,777,778],{"class":87},")                    ",[35,780,781],{"class":748},"# print row 1 at the top of every page\n",[35,783,785,788,790,792,794,796,799,802,804,807,810,813],{"class":37,"line":784},30,[35,786,787],{"class":87},"ws.print_area(",[35,789,393],{"class":137},[35,791,158],{"class":87},[35,793,393],{"class":137},[35,795,158],{"class":87},[35,797,798],{"class":137},"len",[35,800,801],{"class":87},"(sales), ",[35,803,798],{"class":137},[35,805,806],{"class":87},"(sales.columns) ",[35,808,809],{"class":83},"-",[35,811,812],{"class":137}," 1",[35,814,141],{"class":87},[35,816,818,821,824,826,829,831,834,836,838,840,843,845,848,850,853,855,858],{"class":37,"line":817},31,[35,819,820],{"class":87},"ws.set_margins(",[35,822,823],{"class":622},"left",[35,825,131],{"class":83},[35,827,828],{"class":137},"0.5",[35,830,158],{"class":87},[35,832,833],{"class":622},"right",[35,835,131],{"class":83},[35,837,828],{"class":137},[35,839,158],{"class":87},[35,841,842],{"class":622},"top",[35,844,131],{"class":83},[35,846,847],{"class":137},"0.9",[35,849,158],{"class":87},[35,851,852],{"class":622},"bottom",[35,854,131],{"class":83},[35,856,857],{"class":137},"0.8",[35,859,141],{"class":87},[35,861,863],{"class":37,"line":862},32,[35,864,865],{"class":87},"ws.center_horizontally()\n",[10,867,868,871,872,875,876,879,880,882,883,886,887,890,891,18],{},[32,869,870],{},"set_landscape()"," and ",[32,873,874],{},"set_paper(9)"," choose A4 landscape — XlsxWriter's paper codes are Excel's, with 9 for A4 and 1 for US Letter. ",[32,877,878],{},"fit_to_pages(1, 0)"," scales the sheet so all columns fit across one page while letting it run to as many pages down as needed; a ",[32,881,393],{}," for height is what keeps a long table from being squeezed onto a single page. ",[32,884,885],{},"repeat_rows(0)"," prints the header row at the top of every page, which is the single most useful print setting for a long list. The print area limits printing to the data, margins are in inches, and ",[32,888,889],{},"center_horizontally()"," puts the scaled table in the middle of the page rather than against the left margin. Checking the result for cut-off columns is covered in ",[14,892,894],{"href":893},"\u002Fautomating-reporting-workflows\u002Fexporting-excel-reports-to-pdf\u002Fcheck-a-pdf-export-for-cut-off-columns\u002F","Check a PDF Export for Cut-Off Columns",[896,897,905,906,905,910,905,914,905,921,905,931,905,938,905,943,905,948,905,953,905,957,905,961,905,965,905,969,905,972,905,977,905,981,905,985,905,989,905,992,905,995,905,999,905,1003,905,1007,905,1010,905,1015,905,1020],"svg",{"viewBox":898,"role":899,"ariaLabelledBy":900,"xmlns":903,"style":904},"84 0 592 471","img",[901,902],"px-setup-t","px-setup-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:592px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[907,908,909],"title",{"id":901},"What each page setup call controls",[911,912,913],"desc",{"id":902},"Orientation and paper size set the page. Fit to pages sets scaling, one page wide and unlimited pages tall. Repeat rows prints the header on every page. Print area, margins and centring position the table, and headers and footers frame each page.",[915,916],"rect",{"x":917,"y":393,"width":918,"height":919,"fill":920},"84","592","471","#ffffff",[915,922],{"x":923,"y":924,"width":925,"height":926,"rx":927,"fill":928,"stroke":929,"style":930},"100.0","16.0","560.0","59.0","12","#e7ebef","var(--line,#cdd5e6)","stroke-width:2px",[932,933,937],"text",{"x":934,"y":935,"style":936},"380.0","41.5","font-size:13.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","set_landscape, set_paper(9)",[932,939,942],{"x":934,"y":940,"style":941},"61.0","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","A4 landscape",[37,944],{"x1":934,"y1":945,"x2":934,"y2":946,"stroke":947,"style":930},"80.0","102.0","var(--brand,#5b5cf0)",[949,950],"polygon",{"points":951,"fill":952},"380.0,106.0 375.0,97.0 385.0,97.0","#5b5cf0",[915,954],{"x":923,"y":955,"width":925,"height":926,"rx":927,"fill":956,"stroke":947,"style":930},"111.0","#f0f4ff",[932,958,878],{"x":934,"y":959,"style":960},"136.5","font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle",[932,962,964],{"x":934,"y":963,"style":941},"156.0","one page wide, any height",[37,966],{"x1":934,"y1":967,"x2":934,"y2":968,"stroke":947,"style":930},"175.0","197.0",[949,970],{"points":971,"fill":952},"380.0,201.0 375.0,192.0 385.0,192.0",[915,973],{"x":923,"y":974,"width":925,"height":926,"rx":927,"fill":975,"stroke":976,"style":930},"206.0","#d9f4f1","var(--teal,#0f9488)",[932,978,885],{"x":934,"y":979,"style":980},"231.5","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle",[932,982,984],{"x":934,"y":983,"style":941},"251.0","header row on every page",[37,986],{"x1":934,"y1":987,"x2":934,"y2":988,"stroke":947,"style":930},"270.0","292.0",[949,990],{"points":991,"fill":952},"380.0,296.0 375.0,287.0 385.0,287.0",[915,993],{"x":923,"y":994,"width":925,"height":926,"rx":927,"fill":928,"stroke":929,"style":930},"301.0",[932,996,998],{"x":934,"y":997,"style":936},"326.5","print_area, set_margins, center",[932,1000,1002],{"x":934,"y":1001,"style":941},"346.0","position on the page",[37,1004],{"x1":934,"y1":1005,"x2":934,"y2":1006,"stroke":947,"style":930},"365.0","387.0",[949,1008],{"points":1009,"fill":952},"380.0,391.0 375.0,382.0 385.0,382.0",[915,1011],{"x":923,"y":1012,"width":925,"height":926,"rx":927,"fill":1013,"stroke":1014,"style":930},"396.0","#fdefd8","var(--gold,#b4740a)",[932,1016,1019],{"x":934,"y":1017,"style":1018},"421.5","font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","set_header, set_footer",[932,1021,1023],{"x":934,"y":1022,"style":941},"441.0","title, page X of Y, date, logo",[20,1025,1027],{"id":1026},"step-2-page-breaks-between-regions","Step 2 — Page breaks between regions",[10,1029,1030,1031,1034,1035,1038],{},"Each region should start on a new page. ",[32,1032,1033],{},"set_h_pagebreaks()"," takes the rows ",[64,1036,1037],{},"above which"," a break goes:",[25,1040,1042],{"className":74,"code":1041,"language":76,"meta":30,"style":30},"region_starts = sales.index[sales[\"Region\"] != sales[\"Region\"].shift()].tolist()\nbreaks = [i + 1 for i in region_starts[1:]]          # +1 for the header row\nws.set_h_pagebreaks(breaks)\nprint(\"page breaks before rows:\", breaks)\n",[32,1043,1044,1068,1100,1105],{"__ignoreMap":30},[35,1045,1046,1049,1051,1054,1056,1058,1061,1063,1065],{"class":37,"line":38},[35,1047,1048],{"class":87},"region_starts ",[35,1050,131],{"class":83},[35,1052,1053],{"class":87}," sales.index[sales[",[35,1055,188],{"class":45},[35,1057,445],{"class":87},[35,1059,1060],{"class":83},"!=",[35,1062,461],{"class":87},[35,1064,188],{"class":45},[35,1066,1067],{"class":87},"].shift()].tolist()\n",[35,1069,1070,1073,1075,1078,1081,1083,1085,1087,1089,1092,1094,1097],{"class":37,"line":97},[35,1071,1072],{"class":87},"breaks ",[35,1074,131],{"class":83},[35,1076,1077],{"class":87}," [i ",[35,1079,1080],{"class":83},"+",[35,1082,812],{"class":137},[35,1084,231],{"class":83},[35,1086,234],{"class":87},[35,1088,237],{"class":83},[35,1090,1091],{"class":87}," region_starts[",[35,1093,473],{"class":137},[35,1095,1096],{"class":87},":]]          ",[35,1098,1099],{"class":748},"# +1 for the header row\n",[35,1101,1102],{"class":37,"line":110},[35,1103,1104],{"class":87},"ws.set_h_pagebreaks(breaks)\n",[35,1106,1107,1110,1112,1115],{"class":37,"line":118},[35,1108,1109],{"class":137},"print",[35,1111,243],{"class":87},[35,1113,1114],{"class":45},"\"page breaks before rows:\"",[35,1116,1117],{"class":87},", breaks)\n",[10,1119,1120,1121,1124,1125,1127,1128,1131,1132,18],{},"Rows are zero-based and the header occupies row 0, so a region whose first data row is at DataFrame index 30 starts on worksheet row 31. In the LibreOffice export below, the manual breaks combine with ",[32,1122,1123],{},"fit_to_pages",": each region begins a new page and, within a region, pages would break wherever the height runs out. XlsxWriter's documentation warns that in Excel fit-to-page scaling can override manual page breaks, so if your readers print from Excel, confirm the breaks there — or replace ",[32,1126,1123],{}," with a fixed ",[32,1129,1130],{},"set_print_scale"," chosen to fit the width, which leaves manual breaks alone. The same idea with openpyxl is in ",[14,1133,1135],{"href":1134},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Finsert-page-breaks-between-groups-with-openpyxl\u002F","Insert Page Breaks Between Groups with openpyxl",[20,1137,1139],{"id":1138},"step-3-headers-and-footers","Step 3 — Headers and footers",[10,1141,1142,1143,158,1146,871,1149,1152,1153,1156,1157,1160,1161,871,1164,1167,1168,1171,1172,1175,1176,1179],{},"Headers and footers are strings with control codes: ",[32,1144,1145],{},"&L",[32,1147,1148],{},"&C",[32,1150,1151],{},"&R"," start the left, centre and right sections; ",[32,1154,1155],{},"&P"," is the page number, ",[32,1158,1159],{},"&N"," the number of pages, ",[32,1162,1163],{},"&D",[32,1165,1166],{},"&T"," the print date and time, ",[32,1169,1170],{},"&A"," the sheet name and ",[32,1173,1174],{},"&F"," the file name. ",[32,1177,1178],{},"&G"," marks where an image goes:",[25,1181,1183],{"className":74,"code":1182,"language":76,"meta":30,"style":30},"ws.set_header('&L&G&C&\"Calibri,Bold\"&14Sales listing — Q3 2026&R&A',\n              {\"image_left\": \"logo.png\", \"scale_with_doc\": False})\nws.set_footer(\"&LPrinted &D &T&CPage &P of &N&RConfidential — internal use\")\nwb.close()\n",[32,1184,1185,1196,1220,1230],{"__ignoreMap":30},[35,1186,1187,1190,1193],{"class":37,"line":38},[35,1188,1189],{"class":87},"ws.set_header(",[35,1191,1192],{"class":45},"'&L&G&C&\"Calibri,Bold\"&14Sales listing — Q3 2026&R&A'",[35,1194,1195],{"class":87},",\n",[35,1197,1198,1201,1204,1206,1209,1211,1214,1216,1218],{"class":37,"line":97},[35,1199,1200],{"class":87},"              {",[35,1202,1203],{"class":45},"\"image_left\"",[35,1205,542],{"class":87},[35,1207,1208],{"class":45},"\"logo.png\"",[35,1210,158],{"class":87},[35,1212,1213],{"class":45},"\"scale_with_doc\"",[35,1215,542],{"class":87},[35,1217,628],{"class":137},[35,1219,567],{"class":87},[35,1221,1222,1225,1228],{"class":37,"line":110},[35,1223,1224],{"class":87},"ws.set_footer(",[35,1226,1227],{"class":45},"\"&LPrinted &D &T&CPage &P of &N&RConfidential — internal use\"",[35,1229,141],{"class":87},[35,1231,1232],{"class":37,"line":118},[35,1233,1234],{"class":87},"wb.close()\n",[10,1236,1237,1238,871,1241,1244,1245,1248,1249,158,1251,871,1253,1255,1256,1259,1260,18],{},"The header shows the logo on the left, the report title in 14-point bold Calibri in the centre — ",[32,1239,1240],{},"&\"Font,Style\"",[32,1242,1243],{},"&14"," change the font and size for the text that follows — and the sheet name on the right. The footer shows when it was printed, ",[64,1246,1247],{},"Page 3 of 9"," in the centre and a confidentiality note on the right. Because ",[32,1250,1155],{},[32,1252,1159],{},[32,1254,1163],{}," are filled in at print time, they are always correct, whichever pages are printed and whenever. ",[32,1257,1258],{},"scale_with_doc: False"," stops the logo shrinking along with the fit-to-width scaling. Header text is limited to 255 characters including the codes, and a literal ampersand must be written as ",[32,1261,1262],{},"&&",[896,1264,905,1270,905,1273,905,1276,905,1281,905,1287,905,1292,905,1297,905,1300,905,1304,905,1308,905,1314,905,1316,905,1320,905,1322,905,1325,905,1328,905,1332,905,1334,905,1337,905,1339,905,1341,905,1344,905,1348,905,1350,905,1354,905,1356,905,1359,905,1362,905,1366,905,1368,905,1372,905,1374,905,1377,905,1380,905,1384,905,1386,905,1389,905,1391,905,1394,905,1397,905,1401,905,1403,905,1406,905,1408],{"viewBox":1265,"role":899,"ariaLabelledBy":1266,"xmlns":903,"style":1269},"4 0 752 276",[1267,1268],"px-codes-t","px-codes-d","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[907,1271,1272],{"id":1267},"Header and footer codes",[911,1274,1275],{"id":1268},"The codes &L, &C and &R start the left, centre and right sections. &P is the page number and &N the total pages, &D and &T the print date and time, &A the sheet name and &F the file name. &G places an image given in the options. && prints a literal ampersand.",[915,1277],{"x":1278,"y":393,"width":1279,"height":1280,"fill":920},"4","752","276",[915,1282],{"x":1283,"y":924,"width":1284,"height":1285,"rx":393,"fill":920,"stroke":929,"style":1286},"20.0","100.5","40.0","stroke-width:1px",[915,1288],{"x":1289,"y":924,"width":1290,"height":1285,"rx":393,"fill":956,"stroke":947,"style":1291},"120.5","309.8","stroke-width:1.2px",[932,1293,32],{"x":1294,"y":1295,"style":1296},"275.3","41.0","font-size:13px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle",[915,1298],{"x":1299,"y":924,"width":1290,"height":1285,"rx":393,"fill":956,"stroke":947,"style":1291},"430.2",[932,1301,1303],{"x":1302,"y":1295,"style":1296},"585.1","prints",[915,1305],{"x":1283,"y":1306,"width":1284,"height":1307,"rx":393,"fill":928,"stroke":929,"style":1286},"56.0","34.0",[932,1309,1313],{"x":1310,"y":1311,"style":1312},"32.0","78.0","font-size:12.5px;font-weight:700;fill:var(--text,#172033);text-anchor:start","sections",[915,1315],{"x":1289,"y":1306,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1317,1319],{"x":1294,"y":1318,"style":941},"77.0","&L &C &R",[915,1321],{"x":1299,"y":1306,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1323,1324],{"x":1302,"y":1318,"style":941},"left, centre, right",[915,1326],{"x":1283,"y":1327,"width":1284,"height":1307,"rx":393,"fill":928,"stroke":929,"style":1286},"90.0",[932,1329,1331],{"x":1310,"y":1330,"style":1312},"112.0","pages",[915,1333],{"x":1289,"y":1327,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1335,1336],{"x":1294,"y":955,"style":941},"&P of &N",[915,1338],{"x":1299,"y":1327,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1340,1247],{"x":1302,"y":955,"style":941},[915,1342],{"x":1283,"y":1343,"width":1284,"height":1307,"rx":393,"fill":928,"stroke":929,"style":1286},"124.0",[932,1345,1347],{"x":1310,"y":1346,"style":1312},"146.0","date, time",[915,1349],{"x":1289,"y":1343,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1351,1353],{"x":1294,"y":1352,"style":941},"145.0","&D &T",[915,1355],{"x":1299,"y":1343,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1357,1358],{"x":1302,"y":1352,"style":941},"print date and time",[915,1360],{"x":1283,"y":1361,"width":1284,"height":1307,"rx":393,"fill":928,"stroke":929,"style":1286},"158.0",[932,1363,1365],{"x":1310,"y":1364,"style":1312},"180.0","names",[915,1367],{"x":1289,"y":1361,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1369,1371],{"x":1294,"y":1370,"style":941},"179.0","&A, &F",[915,1373],{"x":1299,"y":1361,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1375,1376],{"x":1302,"y":1370,"style":941},"sheet, file name",[915,1378],{"x":1283,"y":1379,"width":1284,"height":1307,"rx":393,"fill":928,"stroke":929,"style":1286},"192.0",[932,1381,1383],{"x":1310,"y":1382,"style":1312},"214.0","image",[915,1385],{"x":1289,"y":1379,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1387,1178],{"x":1294,"y":1388,"style":941},"213.0",[915,1390],{"x":1299,"y":1379,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1392,1393],{"x":1302,"y":1388,"style":941},"logo from options",[915,1395],{"x":1283,"y":1396,"width":1284,"height":1307,"rx":393,"fill":928,"stroke":929,"style":1286},"226.0",[932,1398,1400],{"x":1310,"y":1399,"style":1312},"248.0","ampersand",[915,1402],{"x":1289,"y":1396,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1404,1262],{"x":1294,"y":1405,"style":941},"247.0",[915,1407],{"x":1299,"y":1396,"width":1290,"height":1307,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1409,1410],{"x":1302,"y":1405,"style":941},"&",[20,1412,1414],{"id":1413},"step-4-check-the-printed-pages","Step 4 — Check the printed pages",[10,1416,1417],{},"Export to PDF and read each page's first and last lines:",[25,1419,1421],{"className":74,"code":1420,"language":76,"meta":30,"style":30},"import subprocess\nimport pdfplumber\n\nsubprocess.run([\"soffice\", \"--headless\", \"--convert-to\", \"pdf\", \"--outdir\", \"pdf\", \"sales_print.xlsx\"], check=True, capture_output=True)\nwith pdfplumber.open(\"pdf\u002Fsales_print.pdf\") as pdf:\n    print(\"pages:\", len(pdf.pages), \"| size (pt):\", round(pdf.pages[0].width), \"x\", round(pdf.pages[0].height))\n    for n, page in enumerate(pdf.pages, start=1):\n        lines = page.extract_text().splitlines()\n        first_data = next(l for l in lines if l.startswith(tuple(regions)))\n        print(f\"{n}: {lines[0][:34]:\u003C36} | {first_data.split()[0]:\u003C5} | {lines[-1][:44]}\")\n",[32,1422,1423,1430,1436,1440,1496,1515,1562,1585,1595,1630],{"__ignoreMap":30},[35,1424,1425,1427],{"class":37,"line":38},[35,1426,84],{"class":83},[35,1428,1429],{"class":87}," subprocess\n",[35,1431,1432,1434],{"class":37,"line":97},[35,1433,84],{"class":83},[35,1435,55],{"class":87},[35,1437,1438],{"class":37,"line":110},[35,1439,122],{"emptyLinePlaceholder":121},[35,1441,1442,1445,1448,1450,1453,1455,1458,1460,1463,1465,1468,1470,1472,1474,1476,1478,1481,1483,1485,1487,1490,1492,1494],{"class":37,"line":118},[35,1443,1444],{"class":87},"subprocess.run([",[35,1446,1447],{"class":45},"\"soffice\"",[35,1449,158],{"class":87},[35,1451,1452],{"class":45},"\"--headless\"",[35,1454,158],{"class":87},[35,1456,1457],{"class":45},"\"--convert-to\"",[35,1459,158],{"class":87},[35,1461,1462],{"class":45},"\"pdf\"",[35,1464,158],{"class":87},[35,1466,1467],{"class":45},"\"--outdir\"",[35,1469,158],{"class":87},[35,1471,1462],{"class":45},[35,1473,158],{"class":87},[35,1475,507],{"class":45},[35,1477,328],{"class":87},[35,1479,1480],{"class":622},"check",[35,1482,131],{"class":83},[35,1484,545],{"class":137},[35,1486,158],{"class":87},[35,1488,1489],{"class":622},"capture_output",[35,1491,131],{"class":83},[35,1493,545],{"class":137},[35,1495,141],{"class":87},[35,1497,1498,1501,1504,1507,1510,1512],{"class":37,"line":125},[35,1499,1500],{"class":83},"with",[35,1502,1503],{"class":87}," pdfplumber.open(",[35,1505,1506],{"class":45},"\"pdf\u002Fsales_print.pdf\"",[35,1508,1509],{"class":87},") ",[35,1511,91],{"class":83},[35,1513,1514],{"class":87}," pdf:\n",[35,1516,1517,1520,1522,1525,1527,1529,1532,1535,1537,1540,1543,1545,1548,1551,1553,1555,1557,1559],{"class":37,"line":144},[35,1518,1519],{"class":137},"    print",[35,1521,243],{"class":87},[35,1523,1524],{"class":45},"\"pages:\"",[35,1526,158],{"class":87},[35,1528,798],{"class":137},[35,1530,1531],{"class":87},"(pdf.pages), ",[35,1533,1534],{"class":45},"\"| size (pt):\"",[35,1536,158],{"class":87},[35,1538,1539],{"class":137},"round",[35,1541,1542],{"class":87},"(pdf.pages[",[35,1544,393],{"class":137},[35,1546,1547],{"class":87},"].width), ",[35,1549,1550],{"class":45},"\"x\"",[35,1552,158],{"class":87},[35,1554,1539],{"class":137},[35,1556,1542],{"class":87},[35,1558,393],{"class":137},[35,1560,1561],{"class":87},"].height))\n",[35,1563,1564,1567,1570,1572,1574,1577,1579,1581,1583],{"class":37,"line":177},[35,1565,1566],{"class":83},"    for",[35,1568,1569],{"class":87}," n, page ",[35,1571,237],{"class":83},[35,1573,616],{"class":137},[35,1575,1576],{"class":87},"(pdf.pages, ",[35,1578,633],{"class":622},[35,1580,131],{"class":83},[35,1582,473],{"class":137},[35,1584,640],{"class":87},[35,1586,1587,1590,1592],{"class":37,"line":252},[35,1588,1589],{"class":87},"        lines ",[35,1591,131],{"class":83},[35,1593,1594],{"class":87}," page.extract_text().splitlines()\n",[35,1596,1597,1600,1602,1605,1608,1610,1613,1615,1618,1621,1624,1627],{"class":37,"line":336},[35,1598,1599],{"class":87},"        first_data ",[35,1601,131],{"class":83},[35,1603,1604],{"class":137}," next",[35,1606,1607],{"class":87},"(l ",[35,1609,608],{"class":83},[35,1611,1612],{"class":87}," l ",[35,1614,237],{"class":83},[35,1616,1617],{"class":87}," lines ",[35,1619,1620],{"class":83},"if",[35,1622,1623],{"class":87}," l.startswith(",[35,1625,1626],{"class":137},"tuple",[35,1628,1629],{"class":87},"(regions)))\n",[35,1631,1632,1635,1637,1639,1641,1643,1646,1648,1650,1652,1655,1657,1660,1663,1666,1669,1671,1674,1676,1679,1681,1683,1686,1688,1690,1692,1694,1696,1698,1700,1703,1705,1707,1709],{"class":37,"line":385},[35,1633,1634],{"class":137},"        print",[35,1636,243],{"class":87},[35,1638,206],{"class":83},[35,1640,228],{"class":45},[35,1642,213],{"class":212},[35,1644,1645],{"class":87},"n",[35,1647,225],{"class":212},[35,1649,542],{"class":45},[35,1651,213],{"class":212},[35,1653,1654],{"class":87},"lines[",[35,1656,393],{"class":137},[35,1658,1659],{"class":87},"][:",[35,1661,1662],{"class":137},"34",[35,1664,1665],{"class":87},"]",[35,1667,1668],{"class":83},":\u003C36",[35,1670,225],{"class":212},[35,1672,1673],{"class":45}," | ",[35,1675,213],{"class":212},[35,1677,1678],{"class":87},"first_data.split()[",[35,1680,393],{"class":137},[35,1682,1665],{"class":87},[35,1684,1685],{"class":83},":\u003C5",[35,1687,225],{"class":212},[35,1689,1673],{"class":45},[35,1691,213],{"class":212},[35,1693,1654],{"class":87},[35,1695,809],{"class":83},[35,1697,473],{"class":137},[35,1699,1659],{"class":87},[35,1701,1702],{"class":137},"44",[35,1704,1665],{"class":87},[35,1706,225],{"class":212},[35,1708,228],{"class":45},[35,1710,141],{"class":87},[10,1712,1713,1714,1717,1718,18],{},"The PDF has four A4 landscape pages (842 × 595 points), one per region: each of the 30-line regions fits on a single page once the sheet is scaled to the page width, and the manual breaks start East, North, South and West on pages 1 to 4. Every page starts with the header line — title and sheet name — then the repeated column headings, and every footer reads ",[64,1715,1716],{},"Page n of 4"," with the date and time of the export. If something is wrong, it is wrong here, before the report reaches a printer or a client. Exporting reports to PDF as part of a job is covered in ",[14,1719,1721],{"href":1720},"\u002Fautomating-reporting-workflows\u002Fexporting-excel-reports-to-pdf\u002Fconvert-excel-file-to-pdf-with-python\u002F","Convert an Excel File to PDF with Python",[896,1723,905,1729,905,1732,905,1735,905,1740,905,1744,905,1748,905,1754,905,1758,905,1762,905,1766,905,1770,905,1773,905,1776,905,1779,905,1783,905,1785,905,1788,905,1790,905,1793,905,1796,905,1799,905,1801,905,1805,905,1807,905,1810,905,1812,905,1815,905,1818,905,1821,905,1823,905,1827,905,1829,905,1832,905,1834,905,1836,905,1838,905,1841,905,1843,905,1846,905,1848,905,1850,905,1852,905,1854,905,1857,905,1860,905,1862,905,1866,905,1868,905,1871,905,1873],{"viewBox":1724,"role":899,"ariaLabelledBy":1725,"xmlns":903,"style":1728},"107 0 546 196",[1726,1727],"px-page-t","px-page-d","width:100%;max-width:546px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[907,1730,1731],{"id":1726},"One printed page",[911,1733,1734],{"id":1727},"The header has the logo on the left, the report title in the centre and the sheet name on the right. Below it the repeated column headings and one region's rows, scaled to the page width. The footer has the print date on the left, Page 2 of 4 in the centre and a confidentiality note on the right.",[915,1736],{"x":1737,"y":393,"width":1738,"height":1739,"fill":920},"107","546","196",[915,1741],{"x":1742,"y":924,"width":1310,"height":1743,"rx":393,"fill":928,"stroke":929,"style":1286},"123.2","24.0",[915,1745],{"x":1746,"y":924,"width":1747,"height":1743,"rx":393,"fill":928,"stroke":929,"style":1286},"155.2","174.8",[932,1749,1753],{"x":1750,"y":1751,"style":1752},"242.6","33.0","font-size:11px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","A",[915,1755],{"x":1756,"y":924,"width":1757,"height":1743,"rx":393,"fill":928,"stroke":929,"style":1286},"330.1","170.3",[932,1759,1761],{"x":1760,"y":1751,"style":1752},"415.2","B",[915,1763],{"x":1764,"y":924,"width":1765,"height":1743,"rx":393,"fill":928,"stroke":929,"style":1286},"500.4","136.4",[932,1767,1769],{"x":1768,"y":1751,"style":1752},"568.6","C",[915,1771],{"x":1742,"y":1285,"width":1310,"height":1772,"rx":393,"fill":928,"stroke":929,"style":1286},"28.0",[932,1774,473],{"x":1775,"y":926,"style":1752},"139.2",[915,1777],{"x":1746,"y":1285,"width":1747,"height":1772,"rx":393,"fill":956,"stroke":947,"style":1778},"stroke-width:1.5px",[932,1780,1782],{"x":1750,"y":926,"style":1781},"font-size:12px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","[logo]",[915,1784],{"x":1756,"y":1285,"width":1757,"height":1772,"rx":393,"fill":956,"stroke":947,"style":1778},[932,1786,1787],{"x":1760,"y":926,"style":1781},"Sales listing — Q3 2026",[915,1789],{"x":1764,"y":1285,"width":1765,"height":1772,"rx":393,"fill":956,"stroke":947,"style":1778},[932,1791,1792],{"x":1768,"y":926,"style":1781},"Sales Q3",[915,1794],{"x":1742,"y":1795,"width":1310,"height":1772,"rx":393,"fill":928,"stroke":929,"style":1286},"68.0",[932,1797,380],{"x":1775,"y":1798,"style":1752},"87.0",[915,1800],{"x":1746,"y":1795,"width":1747,"height":1772,"rx":393,"fill":975,"stroke":976,"style":1778},[932,1802,1804],{"x":1750,"y":1798,"style":1803},"font-size:12px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Region  Order  Customer",[915,1806],{"x":1756,"y":1795,"width":1757,"height":1772,"rx":393,"fill":975,"stroke":976,"style":1778},[932,1808,1809],{"x":1760,"y":1798,"style":1803},"Product  Qty  Unit price",[915,1811],{"x":1764,"y":1795,"width":1765,"height":1772,"rx":393,"fill":975,"stroke":976,"style":1778},[932,1813,1814],{"x":1768,"y":1798,"style":1803},"Discount  Rep  Net",[915,1816],{"x":1742,"y":1817,"width":1310,"height":1772,"rx":393,"fill":928,"stroke":929,"style":1286},"96.0",[932,1819,138],{"x":1775,"y":1820,"style":1752},"115.0",[915,1822],{"x":1746,"y":1817,"width":1747,"height":1772,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1824,1826],{"x":1750,"y":1820,"style":1825},"font-size:12px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","North  SO-5030 …",[915,1828],{"x":1756,"y":1817,"width":1757,"height":1772,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1830,1831],{"x":1760,"y":1820,"style":1825},"…",[915,1833],{"x":1764,"y":1817,"width":1765,"height":1772,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1835,1831],{"x":1768,"y":1820,"style":1825},[915,1837],{"x":1742,"y":1343,"width":1310,"height":1772,"rx":393,"fill":928,"stroke":929,"style":1286},[932,1839,1278],{"x":1775,"y":1840,"style":1752},"143.0",[915,1842],{"x":1746,"y":1343,"width":1747,"height":1772,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1844,1845],{"x":1750,"y":1840,"style":1825},"North  SO-5059 …",[915,1847],{"x":1756,"y":1343,"width":1757,"height":1772,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1849,1831],{"x":1760,"y":1840,"style":1825},[915,1851],{"x":1764,"y":1343,"width":1765,"height":1772,"rx":393,"fill":920,"stroke":929,"style":1286},[932,1853,1831],{"x":1768,"y":1840,"style":1825},[915,1855],{"x":1742,"y":1856,"width":1310,"height":1772,"rx":393,"fill":928,"stroke":929,"style":1286},"152.0",[932,1858,345],{"x":1775,"y":1859,"style":1752},"171.0",[915,1861],{"x":1746,"y":1856,"width":1747,"height":1772,"rx":393,"fill":1013,"stroke":1014,"style":1778},[932,1863,1865],{"x":1750,"y":1859,"style":1864},"font-size:12px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","Printed 02\u002F10\u002F2026",[915,1867],{"x":1756,"y":1856,"width":1757,"height":1772,"rx":393,"fill":1013,"stroke":1014,"style":1778},[932,1869,1870],{"x":1760,"y":1859,"style":1864},"Page 2 of 4",[915,1872],{"x":1764,"y":1856,"width":1765,"height":1772,"rx":393,"fill":1013,"stroke":1014,"style":1778},[932,1874,1875],{"x":1768,"y":1859,"style":1864},"Confidential",[20,1877,1879],{"id":1878},"other-print-settings-worth-knowing","Other print settings worth knowing",[10,1881,1882,1883,1886,1887,1889,1890,1893,1894,1897,1898,1901,1902,1905],{},"A few more methods round out page setup. ",[32,1884,1885],{},"hide_gridlines(0)"," ",[64,1888,1303],{}," the gridlines, which helps on dense numeric listings that have no borders of their own; by default Excel shows them on screen and leaves them off paper. ",[32,1891,1892],{},"print_row_col_headers()"," prints the A, B, C column letters and row numbers, useful for review copies where people will refer to cells. ",[32,1895,1896],{},"set_print_scale(85)"," sets a fixed zoom instead of fitting to pages — the two are alternatives, and when fit-to-pages is set the print scale is ignored. ",[32,1899,1900],{},"set_start_page(5)"," makes page numbering start at 5 when the sheet is one section of a larger printed pack, and ",[32,1903,1904],{},"print_across()"," prints across then down for sheets that are both wider and taller than a page. A workbook with several sheets needs these calls on each worksheet, so put the setup in one function and apply it to every sheet the report writes, so all of them print consistently.",[20,1907,1909],{"id":1908},"common-pitfalls","Common pitfalls",[1911,1912,1913,1927,1935,1944,1952],"ul",{},[1914,1915,1916,1923,1924,18],"li",{},[1917,1918,1919,1922],"strong",{},[32,1920,1921],{},"fit_to_pages(1, 1)"," on long lists."," It shrinks everything onto one page; use ",[32,1925,1926],{},"(1, 0)",[1914,1928,1929,1932,1933,18],{},[1917,1930,1931],{},"Header row only on page one."," Call ",[32,1934,885],{},[1914,1936,1937,1940,1941,1943],{},[1917,1938,1939],{},"Page break off by one."," Breaks are zero-based rows ",[64,1942,1037],{}," the break falls; count the header.",[1914,1945,1946,1949,1950,18],{},[1917,1947,1948],{},"Literal ampersands in headers."," Write ",[32,1951,1262],{},[1914,1953,1954,1957,1958,1961,1962,18],{},[1917,1955,1956],{},"Logos shrinking with the sheet."," Set ",[32,1959,1960],{},"scale_with_doc"," to ",[32,1963,628],{},[20,1965,1967],{"id":1966},"conclusion","Conclusion",[10,1969,1970,1971,871,1973,1976,1977,1979,1980,1982,1983,1986,1987,1989,1990,158,1992,158,1994,158,1996,1998],{},"Set up printing when the report is written: ",[32,1972,870],{},[32,1974,1975],{},"set_paper()"," for the page, ",[32,1978,878],{}," for one page wide, ",[32,1981,885],{}," for headings on every page, ",[32,1984,1985],{},"print_area()",", margins and centring for position, and ",[32,1988,1033],{}," to start groups on new pages. Build headers and footers from codes — ",[32,1991,1336],{},[32,1993,1163],{},[32,1995,1170],{},[32,1997,1178],{}," with an image — and check the result by exporting to PDF and reading each page.",[20,2000,2002],{"id":2001},"frequently-asked-questions","Frequently asked questions",[10,2004,2005,2008],{},[1917,2006,2007],{},"How do I repeat the header row on every printed page with XlsxWriter?","\nCall worksheet.repeat_rows(0) for the first row, or repeat_rows(first, last) for several header rows.",[10,2010,2011,2014],{},[1917,2012,2013],{},"How do I fit all columns on one page width in XlsxWriter?","\nCall worksheet.fit_to_pages(1, 0): one page wide and as many pages tall as needed.",[10,2016,2017,2020],{},[1917,2018,2019],{},"How do I add page X of Y to an Excel footer with Python?","\nUse worksheet.set_footer(\"&CPage &P of &N\"); &P and &N are replaced with the page number and page count when printing.",[10,2022,2023,2026],{},[1917,2024,2025],{},"How do I put a logo in an Excel header with XlsxWriter?","\nInclude &G in the header string where the image should go and pass image_left, image_center or image_right with the image path in the options.",[20,2028,2030],{"id":2029},"related","Related",[1911,2032,2033,2039,2046,2053],{},[1914,2034,2035,2036,2038],{},"Up one level: ",[14,2037,17],{"href":16}," — reports with XlsxWriter.",[1914,2040,2041,2045],{},[14,2042,2044],{"href":2043},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fset-print-area-and-page-setup-with-openpyxl\u002F","Set the Print Area and Page Setup with openpyxl"," — the openpyxl equivalent.",[1914,2047,2048,2052],{},[14,2049,2051],{"href":2050},"\u002Fautomating-reporting-workflows\u002Fexporting-excel-reports-to-pdf\u002Fadd-headers-footers-and-page-numbers-to-an-excel-pdf\u002F","Add Headers, Footers and Page Numbers to an Excel PDF"," — headers for PDF exports.",[1914,2054,2055,2059],{},[14,2056,2058],{"href":2057},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fwrite-a-formatted-excel-report-with-xlsxwriter\u002F","Write a Formatted Excel Report with xlsxwriter"," — the rest of the report.",[2061,2062,2063],"style",{},"html pre.shiki code .sMTad, html code.shiki .sMTad{--shiki-default:#6F42C1;--shiki-dark:#FFB757}html pre.shiki code .srMev, html code.shiki .srMev{--shiki-default:#032F62;--shiki-dark:#ADDCFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s-kum, html code.shiki .s-kum{--shiki-default:#D73A49;--shiki-dark:#FF9492}html pre.shiki code .skGVy, html code.shiki .skGVy{--shiki-default:#24292E;--shiki-dark:#F0F3F6}html pre.shiki code .sP0c6, html code.shiki .sP0c6{--shiki-default:#005CC5;--shiki-dark:#91CBFF}html pre.shiki code .sSjpA, html code.shiki .sSjpA{--shiki-default:#005CC5;--shiki-dark:#FF9492}html pre.shiki code .sa561, html code.shiki .sa561{--shiki-default:#E36209;--shiki-dark:#FFB757}html pre.shiki code .s-wDw, html code.shiki .s-wDw{--shiki-default:#6A737D;--shiki-dark:#BDC4CC}",{"title":30,"searchDepth":97,"depth":97,"links":2065},[2066,2067,2068,2069,2070,2071,2072,2073,2074,2075],{"id":22,"depth":97,"text":23},{"id":70,"depth":97,"text":71},{"id":1026,"depth":97,"text":1027},{"id":1138,"depth":97,"text":1139},{"id":1413,"depth":97,"text":1414},{"id":1878,"depth":97,"text":1879},{"id":1908,"depth":97,"text":1909},{"id":1966,"depth":97,"text":1967},{"id":2001,"depth":97,"text":2002},{"id":2029,"depth":97,"text":2030},"2026-10-02","Make an XlsxWriter report print properly: landscape A4, fit to one page wide, repeat the header row on every page, set the print area and margins, add page breaks between groups, and write headers and footers with the report name, page X of Y, the print date and a logo — then check the printed result by exporting it to PDF.","md",[2080,2082,2084,2086],{"q":2007,"a":2081},"Call worksheet.repeat_rows(0) for the first row, or repeat_rows(first, last) for several header rows.",{"q":2013,"a":2083},"Call worksheet.fit_to_pages(1, 0): one page wide and as many pages tall as needed.",{"q":2019,"a":2085},"Use worksheet.set_footer(\"&CPage &P of &N\"); &P and &N are replaced with the page number and page count when printing.",{"q":2025,"a":2087},"Include &G in the header string where the image should go and pass image_left, image_center or image_right with the image path in the options.","print options headers and footers with xlsxwriter",null,{"breadcrumb":2091},[2092,2095,2098],{"name":2093,"item":2094},"Home","\u002F",{"name":2096,"item":2097},"Formatting and Charting Excel Reports with Python","\u002Fformatting-and-charting-excel-reports-with-python\u002F",{"name":17,"item":16},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter",{"title":5,"description":2101},"XlsxWriter page setup for printable reports: set_landscape, set_paper, fit_to_pages, repeat_rows, print_area, margins, page breaks, and header\u002Ffooter codes &P, &N, &D, &A and &G for logos, verified via PDF.","set-print-options-headers-and-footers-with-xlsxwriter","formatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fset-print-options-headers-and-footers-with-xlsxwriter\u002Findex",[2105,2106],"xlsxwriter","report-layouts","how-to","wotUVFsJIqeN_woD9-Ik5bdaE9GMdh-xJ4YcdPvt-d8",[2110,2114],{"title":2111,"path":2112,"stem":2113,"children":-1},"Label Chart Points from Cell Values with XlsxWriter","\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Flabel-chart-points-from-cell-values-with-xlsxwriter","formatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Flabel-chart-points-from-cell-values-with-xlsxwriter\u002Findex",{"title":2115,"path":2116,"stem":2117,"children":-1},"Store Formula Results with xlsxwriter So Every Viewer Shows Values","\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fstore-formula-results-with-xlsxwriter","formatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fstore-formula-results-with-xlsxwriter\u002Findex",[2119,2121],{"path":2120,"title":17},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter",{"path":2122,"title":2096},"\u002Fformatting-and-charting-excel-reports-with-python",[],[2125,2129,2132,2135,2138,2141],{"path":2126,"title":2127,"kind":2128},"\u002Fautomating-reporting-workflows\u002Fbuilding-finance-and-operations-reports\u002Fbuild-a-budget-vs-actual-variance-report","Build a Budget vs Actual Variance Report in Excel with Python","compare",{"path":2130,"title":2131,"kind":2107},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fcombine-chart-types-and-chartsheets-with-xlsxwriter","Combine Chart Types and Chartsheets with XlsxWriter",{"path":2133,"title":2134,"kind":2107},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fdefine-names-and-protect-sheets-with-xlsxwriter","Define Names and Protect Sheets with XlsxWriter",{"path":2136,"title":2137,"kind":2107},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Ffreeze-panes-and-set-zoom-with-xlsxwriter","Freeze Panes and Set Zoom with XlsxWriter",{"path":2139,"title":2140,"kind":2107},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Finsert-checkboxes-with-xlsxwriter","Insert Checkboxes in Excel with xlsxwriter",{"path":2142,"title":2143,"kind":2107},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fwrite-an-excel-table-with-formula-columns-using-xlsxwriter","Write an Excel Table with Formula Columns Using XlsxWriter",1790972108647]