[{"data":1,"prerenderedAt":1655},["ShallowReactive",2],{"doc:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas":3,"surround:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas":1619,"ancestors:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas":1628,"children:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas":1633,"related:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas":1634},{"id":4,"title":5,"body":6,"dateModified":1585,"datePublished":1585,"description":1586,"extension":1587,"faq":1588,"keyword":1597,"kind":1598,"meta":1599,"navigation":110,"path":1608,"seo":1609,"slug":1612,"stem":1613,"topics":1614,"type":1617,"__hash__":1618},"docs\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas\u002Findex.md","Fix Wrong Sheet Order After Writing with pandas",{"type":7,"value":8,"toc":1572},"minimark",[9,37,42,71,78,82,261,275,400,414,500,504,617,628,632,796,806,810,941,959,1102,1106,1117,1132,1136,1282,1293,1435,1439,1483,1487,1493,1497,1505,1514,1523,1535,1539,1568],[10,11,12,13,17,18,17,21,17,24,17,27,30,31,36],"p",{},"A report written with pandas has one sheet per month, and they come out as ",[14,15,16],"em",{},"Apr",", ",[14,19,20],{},"Aug",[14,22,23],{},"Dec",[14,25,26],{},"Feb",[14,28,29],{},"Jan","… Or a summary sheet added to an existing workbook ends up at the far right, after twelve monthly tabs, where nobody will find it. The data is right; the order is wrong, and for a workbook people navigate by tabs that matters almost as much. pandas writes sheets in exactly the order your code writes them, and Excel shows tabs in the order they are stored, so a wrong order always has a cause in the code that produced the sheets — usually one of three. This page reproduces each cause, shows how to write the sheets in the intended order in the first place, how to reorder an existing workbook with openpyxl when that is not possible, and how to make sure the right sheet opens first. It belongs to ",[32,33,35],"a",{"href":34},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002F","Troubleshooting Common Python Excel Errors",".",[38,39,41],"h2",{"id":40},"prerequisites","Prerequisites",[43,44,49],"pre",{"className":45,"code":46,"language":47,"meta":48,"style":48},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install pandas openpyxl\n","bash","",[50,51,52],"code",{"__ignoreMap":48},[53,54,57,61,65,68],"span",{"class":55,"line":56},"line",1,[53,58,60],{"class":59},"sMTad","pip",[53,62,64],{"class":63},"srMev"," install",[53,66,67],{"class":63}," pandas",[53,69,70],{"class":63}," openpyxl\n",[10,72,73,74,77],{},"The input is a year of daily sales. The report should have a ",[14,75,76],{},"Summary"," sheet first, then one sheet per month from January to December.",[38,79,81],{"id":80},"cause-1-group-keys-that-sort-alphabetically","Cause 1 — Group keys that sort alphabetically",[43,83,87],{"className":84,"code":85,"language":86,"meta":48,"style":48},"language-python shiki shiki-themes github-light github-dark-high-contrast","import pandas as pd\n\nsales = pd.read_excel(\"daily_sales.xlsx\")\nsales[\"Month\"] = sales[\"Date\"].dt.strftime(\"%b\")\n\nwith pd.ExcelWriter(\"by_month_wrong.xlsx\") as xw:\n    for month, g in sales.groupby(\"Month\"):\n        g.to_excel(xw, sheet_name=month, index=False)\nwith pd.ExcelFile(\"by_month_wrong.xlsx\") as f:\n    print(f.sheet_names)\n","python",[50,88,89,105,112,130,164,169,189,209,235,252],{"__ignoreMap":48},[53,90,91,95,99,102],{"class":55,"line":56},[53,92,94],{"class":93},"s-kum","import",[53,96,98],{"class":97},"skGVy"," pandas ",[53,100,101],{"class":93},"as",[53,103,104],{"class":97}," pd\n",[53,106,108],{"class":55,"line":107},2,[53,109,111],{"emptyLinePlaceholder":110},true,"\n",[53,113,115,118,121,124,127],{"class":55,"line":114},3,[53,116,117],{"class":97},"sales ",[53,119,120],{"class":93},"=",[53,122,123],{"class":97}," pd.read_excel(",[53,125,126],{"class":63},"\"daily_sales.xlsx\"",[53,128,129],{"class":97},")\n",[53,131,133,136,139,142,144,147,150,153,156,160,162],{"class":55,"line":132},4,[53,134,135],{"class":97},"sales[",[53,137,138],{"class":63},"\"Month\"",[53,140,141],{"class":97},"] ",[53,143,120],{"class":93},[53,145,146],{"class":97}," sales[",[53,148,149],{"class":63},"\"Date\"",[53,151,152],{"class":97},"].dt.strftime(",[53,154,155],{"class":63},"\"",[53,157,159],{"class":158},"sSjpA","%b",[53,161,155],{"class":63},[53,163,129],{"class":97},[53,165,167],{"class":55,"line":166},5,[53,168,111],{"emptyLinePlaceholder":110},[53,170,172,175,178,181,184,186],{"class":55,"line":171},6,[53,173,174],{"class":93},"with",[53,176,177],{"class":97}," pd.ExcelWriter(",[53,179,180],{"class":63},"\"by_month_wrong.xlsx\"",[53,182,183],{"class":97},") ",[53,185,101],{"class":93},[53,187,188],{"class":97}," xw:\n",[53,190,192,195,198,201,204,206],{"class":55,"line":191},7,[53,193,194],{"class":93},"    for",[53,196,197],{"class":97}," month, g ",[53,199,200],{"class":93},"in",[53,202,203],{"class":97}," sales.groupby(",[53,205,138],{"class":63},[53,207,208],{"class":97},"):\n",[53,210,212,215,219,221,224,227,229,233],{"class":55,"line":211},8,[53,213,214],{"class":97},"        g.to_excel(xw, ",[53,216,218],{"class":217},"sa561","sheet_name",[53,220,120],{"class":93},[53,222,223],{"class":97},"month, ",[53,225,226],{"class":217},"index",[53,228,120],{"class":93},[53,230,232],{"class":231},"sP0c6","False",[53,234,129],{"class":97},[53,236,238,240,243,245,247,249],{"class":55,"line":237},9,[53,239,174],{"class":93},[53,241,242],{"class":97}," pd.ExcelFile(",[53,244,180],{"class":63},[53,246,183],{"class":97},[53,248,101],{"class":93},[53,250,251],{"class":97}," f:\n",[53,253,255,258],{"class":55,"line":254},10,[53,256,257],{"class":231},"    print",[53,259,260],{"class":97},"(f.sheet_names)\n",[10,262,263,266,267,270,271,274],{},[50,264,265],{},"groupby"," sorts its keys by default, and month ",[14,268,269],{},"names"," are strings, so they sort alphabetically: April, August, December, February and so on. The sheets are written in that order and Excel shows them in that order. The output shows exactly that: ",[14,272,273],{},"Apr, Aug, Dec, Feb, Jan, Jul, Jun, Mar, May, Nov, Oct, Sep"," — every month present, none in the right place. The fix is to group by something that sorts in time — the month number or a monthly period — and use the name only for the sheet title:",[43,276,278],{"className":84,"code":277,"language":86,"meta":48,"style":48},"sales[\"Period\"] = sales[\"Date\"].dt.to_period(\"M\")\nwith pd.ExcelWriter(\"by_month.xlsx\") as xw:\n    for period, g in sales.groupby(\"Period\"):\n        g.drop(columns=[\"Month\", \"Period\"]).to_excel(xw, sheet_name=period.strftime(\"%b %Y\"), index=False)\nwith pd.ExcelFile(\"by_month.xlsx\") as f:\n    print(f.sheet_names)\n",[50,279,280,303,318,333,380,394],{"__ignoreMap":48},[53,281,282,284,287,289,291,293,295,298,301],{"class":55,"line":56},[53,283,135],{"class":97},[53,285,286],{"class":63},"\"Period\"",[53,288,141],{"class":97},[53,290,120],{"class":93},[53,292,146],{"class":97},[53,294,149],{"class":63},[53,296,297],{"class":97},"].dt.to_period(",[53,299,300],{"class":63},"\"M\"",[53,302,129],{"class":97},[53,304,305,307,309,312,314,316],{"class":55,"line":107},[53,306,174],{"class":93},[53,308,177],{"class":97},[53,310,311],{"class":63},"\"by_month.xlsx\"",[53,313,183],{"class":97},[53,315,101],{"class":93},[53,317,188],{"class":97},[53,319,320,322,325,327,329,331],{"class":55,"line":114},[53,321,194],{"class":93},[53,323,324],{"class":97}," period, g ",[53,326,200],{"class":93},[53,328,203],{"class":97},[53,330,286],{"class":63},[53,332,208],{"class":97},[53,334,335,338,341,343,346,348,350,352,355,357,359,362,364,366,369,372,374,376,378],{"class":55,"line":132},[53,336,337],{"class":97},"        g.drop(",[53,339,340],{"class":217},"columns",[53,342,120],{"class":93},[53,344,345],{"class":97},"[",[53,347,138],{"class":63},[53,349,17],{"class":97},[53,351,286],{"class":63},[53,353,354],{"class":97},"]).to_excel(xw, ",[53,356,218],{"class":217},[53,358,120],{"class":93},[53,360,361],{"class":97},"period.strftime(",[53,363,155],{"class":63},[53,365,159],{"class":158},[53,367,368],{"class":63}," %Y\"",[53,370,371],{"class":97},"), ",[53,373,226],{"class":217},[53,375,120],{"class":93},[53,377,232],{"class":231},[53,379,129],{"class":97},[53,381,382,384,386,388,390,392],{"class":55,"line":166},[53,383,174],{"class":93},[53,385,242],{"class":97},[53,387,311],{"class":63},[53,389,183],{"class":97},[53,391,101],{"class":93},[53,393,251],{"class":97},[53,395,396,398],{"class":55,"line":171},[53,397,257],{"class":231},[53,399,260],{"class":97},[10,401,402,403,406,407,409,410,413],{},"A monthly ",[50,404,405],{},"Period"," sorts chronologically and also carries the year, which avoids a second problem when the data spans more than one year: two sheets called ",[14,408,29],{}," for different years. The same applies to any categorical order that is not alphabetical — sizes, priority levels, regions in a fixed reporting order: group by an ordered key, such as an ordered ",[50,411,412],{},"Categorical",", or loop over an explicit list.",[415,416,424,425,424,429,424,433,424,441,424,451,424,458,424,464,424,469,424,473,424,477,424,482,424,487,424,491,424,494,424,497],"svg",{"viewBox":417,"role":418,"ariaLabelledBy":419,"xmlns":422,"style":423},"4 0 752 173","img",[420,421],"so-groupby-t","so-groupby-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[426,427,428],"title",{"id":420},"Grouping by name or by period",[430,431,432],"desc",{"id":421},"Grouping by month name sorts the keys alphabetically, giving April, August, December and so on. Grouping by a monthly period sorts them in time, January to December, and keeps the year in the sheet name.",[434,435],"rect",{"x":436,"y":437,"width":438,"height":439,"fill":440},"4","0","752","173","#ffffff",[434,442],{"x":443,"y":444,"width":445,"height":446,"rx":447,"fill":448,"stroke":449,"style":450},"20.0","16.0","351.0","141.0","14","#fce9e9","var(--danger,#dc2626)","stroke-width:2px",[452,453,457],"text",{"x":454,"y":455,"style":456},"195.5","44.0","font-size:14px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle","groupby(\"Month\") — names",[55,459],{"x1":460,"y1":461,"x2":462,"y2":461,"stroke":449,"style":463},"36.0","57.0","355.0","stroke-width:1px",[452,465,468],{"x":454,"y":466,"style":467},"77.0","font-size:12px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","Apr, Aug, Dec, Feb, Jan…",[452,470,472],{"x":454,"y":471,"style":467},"103.0","alphabetical order",[452,474,476],{"x":454,"y":475,"style":467},"129.0","Jan of two years collide",[434,478],{"x":479,"y":444,"width":445,"height":446,"rx":447,"fill":480,"stroke":481,"style":450},"389.0","#d9f4f1","var(--teal,#0f9488)",[452,483,486],{"x":484,"y":455,"style":485},"564.5","font-size:14px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","groupby(\"Period\") — periods",[55,488],{"x1":489,"y1":461,"x2":490,"y2":461,"stroke":481,"style":463},"405.0","724.0",[452,492,493],{"x":484,"y":466,"style":467},"Jan 2026, Feb 2026, …",[452,495,496],{"x":484,"y":471,"style":467},"chronological order",[452,498,499],{"x":484,"y":475,"style":467},"year in every name",[38,501,503],{"id":502},"cause-2-sets-and-unordered-collections","Cause 2 — Sets and unordered collections",[43,505,507],{"className":84,"code":506,"language":86,"meta":48,"style":48},"regions = {\"North\", \"South\", \"East\", \"West\"}            # a set: no defined order\nprint(list(regions))\nORDER = [\"North\", \"South\", \"East\", \"West\"]               # the order the business reports in\nprint([r for r in ORDER if r in regions])\n",[50,508,509,544,558,589],{"__ignoreMap":48},[53,510,511,514,516,519,522,524,527,529,532,534,537,540],{"class":55,"line":56},[53,512,513],{"class":97},"regions ",[53,515,120],{"class":93},[53,517,518],{"class":97}," {",[53,520,521],{"class":63},"\"North\"",[53,523,17],{"class":97},[53,525,526],{"class":63},"\"South\"",[53,528,17],{"class":97},[53,530,531],{"class":63},"\"East\"",[53,533,17],{"class":97},[53,535,536],{"class":63},"\"West\"",[53,538,539],{"class":97},"}            ",[53,541,543],{"class":542},"s-wDw","# a set: no defined order\n",[53,545,546,549,552,555],{"class":55,"line":107},[53,547,548],{"class":231},"print",[53,550,551],{"class":97},"(",[53,553,554],{"class":231},"list",[53,556,557],{"class":97},"(regions))\n",[53,559,560,563,566,569,571,573,575,577,579,581,583,586],{"class":55,"line":114},[53,561,562],{"class":231},"ORDER",[53,564,565],{"class":93}," =",[53,567,568],{"class":97}," [",[53,570,521],{"class":63},[53,572,17],{"class":97},[53,574,526],{"class":63},[53,576,17],{"class":97},[53,578,531],{"class":63},[53,580,17],{"class":97},[53,582,536],{"class":63},[53,584,585],{"class":97},"]               ",[53,587,588],{"class":542},"# the order the business reports in\n",[53,590,591,593,596,599,602,604,607,610,612,614],{"class":55,"line":132},[53,592,548],{"class":231},[53,594,595],{"class":97},"([r ",[53,597,598],{"class":93},"for",[53,600,601],{"class":97}," r ",[53,603,200],{"class":93},[53,605,606],{"class":231}," ORDER",[53,608,609],{"class":93}," if",[53,611,601],{"class":97},[53,613,200],{"class":93},[53,615,616],{"class":97}," regions])\n",[10,618,619,620,623,624,627],{},"Sheet names collected in a set — often from ",[50,621,622],{},"set(df[\"Region\"])"," or ",[50,625,626],{},"df[\"Region\"].unique()"," passed through a set to remove duplicates — come back in an order that has nothing to do with how the business reads the report, and string sets can even change order between runs, because Python randomises string hashing per process. Dictionaries keep insertion order, so a dictionary built in the right order is safe; a set is not. When the order matters, loop over an explicit list and keep only the names that occur in the data, as the second line does — the result is the same on every run, and a region that appears in the data but not in the list can be reported rather than placed somewhere arbitrary.",[38,629,631],{"id":630},"cause-3-appending-to-an-existing-workbook","Cause 3 — Appending to an existing workbook",[43,633,635],{"className":84,"code":634,"language":86,"meta":48,"style":48},"summary = sales.groupby(\"Period\")[\"Revenue\"].sum().rename_axis(\"Month\").reset_index()\nsummary[\"Month\"] = summary[\"Month\"].dt.strftime(\"%b %Y\")\nwith pd.ExcelWriter(\"by_month.xlsx\", mode=\"a\", engine=\"openpyxl\", if_sheet_exists=\"replace\") as xw:\n    summary.to_excel(xw, sheet_name=\"Summary\", index=False)\nwith pd.ExcelFile(\"by_month.xlsx\") as f:\n    print(f.sheet_names[:3], \"…\", f.sheet_names[-2:])\n",[50,636,637,662,688,732,754,768],{"__ignoreMap":48},[53,638,639,642,644,646,648,651,654,657,659],{"class":55,"line":56},[53,640,641],{"class":97},"summary ",[53,643,120],{"class":93},[53,645,203],{"class":97},[53,647,286],{"class":63},[53,649,650],{"class":97},")[",[53,652,653],{"class":63},"\"Revenue\"",[53,655,656],{"class":97},"].sum().rename_axis(",[53,658,138],{"class":63},[53,660,661],{"class":97},").reset_index()\n",[53,663,664,667,669,671,673,676,678,680,682,684,686],{"class":55,"line":107},[53,665,666],{"class":97},"summary[",[53,668,138],{"class":63},[53,670,141],{"class":97},[53,672,120],{"class":93},[53,674,675],{"class":97}," summary[",[53,677,138],{"class":63},[53,679,152],{"class":97},[53,681,155],{"class":63},[53,683,159],{"class":158},[53,685,368],{"class":63},[53,687,129],{"class":97},[53,689,690,692,694,696,698,701,703,706,708,711,713,716,718,721,723,726,728,730],{"class":55,"line":114},[53,691,174],{"class":93},[53,693,177],{"class":97},[53,695,311],{"class":63},[53,697,17],{"class":97},[53,699,700],{"class":217},"mode",[53,702,120],{"class":93},[53,704,705],{"class":63},"\"a\"",[53,707,17],{"class":97},[53,709,710],{"class":217},"engine",[53,712,120],{"class":93},[53,714,715],{"class":63},"\"openpyxl\"",[53,717,17],{"class":97},[53,719,720],{"class":217},"if_sheet_exists",[53,722,120],{"class":93},[53,724,725],{"class":63},"\"replace\"",[53,727,183],{"class":97},[53,729,101],{"class":93},[53,731,188],{"class":97},[53,733,734,737,739,741,744,746,748,750,752],{"class":55,"line":132},[53,735,736],{"class":97},"    summary.to_excel(xw, ",[53,738,218],{"class":217},[53,740,120],{"class":93},[53,742,743],{"class":63},"\"Summary\"",[53,745,17],{"class":97},[53,747,226],{"class":217},[53,749,120],{"class":93},[53,751,232],{"class":231},[53,753,129],{"class":97},[53,755,756,758,760,762,764,766],{"class":55,"line":166},[53,757,174],{"class":93},[53,759,242],{"class":97},[53,761,311],{"class":63},[53,763,183],{"class":97},[53,765,101],{"class":93},[53,767,251],{"class":97},[53,769,770,772,775,778,781,784,787,790,793],{"class":55,"line":171},[53,771,257],{"class":231},[53,773,774],{"class":97},"(f.sheet_names[:",[53,776,777],{"class":231},"3",[53,779,780],{"class":97},"], ",[53,782,783],{"class":63},"\"…\"",[53,785,786],{"class":97},", f.sheet_names[",[53,788,789],{"class":93},"-",[53,791,792],{"class":231},"2",[53,794,795],{"class":97},":])\n",[10,797,798,801,802,805],{},[50,799,800],{},"mode=\"a\""," opens an existing workbook and adds to it, and a new sheet goes at the end — so a summary added to a finished monthly workbook lands after December. pandas has no option to insert a sheet at a position. (Replacing a sheet that already exists with ",[50,803,804],{},"if_sheet_exists=\"replace\""," keeps it where it was in current pandas versions; it is new sheets that are added at the end.) The simplest fix is to write the workbook in one pass with the summary first. When the workbook already exists and must be updated rather than rewritten, reorder it afterwards.",[38,807,809],{"id":808},"step-4-reorder-an-existing-workbook-with-openpyxl","Step 4 — Reorder an existing workbook with openpyxl",[43,811,813],{"className":84,"code":812,"language":86,"meta":48,"style":48},"from openpyxl import load_workbook\n\nwb = load_workbook(\"by_month.xlsx\")\nwb.move_sheet(\"Summary\", offset=-wb.sheetnames.index(\"Summary\"))      # move to the front\nwb.active = 0                                                          # open on the summary\nfor ws in wb.worksheets:\n    ws.sheet_view.tabSelected = ws is wb.active                        # only one tab selected\nwb.save(\"by_month.xlsx\")\nprint(load_workbook(\"by_month.xlsx\").sheetnames[:4])\n",[50,814,815,828,832,846,872,885,897,915,924],{"__ignoreMap":48},[53,816,817,820,823,825],{"class":55,"line":56},[53,818,819],{"class":93},"from",[53,821,822],{"class":97}," openpyxl ",[53,824,94],{"class":93},[53,826,827],{"class":97}," load_workbook\n",[53,829,830],{"class":55,"line":107},[53,831,111],{"emptyLinePlaceholder":110},[53,833,834,837,839,842,844],{"class":55,"line":114},[53,835,836],{"class":97},"wb ",[53,838,120],{"class":93},[53,840,841],{"class":97}," load_workbook(",[53,843,311],{"class":63},[53,845,129],{"class":97},[53,847,848,851,853,855,858,861,864,866,869],{"class":55,"line":132},[53,849,850],{"class":97},"wb.move_sheet(",[53,852,743],{"class":63},[53,854,17],{"class":97},[53,856,857],{"class":217},"offset",[53,859,860],{"class":93},"=-",[53,862,863],{"class":97},"wb.sheetnames.index(",[53,865,743],{"class":63},[53,867,868],{"class":97},"))      ",[53,870,871],{"class":542},"# move to the front\n",[53,873,874,877,879,882],{"class":55,"line":166},[53,875,876],{"class":97},"wb.active ",[53,878,120],{"class":93},[53,880,881],{"class":231}," 0",[53,883,884],{"class":542},"                                                          # open on the summary\n",[53,886,887,889,892,894],{"class":55,"line":171},[53,888,598],{"class":93},[53,890,891],{"class":97}," ws ",[53,893,200],{"class":93},[53,895,896],{"class":97}," wb.worksheets:\n",[53,898,899,902,904,906,909,912],{"class":55,"line":191},[53,900,901],{"class":97},"    ws.sheet_view.tabSelected ",[53,903,120],{"class":93},[53,905,891],{"class":97},[53,907,908],{"class":93},"is",[53,910,911],{"class":97}," wb.active                        ",[53,913,914],{"class":542},"# only one tab selected\n",[53,916,917,920,922],{"class":55,"line":211},[53,918,919],{"class":97},"wb.save(",[53,921,311],{"class":63},[53,923,129],{"class":97},[53,925,926,928,931,933,936,938],{"class":55,"line":237},[53,927,548],{"class":231},[53,929,930],{"class":97},"(load_workbook(",[53,932,311],{"class":63},[53,934,935],{"class":97},").sheetnames[:",[53,937,436],{"class":231},[53,939,940],{"class":97},"])\n",[10,942,943,946,947,950,951,954,955,958],{},[50,944,945],{},"move_sheet"," moves one sheet by an offset, so moving it to the front is an offset of minus its current position. For a full reorder — say, a desired list of names — sorting the workbook's internal list by position in that list does it in one line, ",[50,948,949],{},"wb._sheets.sort(key=desired.index)","; the underscore marks it as internal to openpyxl, but it is the documented way people reorder many sheets at once and it is stable across versions. After moving sheets, set ",[50,952,953],{},"wb.active"," to the sheet the reader should see first, and make sure only that tab is marked selected: a workbook saved with several tabs selected opens in Excel with the sheets ",[14,956,957],{},"grouped",", and anything typed then goes into all of them.",[415,960,424,965,424,968,424,971,424,974,424,979,424,985,424,989,424,994,424,998,424,1004,424,1009,424,1014,424,1019,424,1022,424,1025,424,1028,424,1032,424,1035,424,1039,424,1045,424,1049,424,1053,424,1057,424,1060,424,1063,424,1067,424,1070,424,1073,424,1076,424,1080,424,1083,424,1088,424,1093,424,1096,424,1099],{"viewBox":961,"role":418,"ariaLabelledBy":962,"xmlns":422,"style":423},"4 0 752 126",[963,964],"so-fix-t","so-fix-d",[426,966,967],{"id":963},"Getting the order right",[430,969,970],{"id":964},"The best fix is to write sheets in the intended order in one pass. If the workbook already exists, reorder it with openpyxl, by moving one sheet or sorting the whole list, then set the active sheet and make sure only one tab is selected.",[434,972],{"x":436,"y":437,"width":438,"height":973,"fill":440},"126",[434,975],{"x":443,"y":444,"width":976,"height":977,"rx":978,"fill":480,"stroke":481,"style":450},"115.2","94.0","12",[452,980,984],{"x":981,"y":982,"style":983},"77.6","41.5","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Write in",[452,986,988],{"x":981,"y":987,"style":983},"59.0","order",[452,990,993],{"x":981,"y":991,"style":992},"78.5","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","one pass,",[452,995,997],{"x":981,"y":996,"style":992},"96.0","summary first",[55,999],{"x1":1000,"y1":1001,"x2":1002,"y2":1001,"stroke":1003,"style":450},"140.2","63.0","162.2","var(--brand,#5b5cf0)",[1005,1006],"polygon",{"points":1007,"fill":1008},"166.2,63.0 157.2,68.0 157.2,58.0","#5b5cf0",[434,1010],{"x":1011,"y":444,"width":976,"height":977,"rx":978,"fill":1012,"stroke":1013,"style":450},"171.2","#fdefd8","var(--gold,#b4740a)",[452,1015,1018],{"x":1016,"y":982,"style":1017},"228.8","font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","Existing",[452,1020,1021],{"x":1016,"y":987,"style":1017},"workbook?",[452,1023,1024],{"x":1016,"y":991,"style":992},"reorder with",[452,1026,1027],{"x":1016,"y":996,"style":992},"openpyxl",[55,1029],{"x1":1030,"y1":1001,"x2":1031,"y2":1001,"stroke":1003,"style":450},"291.4","313.4",[1005,1033],{"points":1034,"fill":1008},"317.4,63.0 308.4,68.0 308.4,58.0",[434,1036],{"x":1037,"y":444,"width":976,"height":977,"rx":978,"fill":1038,"stroke":1003,"style":450},"322.4","#f0f4ff",[452,1040,1044],{"x":1041,"y":1042,"style":1043},"380.0","50.2","font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","move_sheet \u002F",[452,1046,1048],{"x":1041,"y":1047,"style":1043},"67.8","sort",[452,1050,1052],{"x":1041,"y":1051,"style":992},"87.2","one sheet or all",[55,1054],{"x1":1055,"y1":1001,"x2":1056,"y2":1001,"stroke":1003,"style":450},"442.6","464.6",[1005,1058],{"points":1059,"fill":1008},"468.6,63.0 459.6,68.0 459.6,58.0",[434,1061],{"x":1062,"y":444,"width":976,"height":977,"rx":978,"fill":1038,"stroke":1003,"style":450},"473.6",[452,1064,1066],{"x":1065,"y":982,"style":1043},"531.2","Set active",[452,1068,1069],{"x":1065,"y":987,"style":1043},"sheet",[452,1071,1072],{"x":1065,"y":991,"style":992},"the one to open",[452,1074,1075],{"x":1065,"y":996,"style":992},"on",[55,1077],{"x1":1078,"y1":1001,"x2":1079,"y2":1001,"stroke":1003,"style":450},"593.8","615.8",[1005,1081],{"points":1082,"fill":1008},"619.8,63.0 610.8,68.0 610.8,58.0",[434,1084],{"x":1085,"y":444,"width":976,"height":977,"rx":978,"fill":1086,"stroke":1087,"style":450},"624.8","#e7ebef","var(--line,#cdd5e6)",[452,1089,1092],{"x":1090,"y":982,"style":1091},"682.4","font-size:13.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","One tab",[452,1094,1095],{"x":1090,"y":987,"style":1091},"selected",[452,1097,1098],{"x":1090,"y":991,"style":992},"avoid grouped",[452,1100,1101],{"x":1090,"y":996,"style":992},"sheets",[38,1103,1105],{"id":1104},"with-xlsxwriter-and-when-other-code-reads-by-position","With XlsxWriter, and when other code reads by position",[10,1107,1108,1109,1112,1113,1116],{},"With the XlsxWriter engine the same rule holds even more strictly: sheets appear in the order they are added, and because XlsxWriter only writes new files, there is no reordering afterwards — the fix is always to add them in the right order. Its ",[50,1110,1111],{},"activate()"," method chooses the sheet that opens first, and ",[50,1114,1115],{},"set_first_sheet()"," chooses which tab is scrolled into view at the left of the tab bar, which matters in a workbook with more tabs than fit on screen.",[10,1118,1119,1120,1123,1124,1127,1128,1131],{},"Sheet order also matters to code that reads the workbook later. ",[50,1121,1122],{},"pd.read_excel(path, sheet_name=0)"," reads the ",[14,1125,1126],{},"first"," sheet, whatever it is called, so moving a summary to the front silently changes what such a script reads. Downstream code should read sheets by name — ",[50,1129,1130],{},"sheet_name=\"Summary\""," — which keeps working whatever order the tabs end up in, and is one more reason to fix the order deliberately rather than leave it to chance. Hidden sheets keep their position in the order too, so a hidden lookup sheet at the front would become sheet 0 for any script that reads by position.",[38,1133,1135],{"id":1134},"step-5-test-the-order","Step 5 — Test the order",[43,1137,1139],{"className":84,"code":1138,"language":86,"meta":48,"style":48},"expected = [\"Summary\"] + [p.strftime(\"%b %Y\") for p in pd.period_range(\"2026-01\", \"2026-12\", freq=\"M\")]\nactual = load_workbook(\"by_month.xlsx\", read_only=True).sheetnames\nassert actual == expected, f\"sheet order wrong: {actual}\"\nprint(\"sheet order OK:\", actual[:3], \"…\", actual[-1])\n",[50,1140,1141,1198,1222,1254],{"__ignoreMap":48},[53,1142,1143,1146,1148,1150,1152,1154,1157,1160,1162,1164,1166,1168,1170,1173,1175,1178,1181,1183,1186,1188,1191,1193,1195],{"class":55,"line":56},[53,1144,1145],{"class":97},"expected ",[53,1147,120],{"class":93},[53,1149,568],{"class":97},[53,1151,743],{"class":63},[53,1153,141],{"class":97},[53,1155,1156],{"class":93},"+",[53,1158,1159],{"class":97}," [p.strftime(",[53,1161,155],{"class":63},[53,1163,159],{"class":158},[53,1165,368],{"class":63},[53,1167,183],{"class":97},[53,1169,598],{"class":93},[53,1171,1172],{"class":97}," p ",[53,1174,200],{"class":93},[53,1176,1177],{"class":97}," pd.period_range(",[53,1179,1180],{"class":63},"\"2026-01\"",[53,1182,17],{"class":97},[53,1184,1185],{"class":63},"\"2026-12\"",[53,1187,17],{"class":97},[53,1189,1190],{"class":217},"freq",[53,1192,120],{"class":93},[53,1194,300],{"class":63},[53,1196,1197],{"class":97},")]\n",[53,1199,1200,1203,1205,1207,1209,1211,1214,1216,1219],{"class":55,"line":107},[53,1201,1202],{"class":97},"actual ",[53,1204,120],{"class":93},[53,1206,841],{"class":97},[53,1208,311],{"class":63},[53,1210,17],{"class":97},[53,1212,1213],{"class":217},"read_only",[53,1215,120],{"class":93},[53,1217,1218],{"class":231},"True",[53,1220,1221],{"class":97},").sheetnames\n",[53,1223,1224,1227,1230,1233,1236,1239,1242,1245,1248,1251],{"class":55,"line":114},[53,1225,1226],{"class":93},"assert",[53,1228,1229],{"class":97}," actual ",[53,1231,1232],{"class":93},"==",[53,1234,1235],{"class":97}," expected, ",[53,1237,1238],{"class":93},"f",[53,1240,1241],{"class":63},"\"sheet order wrong: ",[53,1243,1244],{"class":158},"{",[53,1246,1247],{"class":97},"actual",[53,1249,1250],{"class":158},"}",[53,1252,1253],{"class":63},"\"\n",[53,1255,1256,1258,1260,1263,1266,1268,1270,1272,1275,1277,1280],{"class":55,"line":132},[53,1257,548],{"class":231},[53,1259,551],{"class":97},[53,1261,1262],{"class":63},"\"sheet order OK:\"",[53,1264,1265],{"class":97},", actual[:",[53,1267,777],{"class":231},[53,1269,780],{"class":97},[53,1271,783],{"class":63},[53,1273,1274],{"class":97},", actual[",[53,1276,789],{"class":93},[53,1278,1279],{"class":231},"1",[53,1281,940],{"class":97},[10,1283,1284,1285,1288,1289,36],{},"Sheet order is easy to break again later — someone adds a sheet in the middle of the code, or changes a group key — so it is worth a one-line assertion in the report's tests: the expected list of sheet names, built from the same rules as the report, compared with the workbook's ",[50,1286,1287],{},"sheetnames",". Opening the file in read-only mode makes the check fast even for large workbooks. The broader approach to testing report output is in ",[32,1290,1292],{"href":1291},"\u002Fautomating-reporting-workflows\u002Ftesting-and-packaging-excel-automation-scripts\u002Ftest-excel-output-with-pytest\u002F","Test Excel Output with pytest",[415,1294,424,1300,424,1303,424,1306,424,1311,424,1316,424,1320,424,1326,424,1330,424,1334,424,1338,424,1342,424,1346,424,1350,424,1353,424,1357,424,1361,424,1365,424,1369,424,1372,424,1374,424,1377,424,1379,424,1381,424,1383,424,1385,424,1387,424,1389,424,1391,424,1394,424,1396,424,1399,424,1402,424,1405,424,1408,424,1411,424,1413,424,1416,424,1418,424,1421,424,1423,424,1426,424,1428,424,1430,424,1432],{"viewBox":1295,"role":418,"ariaLabelledBy":1296,"xmlns":422,"style":1299},"118 0 523 112",[1297,1298],"so-result-t","so-result-d","width:100%;max-width:523px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[426,1301,1302],{"id":1297},"The final tab order",[430,1304,1305],{"id":1298},"The workbook opens on the Summary sheet, followed by one sheet per month from Jan 2026 to Dec 2026 in calendar order.",[434,1307],{"x":1308,"y":437,"width":1309,"height":1310,"fill":440},"118","523","112",[434,1312],{"x":1313,"y":444,"width":1314,"height":1315,"rx":437,"fill":1086,"stroke":1087,"style":463},"134.6","32.0","24.0",[434,1317],{"x":1318,"y":444,"width":1319,"height":1315,"rx":437,"fill":1086,"stroke":1087,"style":463},"166.6","83.1",[452,1321,1325],{"x":1322,"y":1323,"style":1324},"208.1","33.0","font-size:11px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","A",[434,1327],{"x":1328,"y":444,"width":1329,"height":1315,"rx":437,"fill":1086,"stroke":1087,"style":463},"249.7","82.1",[452,1331,1333],{"x":1332,"y":1323,"style":1324},"290.7","B",[434,1335],{"x":1336,"y":444,"width":1337,"height":1315,"rx":437,"fill":1086,"stroke":1087,"style":463},"331.8","82.4",[452,1339,1341],{"x":1340,"y":1323,"style":1324},"373.0","C",[434,1343],{"x":1344,"y":444,"width":1345,"height":1315,"rx":437,"fill":1086,"stroke":1087,"style":463},"414.2","83.7",[452,1347,1349],{"x":1348,"y":1323,"style":1324},"456.0","D",[434,1351],{"x":1352,"y":444,"width":455,"height":1315,"rx":437,"fill":1086,"stroke":1087,"style":463},"497.9",[452,1354,1356],{"x":1355,"y":1323,"style":1324},"519.9","E",[434,1358],{"x":1359,"y":444,"width":1360,"height":1315,"rx":437,"fill":1086,"stroke":1087,"style":463},"541.9","83.5",[452,1362,1364],{"x":1363,"y":1323,"style":1324},"583.7","F",[434,1366],{"x":1313,"y":1367,"width":1314,"height":1368,"rx":437,"fill":1086,"stroke":1087,"style":463},"40.0","28.0",[452,1370,1279],{"x":1371,"y":987,"style":1324},"150.6",[434,1373],{"x":1318,"y":1367,"width":1319,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1375,1279],{"x":1322,"y":987,"style":1376},"font-size:12px;font-weight:700;fill:var(--text,#172033);text-anchor:middle",[434,1378],{"x":1328,"y":1367,"width":1329,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1380,792],{"x":1332,"y":987,"style":1376},[434,1382],{"x":1336,"y":1367,"width":1337,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1384,777],{"x":1340,"y":987,"style":1376},[434,1386],{"x":1344,"y":1367,"width":1345,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1388,436],{"x":1348,"y":987,"style":1376},[434,1390],{"x":1352,"y":1367,"width":455,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1392,1393],{"x":1355,"y":987,"style":1376},"…",[434,1395],{"x":1359,"y":1367,"width":1360,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1397,1398],{"x":1363,"y":987,"style":1376},"13",[434,1400],{"x":1313,"y":1401,"width":1314,"height":1368,"rx":437,"fill":1086,"stroke":1087,"style":463},"68.0",[452,1403,792],{"x":1371,"y":1404,"style":1324},"87.0",[434,1406],{"x":1318,"y":1401,"width":1319,"height":1368,"rx":437,"fill":480,"stroke":481,"style":1407},"stroke-width:1.5px",[452,1409,76],{"x":1322,"y":1404,"style":1410},"font-size:12px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle",[434,1412],{"x":1328,"y":1401,"width":1329,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1414,1415],{"x":1332,"y":1404,"style":467},"Jan 2026",[434,1417],{"x":1336,"y":1401,"width":1337,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1419,1420],{"x":1340,"y":1404,"style":467},"Feb 2026",[434,1422],{"x":1344,"y":1401,"width":1345,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1424,1425],{"x":1348,"y":1404,"style":467},"Mar 2026",[434,1427],{"x":1352,"y":1401,"width":455,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1429,1393],{"x":1355,"y":1404,"style":467},[434,1431],{"x":1359,"y":1401,"width":1360,"height":1368,"rx":437,"fill":440,"stroke":1087,"style":463},[452,1433,1434],{"x":1363,"y":1404,"style":467},"Dec 2026",[38,1436,1438],{"id":1437},"common-pitfalls","Common pitfalls",[1440,1441,1442,1450,1456,1464,1473],"ul",{},[1443,1444,1445,1449],"li",{},[1446,1447,1448],"strong",{},"Grouping by month names."," Group by a period or month number; use the name only as the title.",[1443,1451,1452,1455],{},[1446,1453,1454],{},"Collecting sheet names in a set."," Loop over an explicit, ordered list.",[1443,1457,1458,1463],{},[1446,1459,1460,1461,36],{},"Appending a summary with ",[50,1462,800],{}," It goes last; write in one pass or reorder.",[1443,1465,1466,1469,1470,1472],{},[1446,1467,1468],{},"Forgetting the active sheet."," Set ",[50,1471,953],{}," after reordering.",[1443,1474,1475,1478,1479,1482],{},[1446,1476,1477],{},"Several tabs selected."," Clear ",[50,1480,1481],{},"tabSelected"," on all but the active sheet.",[38,1484,1486],{"id":1485},"conclusion","Conclusion",[10,1488,1489,1490,1492],{},"pandas writes sheets in the order the code writes them, so a wrong tab order comes from the code: alphabetical group keys such as month names, unordered sets of names, or sheets appended to an existing workbook. Group by periods or loop over an explicit list to write in the right order, write the summary first in a single pass, or reorder an existing workbook with openpyxl's ",[50,1491,945],{}," or by sorting its sheet list; then set the active sheet and assert the order in a test.",[38,1494,1496],{"id":1495},"frequently-asked-questions","Frequently asked questions",[10,1498,1499,1502,1504],{},[1446,1500,1501],{},"Why are my monthly sheets in alphabetical order?",[50,1503,265],{}," sorts month names as text; group by a monthly period or month number instead.",[10,1506,1507,1510,1511,36],{},[1446,1508,1509],{},"How do I move a sheet to the front with openpyxl?","\nUse ",[50,1512,1513],{},"wb.move_sheet(\"Summary\", offset=-wb.sheetnames.index(\"Summary\"))",[10,1515,1516,1519,1522],{},[1446,1517,1518],{},"Why does a new sheet appear at the end when I append with pandas?",[50,1520,1521],{},"ExcelWriter(mode=\"a\")"," adds new sheets after the existing ones; reorder with openpyxl afterwards or write the file in one pass.",[10,1524,1525,1528,1529,1531,1532,1534],{},[1446,1526,1527],{},"How do I choose which sheet opens first?","\nSet ",[50,1530,953],{}," to the sheet's index and make sure only that sheet has ",[50,1533,1481],{}," set.",[38,1536,1538],{"id":1537},"related","Related",[1440,1540,1541,1547,1554,1561],{},[1443,1542,1543,1544,1546],{},"Up one level: ",[32,1545,35],{"href":34}," — common errors and fixes.",[1443,1548,1549,1553],{},[32,1550,1552],{"href":1551},"\u002Fgetting-started-with-python-excel-automation\u002Fworking-with-multiple-excel-sheets-in-python\u002Frename-reorder-and-delete-excel-sheets-with-openpyxl\u002F","Rename, Reorder and Delete Excel Sheets with openpyxl"," — sheet management.",[1443,1555,1556,1560],{},[32,1557,1559],{"href":1558},"\u002Fgetting-started-with-python-excel-automation\u002Fworking-with-multiple-excel-sheets-in-python\u002Fcreate-a-sheet-for-each-group-in-a-dataframe\u002F","Create a Sheet for Each Group in a DataFrame"," — one sheet per group.",[1443,1562,1563,1567],{},[32,1564,1566],{"href":1565},"\u002Fautomating-reporting-workflows\u002Fbuilding-multi-sheet-excel-dashboards\u002Fwrite-multiple-dataframes-to-one-excel-file\u002F","Write Multiple DataFrames to One Excel File"," — writing in one pass.",[1569,1570,1571],"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 .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 .sP0c6, html code.shiki .sP0c6{--shiki-default:#005CC5;--shiki-dark:#91CBFF}html pre.shiki code .s-wDw, html code.shiki .s-wDw{--shiki-default:#6A737D;--shiki-dark:#BDC4CC}",{"title":48,"searchDepth":107,"depth":107,"links":1573},[1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584],{"id":40,"depth":107,"text":41},{"id":80,"depth":107,"text":81},{"id":502,"depth":107,"text":503},{"id":630,"depth":107,"text":631},{"id":808,"depth":107,"text":809},{"id":1104,"depth":107,"text":1105},{"id":1134,"depth":107,"text":1135},{"id":1437,"depth":107,"text":1438},{"id":1485,"depth":107,"text":1486},{"id":1495,"depth":107,"text":1496},{"id":1537,"depth":107,"text":1538},"2026-10-02","Sheets come out as Apr, Aug, Dec, Feb… or the summary ends up last after appending to a workbook. Find which of the usual causes applies — alphabetical group keys, sets and unsorted dictionaries, sheets appended to an existing file — write the sheets in the order you want, or reorder an existing workbook with openpyxl, set the sheet that opens first, and check the final order in a test.","md",[1589,1591,1593,1595],{"q":1501,"a":1590},"groupby sorts month names as text; group by a monthly period or month number instead.",{"q":1509,"a":1592},"Use wb.move_sheet(\"Summary\", offset=-wb.sheetnames.index(\"Summary\")).",{"q":1518,"a":1594},"ExcelWriter(mode=\"a\") adds new sheets after the existing ones; reorder with openpyxl afterwards or write the file in one pass.",{"q":1527,"a":1596},"Set wb.active to the sheet's index and make sure only that sheet has tabSelected set.","excel sheet order pandas",null,{"breadcrumb":1600},[1601,1604,1607],{"name":1602,"item":1603},"Home","\u002F",{"name":1605,"item":1606},"Getting Started with Python Excel Automation","\u002Fgetting-started-with-python-excel-automation\u002F",{"name":35,"item":34},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas",{"title":1610,"description":1611},"Fix Wrong Sheet Order After Writing Excel with pandas","Fix sheet order in Excel files written by pandas: months sorted alphabetically, groupby key order, sets, appended sheets at the end, reordering with openpyxl move_sheet and _sheets, and the active sheet.","fix-wrong-sheet-order-after-writing-with-pandas","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-wrong-sheet-order-after-writing-with-pandas\u002Findex",[1615,1616],"troubleshooting","writing-excel","how-to","LnSe1_o2uAje-HdotHuMSG3luIleEwAUIfJk3jjdZmo",[1620,1624],{"title":1621,"path":1622,"stem":1623,"children":-1},"Fix \"Worksheet index 0 is invalid, 0 worksheets found\"","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-worksheet-index-0-is-invalid-0-worksheets-found","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-worksheet-index-0-is-invalid-0-worksheets-found\u002Findex",{"title":1625,"path":1626,"stem":1627,"children":-1},"Fix \"XLRDError: Excel xlsx file; not supported\" in Python","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-xlrderror-excel-xlsx-file-not-supported","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-xlrderror-excel-xlsx-file-not-supported\u002Findex",[1629,1631],{"path":1630,"title":1605},"\u002Fgetting-started-with-python-excel-automation",{"path":1632,"title":35},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors",[],[1635,1639,1642,1645,1648,1651],{"path":1636,"title":1637,"kind":1638},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation\u002Fhandle-permission-denied-when-writing-excel-in-python","Handle Permission Denied When Writing Excel in Python","fix",{"path":1640,"title":1641,"kind":1617},"\u002Fgetting-started-with-python-excel-automation\u002Fusing-openpyxl-for-excel-file-manipulation\u002Fwhat-openpyxl-loses-when-saving-an-existing-workbook","What openpyxl Loses When You Save an Existing Workbook",{"path":1643,"title":1644,"kind":1638},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-dates-and-times-in-excel-data\u002Ffix-excel-serial-numbers-showing-instead-of-dates","Fix Excel Serial Numbers Showing Instead of Dates",{"path":1646,"title":1647,"kind":1617},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-dates-and-times-in-excel-data\u002Fhandle-daylight-saving-time-in-excel-timestamps","Handle Daylight Saving Time in Excel Timestamps",{"path":1649,"title":1650,"kind":1617},"\u002Fautomating-reporting-workflows\u002Fautomating-excel-online-with-microsoft-graph\u002Fhandle-microsoft-graph-throttling-for-excel","Handle Microsoft Graph Throttling in Excel Automation",{"path":1652,"title":1653,"kind":1654},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation","Error Handling and Logging in Excel Automation","guide",1790972067759]