[{"data":1,"prerenderedAt":1823},["ShallowReactive",2],{"doc:\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl":3,"surround:\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl":1790,"ancestors:\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl":1798,"children:\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl":1803,"related:\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl":1804},{"id":4,"title":5,"body":6,"dateModified":1755,"datePublished":1755,"description":1756,"extension":1757,"faq":1758,"keyword":1768,"kind":1769,"meta":1770,"navigation":250,"path":1779,"seo":1780,"slug":1783,"stem":1784,"topics":1785,"type":1788,"__hash__":1789},"docs\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl\u002Findex.md","Hide Gridlines and Set the Zoom Level with openpyxl",{"type":7,"value":8,"toc":1741},"minimark",[9,33,38,63,89,207,211,222,318,328,332,338,388,401,536,540,543,657,690,694,697,773,810,814,820,854,871,968,1181,1192,1196,1203,1422,1429,1433,1440,1580,1594,1598,1652,1656,1672,1676,1682,1688,1698,1704,1708,1737],[10,11,12,13,17,18,22,23,26,27,32],"p",{},"The first seconds after someone opens a report decide whether it looks designed or dumped. Grid lines everywhere, a zoom level that shows three columns, the cursor sitting in some random cell halfway down the data, or — worse — the title bar saying ",[14,15,16],"code",{},"[Group]"," because two sheets were left selected: none of these change the numbers, but all of them make the file feel unfinished. They are all ",[19,20,21],"em",{},"sheet view"," settings, stored per worksheet, and openpyxl exposes them through ",[14,24,25],{},"ws.sheet_view",". This page, part of ",[28,29,31],"a",{"href":30},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002F","Styling Excel Cells with openpyxl",", covers each one and the trap that catches most scripts.",[34,35,37],"h2",{"id":36},"prerequisites","Prerequisites",[39,40,45],"pre",{"className":41,"code":42,"language":43,"meta":44,"style":44},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install openpyxl\n","bash","",[14,46,47],{"__ignoreMap":44},[48,49,52,56,60],"span",{"class":50,"line":51},"line",1,[48,53,55],{"class":54},"sMTad","pip",[48,57,59],{"class":58},"srMev"," install",[48,61,62],{"class":58}," openpyxl\n",[10,64,65,68,69,72,73,76,77,80,81,84,85,88],{},[14,66,67],{},"regional.xlsx"," has a ",[14,70,71],{},"Summary"," sheet laid out as a small report — a title in ",[14,74,75],{},"B2"," and a table starting in ",[14,78,79],{},"B4"," — and a ",[14,82,83],{},"Data"," sheet with 200 rows. Like every file Excel itself saves, its active sheet carries a ",[14,86,87],{},"tabSelected"," flag, which matters in Step 5.",[90,91,99,100,99,104,99,108,99,116,99,126,99,137,99,144,99,149,99,154,99,159,99,163,99,170,99,175,99,179,99,183,99,186,99,191,99,198,99,203],"svg",{"viewBox":92,"role":93,"ariaLabelledBy":94,"xmlns":97,"style":98},"64 0 632 383","img",[95,96],"sv-where-t","sv-where-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:632px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[101,102,103],"title",{"id":95},"Where the view settings live",[105,106,107],"desc",{"id":96},"A workbook contains worksheets, each worksheet has a sheet view holding gridlines, zoom, view mode and zeros, and the sheet view holds a selection with the active cell.",[109,110],"rect",{"x":111,"y":112,"width":113,"height":114,"fill":115},"64","0","632","383","#ffffff",[109,117],{"x":118,"y":119,"width":120,"height":121,"rx":122,"fill":123,"stroke":124,"style":125},"80.0","16.0","600.0","93.0","12","#e7ebef","var(--line,#cdd5e6)","stroke-width:2px",[127,128,130],"g",{"transform":129},"translate(368.0,29.0) scale(1.000)",[131,132],"path",{"d":133,"fill":134,"stroke":135,"style":136},"M6 3h9l4 4v14H6z M15 3v4h4 M9.5 11.5l4.5 6 M14 11.5l-4.5 6","none","var(--text,#172033)","stroke-width:1.80px;stroke-linecap:round;stroke-linejoin:round",[138,139,143],"text",{"x":140,"y":141,"style":142},"380.0","75.5","font-size:13.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","Workbook",[138,145,148],{"x":140,"y":146,"style":147},"95.0","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","wb.active — which sheet opens first",[50,150],{"x1":140,"y1":151,"x2":140,"y2":152,"stroke":153,"style":125},"114.0","136.0","var(--brand,#5b5cf0)",[155,156],"polygon",{"points":157,"fill":158},"380.0,140.0 375.0,131.0 385.0,131.0","#5b5cf0",[109,160],{"x":118,"y":161,"width":120,"height":121,"rx":122,"fill":162,"stroke":153,"style":125},"145.0","#f0f4ff",[127,164,166],{"transform":165},"translate(368.0,158.0) scale(1.000)",[131,167],{"d":168,"fill":134,"stroke":169,"style":136},"M4 4h16v16H4z M4 9h16 M4 14h16 M10 4v16","var(--brand-strong,#4338ca)",[138,171,174],{"x":140,"y":172,"style":173},"204.5","font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Worksheet sheet_view",[138,176,178],{"x":140,"y":177,"style":147},"224.0","showGridLines, zoomScale, view, showZeros, tabSelected",[50,180],{"x1":140,"y1":181,"x2":140,"y2":182,"stroke":153,"style":125},"243.0","265.0",[155,184],{"points":185,"fill":158},"380.0,269.0 375.0,260.0 385.0,260.0",[109,187],{"x":118,"y":188,"width":120,"height":121,"rx":122,"fill":189,"stroke":190,"style":125},"274.0","#d9f4f1","var(--teal,#0f9488)",[127,192,194],{"transform":193},"translate(368.0,287.0) scale(1.000)",[131,195],{"d":196,"fill":134,"stroke":197,"style":136},"M11 4a7 7 0 1 0 .01 0z M16 16l5 5","var(--teal-ink,#0b6157)",[138,199,202],{"x":140,"y":200,"style":201},"333.5","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Pane and selection",[138,204,206],{"x":140,"y":205,"style":147},"353.0","topLeftCell, activeCell, sqref",[34,208,210],{"id":209},"step-1-hide-gridlines-and-headings","Step 1 — Hide gridlines and headings",[10,212,213,214,217,218,221],{},"Gridlines are the faint lines around every cell. A report that draws its own borders looks cleaner without them. Row and column headings — the ",[14,215,216],{},"A B C"," and ",[14,219,220],{},"1 2 3"," — can go too on a sheet that is meant to be read, not edited:",[39,223,227],{"className":224,"code":225,"language":226,"meta":44,"style":44},"language-python shiki shiki-themes github-light github-dark-high-contrast","from openpyxl import load_workbook\n\nwb = load_workbook(\"regional.xlsx\")\nws = wb[\"Summary\"]\nws.sheet_view.showGridLines = False\nws.sheet_view.showRowColHeaders = False\nprint(ws.sheet_view.showGridLines, ws.sheet_view.showRowColHeaders)\n","python",[14,228,229,245,252,270,287,299,309],{"__ignoreMap":44},[48,230,231,235,239,242],{"class":50,"line":51},[48,232,234],{"class":233},"s-kum","from",[48,236,238],{"class":237},"skGVy"," openpyxl ",[48,240,241],{"class":233},"import",[48,243,244],{"class":237}," load_workbook\n",[48,246,248],{"class":50,"line":247},2,[48,249,251],{"emptyLinePlaceholder":250},true,"\n",[48,253,255,258,261,264,267],{"class":50,"line":254},3,[48,256,257],{"class":237},"wb ",[48,259,260],{"class":233},"=",[48,262,263],{"class":237}," load_workbook(",[48,265,266],{"class":58},"\"regional.xlsx\"",[48,268,269],{"class":237},")\n",[48,271,273,276,278,281,284],{"class":50,"line":272},4,[48,274,275],{"class":237},"ws ",[48,277,260],{"class":233},[48,279,280],{"class":237}," wb[",[48,282,283],{"class":58},"\"Summary\"",[48,285,286],{"class":237},"]\n",[48,288,290,293,295],{"class":50,"line":289},5,[48,291,292],{"class":237},"ws.sheet_view.showGridLines ",[48,294,260],{"class":233},[48,296,298],{"class":297},"sP0c6"," False\n",[48,300,302,305,307],{"class":50,"line":301},6,[48,303,304],{"class":237},"ws.sheet_view.showRowColHeaders ",[48,306,260],{"class":233},[48,308,298],{"class":297},[48,310,312,315],{"class":50,"line":311},7,[48,313,314],{"class":297},"print",[48,316,317],{"class":237},"(ws.sheet_view.showGridLines, ws.sheet_view.showRowColHeaders)\n",[10,319,320,321,323,324,327],{},"These settings affect only the screen. Whether gridlines ",[19,322,314],{}," is a separate page-setup option, ",[14,325,326],{},"ws.print_options.gridLines",", which is off by default — so a sheet can show gridlines on screen and print without them, or the other way round. Keep headings on data sheets: people need them to refer to cells, to read the row count at a glance and to use filters sensibly.",[34,329,331],{"id":330},"step-2-set-the-zoom","Step 2 — Set the zoom",[10,333,334,337],{},[14,335,336],{},"zoomScale"," is a percentage from 10 to 400. A summary with large fonts often reads best at 90–110%; a wide data sheet at 80–85% so more columns fit on a laptop screen:",[39,339,341],{"className":224,"code":340,"language":226,"meta":44,"style":44},"ws.sheet_view.zoomScale = 110\nwb[\"Data\"].sheet_view.zoomScale = 85\nprint({s.title: s.sheet_view.zoomScale for s in wb.worksheets})\n",[14,342,343,353,369],{"__ignoreMap":44},[48,344,345,348,350],{"class":50,"line":51},[48,346,347],{"class":237},"ws.sheet_view.zoomScale ",[48,349,260],{"class":233},[48,351,352],{"class":297}," 110\n",[48,354,355,358,361,364,366],{"class":50,"line":247},[48,356,357],{"class":237},"wb[",[48,359,360],{"class":58},"\"Data\"",[48,362,363],{"class":237},"].sheet_view.zoomScale ",[48,365,260],{"class":233},[48,367,368],{"class":297}," 85\n",[48,370,371,373,376,379,382,385],{"class":50,"line":254},[48,372,314],{"class":297},[48,374,375],{"class":237},"({s.title: s.sheet_view.zoomScale ",[48,377,378],{"class":233},"for",[48,380,381],{"class":237}," s ",[48,383,384],{"class":233},"in",[48,386,387],{"class":237}," wb.worksheets})\n",[10,389,390,391,217,394,397,398,400],{},"Each sheet keeps its own zoom, and Excel remembers the one saved in the file until the reader changes it. The Page Layout and Page Break Preview views have their own zoom attributes, ",[14,392,393],{},"zoomScalePageLayoutView",[14,395,396],{},"zoomScaleSheetLayoutView","; ",[14,399,336],{}," applies to whichever view the sheet opens in.",[90,402,99,408,99,411,99,414,99,419,99,425,99,431,99,437,99,443,99,449,99,457,99,461,99,466,99,470,99,475,99,479,99,484,99,487,99,493,99,498,99,502,99,506,99,512,99,515,99,520,99,523,99,528,99,531],{"viewBox":403,"role":93,"ariaLabelledBy":404,"xmlns":97,"style":407},"4 0 752 233",[405,406],"sv-before-after-t","sv-before-after-d","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[101,409,410],{"id":405},"The same sheet with default and designed view settings",[105,412,413],{"id":406},"Two panels. The default view has gridlines, headings, 100 percent zoom and the cursor wherever it was left. The designed view hides gridlines and headings, uses 110 percent zoom, selects the title cell and starts scrolled to the top.",[109,415],{"x":416,"y":112,"width":417,"height":418,"fill":115},"4","752","233",[109,420],{"x":421,"y":119,"width":422,"height":423,"rx":424,"fill":123,"stroke":124,"style":125},"20.0","351.0","201.0","14",[127,426,428],{"transform":427},"translate(182.5,29.0) scale(1.083)",[131,429],{"d":168,"fill":134,"stroke":135,"style":430},"stroke-width:1.66px;stroke-linecap:round;stroke-linejoin:round",[138,432,436],{"x":433,"y":434,"style":435},"195.5","78.0","font-size:14px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","Default view",[50,438],{"x1":439,"y1":440,"x2":441,"y2":440,"stroke":124,"style":442},"36.0","91.0","355.0","stroke-width:1px",[138,444,448],{"x":445,"y":446,"style":447},"60.0","111.0","font-size:12px;font-weight:400;fill:var(--text,#172033);text-anchor:start","gridlines on every cell",[127,450,452],{"transform":451},"translate(38.5,99.5) scale(0.625)",[131,453],{"d":454,"fill":134,"stroke":455,"style":456},"M6 6l12 12 M18 6L6 18","var(--accent,#f43f8f)","stroke-width:2.88px;stroke-linecap:round;stroke-linejoin:round",[138,458,460],{"x":445,"y":459,"style":447},"137.0","headings A B C and 1 2 3",[127,462,464],{"transform":463},"translate(38.5,125.5) scale(0.625)",[131,465],{"d":454,"fill":134,"stroke":455,"style":456},[138,467,469],{"x":445,"y":468,"style":447},"163.0","zoom 100%",[127,471,473],{"transform":472},"translate(38.5,151.5) scale(0.625)",[131,474],{"d":454,"fill":134,"stroke":455,"style":456},[138,476,478],{"x":445,"y":477,"style":447},"189.0","cursor where it was last left",[127,480,482],{"transform":481},"translate(38.5,177.5) scale(0.625)",[131,483],{"d":454,"fill":134,"stroke":455,"style":456},[109,485],{"x":486,"y":119,"width":422,"height":423,"rx":424,"fill":189,"stroke":190,"style":125},"389.0",[127,488,490],{"transform":489},"translate(551.5,29.0) scale(1.083)",[131,491],{"d":492,"fill":134,"stroke":197,"style":430},"M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z M12 9a3 3 0 1 0 .01 0z",[138,494,497],{"x":495,"y":434,"style":496},"564.5","font-size:14px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Designed view",[50,499],{"x1":500,"y1":440,"x2":501,"y2":440,"stroke":190,"style":442},"405.0","724.0",[138,503,505],{"x":504,"y":446,"style":447},"429.0","no gridlines, own borders",[127,507,509],{"transform":508},"translate(407.5,99.5) scale(0.625)",[131,510],{"d":511,"fill":134,"stroke":190,"style":456},"M5 12.5l4.5 4.5L19 7",[138,513,514],{"x":504,"y":459,"style":447},"headings hidden on the summary",[127,516,518],{"transform":517},"translate(407.5,125.5) scale(0.625)",[131,519],{"d":511,"fill":134,"stroke":190,"style":456},[138,521,522],{"x":504,"y":468,"style":447},"zoom 110%",[127,524,526],{"transform":525},"translate(407.5,151.5) scale(0.625)",[131,527],{"d":511,"fill":134,"stroke":190,"style":456},[138,529,530],{"x":504,"y":477,"style":447},"B2 selected, scrolled to the top",[127,532,534],{"transform":533},"translate(407.5,177.5) scale(0.625)",[131,535],{"d":511,"fill":134,"stroke":190,"style":456},[34,537,539],{"id":538},"step-3-choose-the-selected-cell-and-the-scroll-position","Step 3 — Choose the selected cell and the scroll position",[10,541,542],{},"When the file opens, the cursor sits on the active cell and the window shows the sheet from its top-left cell. Point both at the start of the report:",[39,544,546],{"className":224,"code":545,"language":226,"meta":44,"style":44},"from openpyxl.worksheet.views import Selection\n\nws.sheet_view.selection = [Selection(activeCell=\"B2\", sqref=\"B2\")]\nws.sheet_view.topLeftCell = \"A1\"\ndata = wb[\"Data\"]\ndata.sheet_view.selection = [Selection(activeCell=\"A2\", sqref=\"A2\")]\nprint(ws.sheet_view.selection[0].activeCell, ws.sheet_view.topLeftCell)\n",[14,547,548,560,564,596,606,619,645],{"__ignoreMap":44},[48,549,550,552,555,557],{"class":50,"line":51},[48,551,234],{"class":233},[48,553,554],{"class":237}," openpyxl.worksheet.views ",[48,556,241],{"class":233},[48,558,559],{"class":237}," Selection\n",[48,561,562],{"class":50,"line":247},[48,563,251],{"emptyLinePlaceholder":250},[48,565,566,569,571,574,578,580,583,586,589,591,593],{"class":50,"line":254},[48,567,568],{"class":237},"ws.sheet_view.selection ",[48,570,260],{"class":233},[48,572,573],{"class":237}," [Selection(",[48,575,577],{"class":576},"sa561","activeCell",[48,579,260],{"class":233},[48,581,582],{"class":58},"\"B2\"",[48,584,585],{"class":237},", ",[48,587,588],{"class":576},"sqref",[48,590,260],{"class":233},[48,592,582],{"class":58},[48,594,595],{"class":237},")]\n",[48,597,598,601,603],{"class":50,"line":272},[48,599,600],{"class":237},"ws.sheet_view.topLeftCell ",[48,602,260],{"class":233},[48,604,605],{"class":58}," \"A1\"\n",[48,607,608,611,613,615,617],{"class":50,"line":289},[48,609,610],{"class":237},"data ",[48,612,260],{"class":233},[48,614,280],{"class":237},[48,616,360],{"class":58},[48,618,286],{"class":237},[48,620,621,624,626,628,630,632,635,637,639,641,643],{"class":50,"line":301},[48,622,623],{"class":237},"data.sheet_view.selection ",[48,625,260],{"class":233},[48,627,573],{"class":237},[48,629,577],{"class":576},[48,631,260],{"class":233},[48,633,634],{"class":58},"\"A2\"",[48,636,585],{"class":237},[48,638,588],{"class":576},[48,640,260],{"class":233},[48,642,634],{"class":58},[48,644,595],{"class":237},[48,646,647,649,652,654],{"class":50,"line":311},[48,648,314],{"class":297},[48,650,651],{"class":237},"(ws.sheet_view.selection[",[48,653,112],{"class":297},[48,655,656],{"class":237},"].activeCell, ws.sheet_view.topLeftCell)\n",[10,658,659,661,662,664,665,668,669,672,673,676,677,680,681,684,685,689],{},[14,660,577],{}," is where the cursor is; ",[14,663,588],{}," is the highlighted range, which can be larger — ",[14,666,667],{},"sqref=\"B4:E8\""," with ",[14,670,671],{},"activeCell=\"B4\""," opens with the table selected. On a sheet with frozen panes the selection belongs to a pane: ",[14,674,675],{},"ws.freeze_panes = \"A2\""," creates a bottom pane, and the selection should name it with ",[14,678,679],{},"pane=\"bottomLeft\"",". Set ",[14,682,683],{},"freeze_panes"," first and openpyxl builds matching selections for you — see ",[28,686,688],{"href":687},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Ffreeze-header-row-in-excel-with-openpyxl\u002F","Freeze the Header Row in Excel with openpyxl",".",[34,691,693],{"id":692},"step-4-page-layout-view-zeros-and-right-to-left","Step 4 — Page Layout view, zeros and right-to-left",[10,695,696],{},"Three more settings are occasionally exactly what a report needs:",[39,698,700],{"className":224,"code":699,"language":226,"meta":44,"style":44},"ws.sheet_view.showZeros = False            # West's 0 sales show as a blank cell\nwb[\"Data\"].sheet_view.view = \"pageLayout\"  # opens showing pages, margins, header and footer\narabic = wb.create_sheet(\"تقرير\")\narabic.sheet_view.rightToLeft = True       # column A on the right, for RTL languages\nprint(ws.sheet_view.showZeros, wb[\"Data\"].sheet_view.view, arabic.sheet_view.rightToLeft)\n",[14,701,702,716,733,748,761],{"__ignoreMap":44},[48,703,704,707,709,712],{"class":50,"line":51},[48,705,706],{"class":237},"ws.sheet_view.showZeros ",[48,708,260],{"class":233},[48,710,711],{"class":297}," False",[48,713,715],{"class":714},"s-wDw","            # West's 0 sales show as a blank cell\n",[48,717,718,720,722,725,727,730],{"class":50,"line":247},[48,719,357],{"class":237},[48,721,360],{"class":58},[48,723,724],{"class":237},"].sheet_view.view ",[48,726,260],{"class":233},[48,728,729],{"class":58}," \"pageLayout\"",[48,731,732],{"class":714},"  # opens showing pages, margins, header and footer\n",[48,734,735,738,740,743,746],{"class":50,"line":254},[48,736,737],{"class":237},"arabic ",[48,739,260],{"class":233},[48,741,742],{"class":237}," wb.create_sheet(",[48,744,745],{"class":58},"\"تقرير\"",[48,747,269],{"class":237},[48,749,750,753,755,758],{"class":50,"line":272},[48,751,752],{"class":237},"arabic.sheet_view.rightToLeft ",[48,754,260],{"class":233},[48,756,757],{"class":297}," True",[48,759,760],{"class":714},"       # column A on the right, for RTL languages\n",[48,762,763,765,768,770],{"class":50,"line":289},[48,764,314],{"class":297},[48,766,767],{"class":237},"(ws.sheet_view.showZeros, wb[",[48,769,360],{"class":58},[48,771,772],{"class":237},"].sheet_view.view, arabic.sheet_view.rightToLeft)\n",[774,775,776,787,804],"ul",{},[777,778,779,782,783,786],"li",{},[14,780,781],{},"showZeros = False"," hides every zero on the sheet, which tidies sparse tables but also hides genuine zeros — the West region's sales here. For more control, use a number format such as ",[14,784,785],{},"#,##0;-#,##0;;@",", whose empty third section hides zeros in chosen cells only.",[777,788,789,792,793,585,796,799,800,803],{},[14,790,791],{},"view"," is ",[14,794,795],{},"\"normal\"",[14,797,798],{},"\"pageLayout\""," or ",[14,801,802],{},"\"pageBreakPreview\"",". Page Layout suits sheets that are printed, because the reader sees the page boundaries and the header and footer.",[777,805,806,809],{},[14,807,808],{},"rightToLeft"," mirrors the sheet for Arabic, Hebrew and other right-to-left languages.",[34,811,813],{"id":812},"step-5-change-the-active-sheet-without-grouping-sheets","Step 5 — Change the active sheet without grouping sheets",[10,815,816,819],{},[14,817,818],{},"wb.active"," decides which tab is showing when the workbook opens. Setting it looks harmless:",[39,821,823],{"className":224,"code":822,"language":226,"meta":44,"style":44},"wb.active = wb[\"Data\"]\nprint([(s.title, s.sheet_view.tabSelected) for s in wb.worksheets])\n",[14,824,825,838],{"__ignoreMap":44},[48,826,827,830,832,834,836],{"class":50,"line":51},[48,828,829],{"class":237},"wb.active ",[48,831,260],{"class":233},[48,833,280],{"class":237},[48,835,360],{"class":58},[48,837,286],{"class":237},[48,839,840,842,845,847,849,851],{"class":50,"line":247},[48,841,314],{"class":297},[48,843,844],{"class":237},"([(s.title, s.sheet_view.tabSelected) ",[48,846,378],{"class":233},[48,848,381],{"class":237},[48,850,384],{"class":233},[48,852,853],{"class":237}," wb.worksheets])\n",[10,855,856,857,859,860,863,864,867,868,870],{},"But ",[14,858,71],{}," still has ",[14,861,862],{},"tabSelected = True",", copied from the file as Excel saved it. openpyxl sets the new active sheet but does not clear the flag on the old one, so both sheets are ",[19,865,866],{},"selected"," when the file opens: Excel shows ",[14,869,16],{}," in the title bar, and anything the reader types lands on both sheets at once. It is an easy way to corrupt a report by accident. Clear the flag everywhere and set it only on the sheet that should be active:",[39,872,874],{"className":224,"code":873,"language":226,"meta":44,"style":44},"def set_active(wb, sheet):\n    for s in wb.worksheets:\n        s.sheet_view.tabSelected = False\n    wb.active = wb[sheet]\n    wb[sheet].sheet_view.tabSelected = True\n\nset_active(wb, \"Summary\")\nprint([(s.title, s.sheet_view.tabSelected) for s in wb.worksheets])\nwb.save(\"regional_view.xlsx\")\n",[14,875,876,888,900,909,919,929,933,942,957],{"__ignoreMap":44},[48,877,878,881,885],{"class":50,"line":51},[48,879,880],{"class":233},"def",[48,882,884],{"class":883},"s_Opv"," set_active",[48,886,887],{"class":237},"(wb, sheet):\n",[48,889,890,893,895,897],{"class":50,"line":247},[48,891,892],{"class":233},"    for",[48,894,381],{"class":237},[48,896,384],{"class":233},[48,898,899],{"class":237}," wb.worksheets:\n",[48,901,902,905,907],{"class":50,"line":254},[48,903,904],{"class":237},"        s.sheet_view.tabSelected ",[48,906,260],{"class":233},[48,908,298],{"class":297},[48,910,911,914,916],{"class":50,"line":272},[48,912,913],{"class":237},"    wb.active ",[48,915,260],{"class":233},[48,917,918],{"class":237}," wb[sheet]\n",[48,920,921,924,926],{"class":50,"line":289},[48,922,923],{"class":237},"    wb[sheet].sheet_view.tabSelected ",[48,925,260],{"class":233},[48,927,928],{"class":297}," True\n",[48,930,931],{"class":50,"line":301},[48,932,251],{"emptyLinePlaceholder":250},[48,934,935,938,940],{"class":50,"line":311},[48,936,937],{"class":237},"set_active(wb, ",[48,939,283],{"class":58},[48,941,269],{"class":237},[48,943,945,947,949,951,953,955],{"class":50,"line":944},8,[48,946,314],{"class":297},[48,948,844],{"class":237},[48,950,378],{"class":233},[48,952,381],{"class":237},[48,954,384],{"class":233},[48,956,853],{"class":237},[48,958,960,963,966],{"class":50,"line":959},9,[48,961,962],{"class":237},"wb.save(",[48,964,965],{"class":58},"\"regional_view.xlsx\"",[48,967,269],{"class":237},[90,969,99,975,99,978,99,981,99,986,99,993,99,998,99,1004,99,1009,99,1014,99,1017,99,1023,99,1027,99,1031,99,1035,99,1039,99,1043,99,1048,99,1050,99,1054,99,1056,99,1059,99,1061,99,1064,99,1067,99,1071,99,1073,99,1077,99,1079,99,1082,99,1084,99,1087,99,1090,99,1093,99,1095,99,1098,99,1100,99,1103,99,1105,99,1108,99,1113,99,1119,99,1124,99,1128,99,1132,99,1135,99,1139,99,1144,99,1149,99,1152,99,1160,99,1167,99,1173,99,1177],{"viewBox":970,"role":93,"ariaLabelledBy":971,"xmlns":97,"style":974},"106 0 547 194",[972,973],"sv-group-t","sv-group-d","width:100%;max-width:547px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[101,976,977],{"id":972},"Two tabs selected — the file opens in Group mode",[105,979,980],{"id":973},"A workbook window whose title reads Group, with the Summary and Data tabs both highlighted as selected, which means edits apply to both sheets.",[109,982],{"x":983,"y":112,"width":984,"height":985,"fill":115},"106","547","194",[109,987],{"x":988,"y":119,"width":989,"height":990,"rx":991,"fill":123,"stroke":124,"style":992},"122.6","238.3","30.0","8","stroke-width:1.5px",[109,994],{"x":988,"y":995,"width":989,"height":996,"rx":112,"fill":123,"stroke":124,"style":997},"38.0","8.0","stroke-width:0px",[127,999,1001],{"transform":1000},"translate(132.6,23.0) scale(0.667)",[131,1002],{"d":133,"fill":134,"stroke":197,"style":1003},"stroke-width:2.70px;stroke-linecap:round;stroke-linejoin:round",[138,1005,1008],{"x":1006,"y":439,"style":1007},"154.6","font-size:12px;font-weight:700;fill:var(--text,#172033);text-anchor:start","regional.xlsx  [Group]",[109,1010],{"x":988,"y":1011,"width":1012,"height":1013,"rx":112,"fill":123,"stroke":124,"style":442},"46.0","32.0","24.0",[109,1015],{"x":1006,"y":1011,"width":1016,"height":1013,"rx":112,"fill":123,"stroke":124,"style":442},"66.7",[138,1018,1022],{"x":1019,"y":1020,"style":1021},"187.9","63.0","font-size:11px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","A",[109,1024],{"x":1025,"y":1011,"width":1026,"height":1013,"rx":112,"fill":123,"stroke":124,"style":442},"221.3","69.4",[138,1028,1030],{"x":1029,"y":1020,"style":1021},"256.0","B",[109,1032],{"x":1033,"y":1011,"width":1034,"height":1013,"rx":112,"fill":123,"stroke":124,"style":442},"290.7","70.1",[138,1036,1038],{"x":1037,"y":1020,"style":1021},"325.8","C",[109,1040],{"x":988,"y":1041,"width":1012,"height":1042,"rx":112,"fill":123,"stroke":124,"style":442},"70.0","28.0",[138,1044,1047],{"x":1045,"y":1046,"style":1021},"138.6","89.0","1",[109,1049],{"x":1006,"y":1041,"width":1016,"height":1042,"rx":112,"fill":162,"stroke":153,"style":992},[138,1051,1053],{"x":1019,"y":1046,"style":1052},"font-size:12px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Region",[109,1055],{"x":1025,"y":1041,"width":1026,"height":1042,"rx":112,"fill":162,"stroke":153,"style":992},[138,1057,1058],{"x":1029,"y":1046,"style":1052},"Sales",[109,1060],{"x":1033,"y":1041,"width":1034,"height":1042,"rx":112,"fill":162,"stroke":153,"style":992},[138,1062,1063],{"x":1037,"y":1046,"style":1052},"Target",[109,1065],{"x":988,"y":1066,"width":1012,"height":1042,"rx":112,"fill":123,"stroke":124,"style":442},"98.0",[138,1068,1070],{"x":1045,"y":1069,"style":1021},"117.0","2",[109,1072],{"x":1006,"y":1066,"width":1016,"height":1042,"rx":112,"fill":115,"stroke":124,"style":442},[138,1074,1076],{"x":1019,"y":1069,"style":1075},"font-size:12px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","North",[109,1078],{"x":1025,"y":1066,"width":1026,"height":1042,"rx":112,"fill":115,"stroke":124,"style":442},[138,1080,1081],{"x":1029,"y":1069,"style":1075},"48,210",[109,1083],{"x":1033,"y":1066,"width":1034,"height":1042,"rx":112,"fill":115,"stroke":124,"style":442},[138,1085,1086],{"x":1037,"y":1069,"style":1075},"45,000",[109,1088],{"x":988,"y":1089,"width":1012,"height":1042,"rx":112,"fill":123,"stroke":124,"style":442},"126.0",[138,1091,1092],{"x":1045,"y":161,"style":1021},"3",[109,1094],{"x":1006,"y":1089,"width":1016,"height":1042,"rx":112,"fill":115,"stroke":124,"style":442},[138,1096,1097],{"x":1019,"y":161,"style":1075},"South",[109,1099],{"x":1025,"y":1089,"width":1026,"height":1042,"rx":112,"fill":115,"stroke":124,"style":442},[138,1101,1102],{"x":1029,"y":161,"style":1075},"39,980",[109,1104],{"x":1033,"y":1089,"width":1034,"height":1042,"rx":112,"fill":115,"stroke":124,"style":442},[138,1106,1107],{"x":1037,"y":161,"style":1075},"42,000",[109,1109],{"x":1110,"y":1111,"width":1112,"height":1013,"rx":112,"fill":115,"stroke":124,"style":442},"130.6","154.0","80.7",[50,1114],{"x1":1115,"y1":1116,"x2":1117,"y2":1116,"stroke":190,"style":1118},"132.6","177.0","209.2","stroke-width:3px",[138,1120,71],{"x":1121,"y":1122,"style":1123},"170.9","170.5","font-size:11.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle",[109,1125],{"x":1126,"y":1111,"width":1127,"height":1013,"rx":112,"fill":115,"stroke":124,"style":442},"213.2","51.2",[50,1129],{"x1":1130,"y1":1116,"x2":1131,"y2":1116,"stroke":190,"style":1118},"215.2","262.4",[138,1133,83],{"x":1134,"y":1122,"style":1123},"238.8",[109,1136],{"x":1137,"y":1111,"width":1138,"height":1013,"rx":112,"fill":123,"stroke":124,"style":442},"266.4","58.6",[138,1140,1143],{"x":1141,"y":1122,"style":1142},"295.7","font-size:11.5px;font-weight:400;fill:var(--muted,#5b6780);text-anchor:middle","تقرير",[50,1145],{"x1":1146,"y1":1147,"x2":1148,"y2":1147,"stroke":153,"style":125},"368.8","97.0","400.8",[155,1150],{"points":1151,"fill":158},"404.8,97.0 395.8,102.0 395.8,92.0",[109,1153],{"x":1154,"y":1155,"width":1156,"height":1157,"rx":122,"fill":1158,"stroke":1159,"style":125},"410.8","41.8","226.6","110.5","#fce9e9","var(--danger,#dc2626)",[127,1161,1163],{"transform":1162},"translate(512.1,54.8) scale(1.000)",[131,1164],{"d":1165,"fill":134,"stroke":1166,"style":136},"M12 3.5l9.5 17h-19z M12 10v5 M12 17.8v.4","var(--accent-ink,#be185d)",[138,1168,1172],{"x":1169,"y":1170,"style":1171},"524.1","101.2","font-size:13.5px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle","Both tabs selected",[138,1174,1176],{"x":1169,"y":1175,"style":147},"120.8","typing edits both sheets",[138,1178,1180],{"x":1169,"y":1179,"style":147},"138.2","clear tabSelected everywhere first",[10,1182,1183,1184,1187,1188,1191],{},"The same applies after ",[14,1185,1186],{},"copy_worksheet"," or when reading a template whose author left several sheets selected. Running ",[14,1189,1190],{},"set_active"," just before saving is a cheap habit for any workbook that went through openpyxl.",[34,1193,1195],{"id":1194},"apply-one-house-style-to-every-sheet","Apply one house style to every sheet",[10,1197,1198,1199,1202],{},"Reports built by several scripts drift: one sheet at 100%, another at 70% because someone was looking at it on a big monitor, gridlines on here and off there. A single function run just before ",[14,1200,1201],{},"save"," gives every workbook the same finish. Treat presentation sheets and data sheets differently, and finish with the active-sheet fix:",[39,1204,1206],{"className":224,"code":1205,"language":226,"meta":44,"style":44},"from openpyxl.worksheet.views import Selection\n\ndef finish_views(wb, first=\"Summary\", presentation=(\"Summary\",)):\n    for s in wb.worksheets:\n        is_report = s.title in presentation\n        s.sheet_view.showGridLines = not is_report\n        s.sheet_view.showRowColHeaders = not is_report\n        s.sheet_view.zoomScale = 110 if is_report else 85\n        s.sheet_view.topLeftCell = \"A1\"\n        if not s.freeze_panes:\n            s.sheet_view.selection = [Selection(activeCell=\"A1\", sqref=\"A1\")]\n    set_active(wb, first)\n\nwb = load_workbook(\"regional.xlsx\")\nfinish_views(wb)\nprint([(s.title, s.sheet_view.zoomScale, s.sheet_view.showGridLines) for s in wb.worksheets])\nwb.save(\"regional_finished.xlsx\")\n",[14,1207,1208,1218,1222,1249,1259,1274,1287,1298,1319,1328,1339,1366,1372,1377,1390,1396,1412],{"__ignoreMap":44},[48,1209,1210,1212,1214,1216],{"class":50,"line":51},[48,1211,234],{"class":233},[48,1213,554],{"class":237},[48,1215,241],{"class":233},[48,1217,559],{"class":237},[48,1219,1220],{"class":50,"line":247},[48,1221,251],{"emptyLinePlaceholder":250},[48,1223,1224,1226,1229,1232,1234,1236,1239,1241,1244,1246],{"class":50,"line":254},[48,1225,880],{"class":233},[48,1227,1228],{"class":883}," finish_views",[48,1230,1231],{"class":237},"(wb, first",[48,1233,260],{"class":233},[48,1235,283],{"class":58},[48,1237,1238],{"class":237},", presentation",[48,1240,260],{"class":233},[48,1242,1243],{"class":237},"(",[48,1245,283],{"class":58},[48,1247,1248],{"class":237},",)):\n",[48,1250,1251,1253,1255,1257],{"class":50,"line":272},[48,1252,892],{"class":233},[48,1254,381],{"class":237},[48,1256,384],{"class":233},[48,1258,899],{"class":237},[48,1260,1261,1264,1266,1269,1271],{"class":50,"line":289},[48,1262,1263],{"class":237},"        is_report ",[48,1265,260],{"class":233},[48,1267,1268],{"class":237}," s.title ",[48,1270,384],{"class":233},[48,1272,1273],{"class":237}," presentation\n",[48,1275,1276,1279,1281,1284],{"class":50,"line":301},[48,1277,1278],{"class":237},"        s.sheet_view.showGridLines ",[48,1280,260],{"class":233},[48,1282,1283],{"class":233}," not",[48,1285,1286],{"class":237}," is_report\n",[48,1288,1289,1292,1294,1296],{"class":50,"line":311},[48,1290,1291],{"class":237},"        s.sheet_view.showRowColHeaders ",[48,1293,260],{"class":233},[48,1295,1283],{"class":233},[48,1297,1286],{"class":237},[48,1299,1300,1303,1305,1308,1311,1314,1317],{"class":50,"line":944},[48,1301,1302],{"class":237},"        s.sheet_view.zoomScale ",[48,1304,260],{"class":233},[48,1306,1307],{"class":297}," 110",[48,1309,1310],{"class":233}," if",[48,1312,1313],{"class":237}," is_report ",[48,1315,1316],{"class":233},"else",[48,1318,368],{"class":297},[48,1320,1321,1324,1326],{"class":50,"line":959},[48,1322,1323],{"class":237},"        s.sheet_view.topLeftCell ",[48,1325,260],{"class":233},[48,1327,605],{"class":58},[48,1329,1331,1334,1336],{"class":50,"line":1330},10,[48,1332,1333],{"class":233},"        if",[48,1335,1283],{"class":233},[48,1337,1338],{"class":237}," s.freeze_panes:\n",[48,1340,1342,1345,1347,1349,1351,1353,1356,1358,1360,1362,1364],{"class":50,"line":1341},11,[48,1343,1344],{"class":237},"            s.sheet_view.selection ",[48,1346,260],{"class":233},[48,1348,573],{"class":237},[48,1350,577],{"class":576},[48,1352,260],{"class":233},[48,1354,1355],{"class":58},"\"A1\"",[48,1357,585],{"class":237},[48,1359,588],{"class":576},[48,1361,260],{"class":233},[48,1363,1355],{"class":58},[48,1365,595],{"class":237},[48,1367,1369],{"class":50,"line":1368},12,[48,1370,1371],{"class":237},"    set_active(wb, first)\n",[48,1373,1375],{"class":50,"line":1374},13,[48,1376,251],{"emptyLinePlaceholder":250},[48,1378,1380,1382,1384,1386,1388],{"class":50,"line":1379},14,[48,1381,257],{"class":237},[48,1383,260],{"class":233},[48,1385,263],{"class":237},[48,1387,266],{"class":58},[48,1389,269],{"class":237},[48,1391,1393],{"class":50,"line":1392},15,[48,1394,1395],{"class":237},"finish_views(wb)\n",[48,1397,1399,1401,1404,1406,1408,1410],{"class":50,"line":1398},16,[48,1400,314],{"class":297},[48,1402,1403],{"class":237},"([(s.title, s.sheet_view.zoomScale, s.sheet_view.showGridLines) ",[48,1405,378],{"class":233},[48,1407,381],{"class":237},[48,1409,384],{"class":233},[48,1411,853],{"class":237},[48,1413,1415,1417,1420],{"class":50,"line":1414},17,[48,1416,962],{"class":237},[48,1418,1419],{"class":58},"\"regional_finished.xlsx\"",[48,1421,269],{"class":237},[10,1423,1424,1425,689],{},"Sheets with frozen panes keep the selection openpyxl built for their pane, which is why the function only resets the selection when there is no freeze. Keeping the rules in one function also means changing the house style later — a different zoom for data sheets, say — is a one-line edit rather than a hunt through every report script. The same function fits naturally next to the other finishing steps in ",[28,1426,1428],{"href":1427},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fapply-a-reusable-style-theme-across-an-excel-report\u002F","Apply a Reusable Style Theme Across an Excel Report",[34,1430,1432],{"id":1431},"the-same-settings-in-xlsxwriter","The same settings in xlsxwriter",[10,1434,1435,1436,1439],{},"When the file is written from scratch with xlsxwriter, the settings are worksheet methods and the grouping problem does not arise, because ",[14,1437,1438],{},"activate()"," handles selection:",[39,1441,1443],{"className":224,"code":1442,"language":226,"meta":44,"style":44},"import xlsxwriter\n\nbook = xlsxwriter.Workbook(\"regional_xw.xlsx\")\nsummary = book.add_worksheet(\"Summary\")\ndetail = book.add_worksheet(\"Data\")\nsummary.write(\"B2\", \"Regional sales — September 2026\")\nsummary.hide_gridlines(2)       # 2 = hide on screen and in print\nsummary.set_zoom(110)\nsummary.set_selection(\"B2\")\ndetail.set_zoom(85)\ndetail.set_page_view()\nsummary.activate()\nbook.close()\nprint(\"written\")\n",[14,1444,1445,1452,1456,1471,1485,1498,1512,1525,1535,1544,1554,1559,1564,1569],{"__ignoreMap":44},[48,1446,1447,1449],{"class":50,"line":51},[48,1448,241],{"class":233},[48,1450,1451],{"class":237}," xlsxwriter\n",[48,1453,1454],{"class":50,"line":247},[48,1455,251],{"emptyLinePlaceholder":250},[48,1457,1458,1461,1463,1466,1469],{"class":50,"line":254},[48,1459,1460],{"class":237},"book ",[48,1462,260],{"class":233},[48,1464,1465],{"class":237}," xlsxwriter.Workbook(",[48,1467,1468],{"class":58},"\"regional_xw.xlsx\"",[48,1470,269],{"class":237},[48,1472,1473,1476,1478,1481,1483],{"class":50,"line":272},[48,1474,1475],{"class":237},"summary ",[48,1477,260],{"class":233},[48,1479,1480],{"class":237}," book.add_worksheet(",[48,1482,283],{"class":58},[48,1484,269],{"class":237},[48,1486,1487,1490,1492,1494,1496],{"class":50,"line":289},[48,1488,1489],{"class":237},"detail ",[48,1491,260],{"class":233},[48,1493,1480],{"class":237},[48,1495,360],{"class":58},[48,1497,269],{"class":237},[48,1499,1500,1503,1505,1507,1510],{"class":50,"line":301},[48,1501,1502],{"class":237},"summary.write(",[48,1504,582],{"class":58},[48,1506,585],{"class":237},[48,1508,1509],{"class":58},"\"Regional sales — September 2026\"",[48,1511,269],{"class":237},[48,1513,1514,1517,1519,1522],{"class":50,"line":311},[48,1515,1516],{"class":237},"summary.hide_gridlines(",[48,1518,1070],{"class":297},[48,1520,1521],{"class":237},")       ",[48,1523,1524],{"class":714},"# 2 = hide on screen and in print\n",[48,1526,1527,1530,1533],{"class":50,"line":944},[48,1528,1529],{"class":237},"summary.set_zoom(",[48,1531,1532],{"class":297},"110",[48,1534,269],{"class":237},[48,1536,1537,1540,1542],{"class":50,"line":959},[48,1538,1539],{"class":237},"summary.set_selection(",[48,1541,582],{"class":58},[48,1543,269],{"class":237},[48,1545,1546,1549,1552],{"class":50,"line":1330},[48,1547,1548],{"class":237},"detail.set_zoom(",[48,1550,1551],{"class":297},"85",[48,1553,269],{"class":237},[48,1555,1556],{"class":50,"line":1341},[48,1557,1558],{"class":237},"detail.set_page_view()\n",[48,1560,1561],{"class":50,"line":1368},[48,1562,1563],{"class":237},"summary.activate()\n",[48,1565,1566],{"class":50,"line":1374},[48,1567,1568],{"class":237},"book.close()\n",[48,1570,1571,1573,1575,1578],{"class":50,"line":1379},[48,1572,314],{"class":297},[48,1574,1243],{"class":237},[48,1576,1577],{"class":58},"\"written\"",[48,1579,269],{"class":237},[10,1581,1582,1585,1586,1588,1589,1593],{},[14,1583,1584],{},"hide_gridlines(1)"," hides only printed gridlines, ",[14,1587,1070],{}," hides both. The xlsxwriter method names map one-to-one to the openpyxl attributes above, so either library can produce the same finished view; ",[28,1590,1592],{"href":1591},"\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"," puts them in context.",[34,1595,1597],{"id":1596},"common-pitfalls","Common pitfalls",[774,1599,1600,1610,1616,1630,1639],{},[777,1601,1602,1606,1607,1609],{},[1603,1604,1605],"strong",{},"Grouped sheets."," Clear ",[14,1608,87],{}," on every sheet before marking the active one.",[777,1611,1612,1615],{},[1603,1613,1614],{},"Hidden sheet as active."," Never make a hidden sheet active; set the active sheet first, then hide others.",[777,1617,1618,1621,1622,1625,1626,1629],{},[1603,1619,1620],{},"Confusing screen and print gridlines."," ",[14,1623,1624],{},"sheet_view.showGridLines"," is the screen, ",[14,1627,1628],{},"print_options.gridLines"," is paper.",[777,1631,1632,1638],{},[1603,1633,1634,1637],{},[14,1635,1636],{},"showZeros"," hiding real data."," It applies to the whole sheet; use a number format for targeted blanks.",[777,1640,1641,1644,1645,1648,1649,1651],{},[1603,1642,1643],{},"Selections in frozen sheets."," A selection without the right ",[14,1646,1647],{},"pane"," is ignored or moved by Excel; set ",[14,1650,683],{}," before the selection.",[34,1653,1655],{"id":1654},"conclusion","Conclusion",[10,1657,1658,1659,1661,1662,1665,1666,1668,1669,1671],{},"Set the view once, just before saving: hide gridlines and headings on presentation sheets, give each sheet a sensible ",[14,1660,336],{},", point the selection and ",[14,1663,1664],{},"topLeftCell"," at the start of the report, and choose Page Layout view for sheets that get printed. Then clear ",[14,1667,87],{}," on every sheet and set it — together with ",[14,1670,818],{}," — only on the sheet the reader should see first, so the file never opens grouped.",[34,1673,1675],{"id":1674},"frequently-asked-questions","Frequently asked questions",[10,1677,1678,1681],{},[1603,1679,1680],{},"How do I hide gridlines in Excel with openpyxl?","\nSet ws.sheet_view.showGridLines = False on each sheet. That hides them on screen; printed gridlines are controlled separately by ws.print_options.gridLines, which is off by default.",[10,1683,1684,1687],{},[1603,1685,1686],{},"How do I set the zoom level with openpyxl?","\nSet ws.sheet_view.zoomScale to a percentage between 10 and 400, for example 85. Each sheet has its own zoom, and Excel opens the sheet at that level.",[10,1689,1690,1697],{},[1603,1691,1692,1693,1696],{},"Why does my workbook open with ",[48,1694,1695],{},"Group"," in the title bar?","\nMore than one sheet has tabSelected set. Setting wb.active in openpyxl does not clear the flag on the previously active sheet. Set tabSelected = False on every worksheet, then set wb.active and tabSelected = True on the one sheet that should open.",[10,1699,1700,1703],{},[1603,1701,1702],{},"How do I make a workbook open at a specific cell?","\nSet the sheet's selection to Selection(activeCell=\"B2\", sqref=\"B2\") and its topLeftCell to the cell that should appear at the top-left of the window, and make that sheet the active one.",[34,1705,1707],{"id":1706},"related","Related",[774,1709,1710,1716,1723,1730],{},[777,1711,1712,1713,1715],{},"Up one level: ",[28,1714,31],{"href":30}," — fonts, fills, borders and layout.",[777,1717,1718,1722],{},[28,1719,1721],{"href":1720},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fset-the-active-sheet-and-tab-colour-with-openpyxl\u002F","Set the Active Sheet and Tab Colour with openpyxl"," — which sheet opens first, and how its tab looks.",[777,1724,1725,1729],{},[28,1726,1728],{"href":1727},"\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 print-side counterparts of these settings.",[777,1731,1732,1736],{},[28,1733,1735],{"href":1734},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fprotecting-and-sharing-excel-workbooks\u002Fhide-sheets-rows-and-columns-with-openpyxl\u002F","Hide Sheets, Rows and Columns with openpyxl"," — hiding content rather than chrome.",[1738,1739,1740],"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 .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}html pre.shiki code .s_Opv, html code.shiki .s_Opv{--shiki-default:#6F42C1;--shiki-dark:#DBB7FF}",{"title":44,"searchDepth":247,"depth":247,"links":1742},[1743,1744,1745,1746,1747,1748,1749,1750,1751,1752,1753,1754],{"id":36,"depth":247,"text":37},{"id":209,"depth":247,"text":210},{"id":330,"depth":247,"text":331},{"id":538,"depth":247,"text":539},{"id":692,"depth":247,"text":693},{"id":812,"depth":247,"text":813},{"id":1194,"depth":247,"text":1195},{"id":1431,"depth":247,"text":1432},{"id":1596,"depth":247,"text":1597},{"id":1654,"depth":247,"text":1655},{"id":1674,"depth":247,"text":1675},{"id":1706,"depth":247,"text":1707},"2026-09-29","Control how a generated workbook looks the moment it opens: hide gridlines and headings, set the zoom, choose the selected cell and the first visible row, open in Page Layout view, hide zeros, set right-to-left sheets, and avoid the grouped-sheets trap when changing the active sheet.","md",[1759,1761,1763,1766],{"q":1680,"a":1760},"Set ws.sheet_view.showGridLines = False on each sheet. That hides them on screen; printed gridlines are controlled separately by ws.print_options.gridLines, which is off by default.",{"q":1686,"a":1762},"Set ws.sheet_view.zoomScale to a percentage between 10 and 400, for example 85. Each sheet has its own zoom, and Excel opens the sheet at that level.",{"q":1764,"a":1765},"Why does my workbook open with [Group] in the title bar?","More than one sheet has tabSelected set. Setting wb.active in openpyxl does not clear the flag on the previously active sheet. Set tabSelected = False on every worksheet, then set wb.active and tabSelected = True on the one sheet that should open.",{"q":1702,"a":1767},"Set the sheet's selection to Selection(activeCell=\"B2\", sqref=\"B2\") and its topLeftCell to the cell that should appear at the top-left of the window, and make that sheet the active one.","hide gridlines and set zoom with openpyxl",null,{"breadcrumb":1771},[1772,1775,1778],{"name":1773,"item":1774},"Home","\u002F",{"name":1776,"item":1777},"Formatting and Charting Excel Reports with Python","\u002Fformatting-and-charting-excel-reports-with-python\u002F",{"name":31,"item":30},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl",{"title":1781,"description":1782},"Hide Gridlines, Set Zoom and Active Cell with openpyxl","Use ws.sheet_view in openpyxl to hide gridlines, set zoomScale, select a cell, scroll with topLeftCell, pick Page Layout view and hide zeros — plus fix sheets opening grouped because tabSelected was left on. xlsxwriter equivalents included.","hide-gridlines-and-set-zoom-with-openpyxl","formatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Fhide-gridlines-and-set-zoom-with-openpyxl\u002Findex",[1786,1787],"cell-styling","openpyxl","how-to","riHiEC8J72Bx_0s6TmvM9d3QYklUvykv39iOBbVXNys",[1791,1794],{"title":688,"path":1792,"stem":1793,"children":-1},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Ffreeze-header-row-in-excel-with-openpyxl","formatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Ffreeze-header-row-in-excel-with-openpyxl\u002Findex",{"title":1795,"path":1796,"stem":1797,"children":-1},"Indent Cells to Show a Hierarchy with openpyxl","\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Findent-cells-to-show-a-hierarchy-with-openpyxl","formatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl\u002Findent-cells-to-show-a-hierarchy-with-openpyxl\u002Findex",[1799,1801],{"path":1800,"title":1776},"\u002Fformatting-and-charting-excel-reports-with-python",{"path":1802,"title":31},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fstyling-excel-cells-with-openpyxl",[],[1805,1808,1811,1814,1817,1820],{"path":1806,"title":1807,"kind":1788},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fwrite-rich-text-in-a-cell-with-xlsxwriter","Write Rich Text with Mixed Formats in One Cell with xlsxwriter",{"path":1809,"title":1810,"kind":1788},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fcopy-cell-styles-with-openpyxl","Copy Cell Styles from One Cell to Another with openpyxl",{"path":1812,"title":1813,"kind":1788},"\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fauto-fit-column-widths-when-writing-with-pandas","Auto-Fit Column Widths When Writing with pandas",{"path":1815,"title":1816,"kind":1788},"\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fexport-a-styled-pandas-dataframe-to-excel","Export a Styled pandas DataFrame to Excel",{"path":1818,"title":1819,"kind":1788},"\u002Fautomating-reporting-workflows\u002Fbuilding-finance-and-operations-reports\u002Fgenerate-a-staff-rota-in-excel-with-python","Generate a Staff Rota in Excel with Python",{"path":1821,"title":1822,"kind":1788},"\u002Fautomating-reporting-workflows\u002Fbuilding-multi-sheet-excel-dashboards\u002Fadd-a-table-of-contents-sheet-with-hyperlinks-in-excel","Add a Table of Contents Sheet with Hyperlinks in Excel",1790972117314]