[{"data":1,"prerenderedAt":1925},["ShallowReactive",2],{"doc:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter":3,"surround:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter":1889,"ancestors:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter":1898,"children:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter":1903,"related:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter":1904},{"id":4,"title":5,"body":6,"dateModified":1855,"datePublished":1855,"description":1856,"extension":1857,"faq":1858,"keyword":1867,"kind":1868,"meta":1869,"navigation":127,"path":1877,"seo":1878,"slug":1881,"stem":1882,"topics":1883,"type":1887,"__hash__":1888},"docs\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter\u002Findex.md","Fix \"Filesize would require ZIP64 extensions\" (LargeZipFile) in XlsxWriter",{"type":7,"value":8,"toc":1841},"minimark",[9,13,24,46,51,77,84,88,105,193,207,323,327,598,611,615,620,735,745,751,937,941,948,1267,1270,1349,1353,1356,1397,1527,1531,1534,1683,1690,1694,1701,1705,1756,1760,1776,1780,1786,1792,1798,1804,1808,1837],[10,11,12],"p",{},"A nightly export that has run for months suddenly fails at the very end — after minutes of writing — with:",[14,15,21],"pre",{"className":16,"code":18,"language":19,"meta":20},[17],"language-text","xlsxwriter.exceptions.FileSizeError: Filesize would require ZIP64 extensions. Use workbook.use_zip64().\n","text","",[22,23,18],"code",{"__ignoreMap":20},[10,25,26,27,30,31,34,35,39,40,45],{},"Older XlsxWriter versions, and code that catches the lower-level exception, show ",[22,28,29],{},"zipfile.LargeZipFile: File size too large"," instead. The message mentions file size, but the finished ",[22,32,33],{},".xlsx"," may be only a few hundred megabytes. What crossed the limit is one XML part ",[36,37,38],"em",{},"inside"," the package, before compression. This page explains the limit, shows how to predict when an export will hit it, and covers the one-line fix and the cases where the better fix is a smaller workbook. It belongs to ",[41,42,44],"a",{"href":43},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002F","Troubleshooting Common Python Excel Errors",".",[47,48,50],"h2",{"id":49},"prerequisites","Prerequisites",[14,52,56],{"className":53,"code":54,"language":55,"meta":20,"style":20},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install xlsxwriter pandas\n","bash",[22,57,58],{"__ignoreMap":20},[59,60,63,67,71,74],"span",{"class":61,"line":62},"line",1,[59,64,66],{"class":65},"sMTad","pip",[59,68,70],{"class":69},"srMev"," install",[59,72,73],{"class":69}," xlsxwriter",[59,75,76],{"class":69}," pandas\n",[10,78,79,80,83],{},"Reproducing the error for real means writing more than two gigabytes of XML, which takes minutes and a lot of disk. The examples below lower Python's ",[22,81,82],{},"zipfile"," threshold for the duration of a test, so the same code path raises the same exception on a small workbook.",[47,85,87],{"id":86},"step-1-understand-what-the-limit-applies-to","Step 1 — Understand what the limit applies to",[10,89,90,91,93,94,97,98,100,101,104],{},"An ",[22,92,33],{}," file is a ZIP archive, and each worksheet is one member of it: ",[22,95,96],{},"xl\u002Fworksheets\u002Fsheet1.xml",". The original ZIP format records sizes in 32-bit fields; members larger than that need the ZIP64 extension. Python's ",[22,99,82],{}," refuses to write ZIP64 unless the caller allows it, and its threshold is ",[22,102,103],{},"zipfile.ZIP64_LIMIT",":",[14,106,110],{"className":107,"code":108,"language":109,"meta":20,"style":20},"language-python shiki shiki-themes github-light github-dark-high-contrast","import zipfile\n\nprint(f\"{zipfile.ZIP64_LIMIT:,} bytes = {zipfile.ZIP64_LIMIT \u002F 2**30:.2f} GiB\")\n","python",[22,111,112,122,129],{"__ignoreMap":20},[59,113,114,118],{"class":61,"line":62},[59,115,117],{"class":116},"s-kum","import",[59,119,121],{"class":120},"skGVy"," zipfile\n",[59,123,125],{"class":61,"line":124},2,[59,126,128],{"emptyLinePlaceholder":127},true,"\n",[59,130,132,136,139,142,145,149,152,155,158,161,164,166,168,170,173,176,179,182,185,187,190],{"class":61,"line":131},3,[59,133,135],{"class":134},"sP0c6","print",[59,137,138],{"class":120},"(",[59,140,141],{"class":116},"f",[59,143,144],{"class":69},"\"",[59,146,148],{"class":147},"sSjpA","{",[59,150,151],{"class":120},"zipfile.",[59,153,154],{"class":134},"ZIP64_LIMIT",[59,156,157],{"class":116},":,",[59,159,160],{"class":147},"}",[59,162,163],{"class":69}," bytes = ",[59,165,148],{"class":147},[59,167,151],{"class":120},[59,169,154],{"class":134},[59,171,172],{"class":116}," \u002F",[59,174,175],{"class":134}," 2",[59,177,178],{"class":116},"**",[59,180,181],{"class":134},"30",[59,183,184],{"class":116},":.2f",[59,186,160],{"class":147},[59,188,189],{"class":69}," GiB\"",[59,191,192],{"class":120},")\n",[10,194,195,196,199,200,203,204,206],{},"The limit is 2,147,483,647 bytes — 2 GiB — ",[36,197,198],{},"per member, uncompressed",". XlsxWriter writes each sheet's XML to a temporary file first and adds it to the archive when you call ",[22,201,202],{},"close()",", which is why the error appears at the very end. Sheet XML compresses about four to one, so a workbook can fail with a 2 GiB sheet part while the final ",[22,205,33],{}," would have been around 500 MB.",[208,209,217,218,217,222,217,226,217,234,217,244,217,255,217,261,217,266,217,271,217,276,217,281,217,288,217,292,217,296,217,300,217,303,217,308,217,315,217,319],"svg",{"viewBox":210,"role":211,"ariaLabelledBy":212,"xmlns":215,"style":216},"84 0 592 383","img",[213,214],"zip64-limit-t","zip64-limit-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:592px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[219,220,221],"title",{"id":213},"Where the 2 GiB limit applies",[223,224,225],"desc",{"id":214},"The .xlsx archive contains XML parts. The limit applies to each part's uncompressed size, so sheet1.xml at 2.3 GiB triggers the error even though the compressed workbook would be about 600 MB.",[227,228],"rect",{"x":229,"y":230,"width":231,"height":232,"fill":233},"84","0","592","383","#ffffff",[227,235],{"x":236,"y":237,"width":238,"height":239,"rx":240,"fill":241,"stroke":242,"style":243},"100.0","16.0","560.0","93.0","12","#e7ebef","var(--line,#cdd5e6)","stroke-width:2px",[245,246,248],"g",{"transform":247},"translate(368.0,29.0) scale(1.000)",[249,250],"path",{"d":251,"fill":252,"stroke":253,"style":254},"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",[19,256,260],{"x":257,"y":258,"style":259},"380.0","75.5","font-size:13.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","report.xlsx on disk",[19,262,265],{"x":257,"y":263,"style":264},"95.0","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","≈ 600 MB compressed — not the problem",[61,267],{"x1":257,"y1":268,"x2":257,"y2":269,"stroke":270,"style":243},"114.0","136.0","var(--brand,#5b5cf0)",[272,273],"polygon",{"points":274,"fill":275},"380.0,140.0 375.0,131.0 385.0,131.0","#5b5cf0",[227,277],{"x":236,"y":278,"width":238,"height":239,"rx":240,"fill":279,"stroke":280,"style":243},"145.0","#fce9e9","var(--danger,#dc2626)",[245,282,284],{"transform":283},"translate(368.0,158.0) scale(1.000)",[249,285],{"d":286,"fill":252,"stroke":287,"style":254},"M4 4h16v16H4z M4 9h16 M4 14h16 M10 4v16","var(--accent-ink,#be185d)",[19,289,96],{"x":257,"y":290,"style":291},"204.5","font-size:13.5px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle",[19,293,295],{"x":257,"y":294,"style":264},"224.0","2.3 GiB uncompressed — over the limit",[61,297],{"x1":257,"y1":298,"x2":257,"y2":299,"stroke":270,"style":243},"243.0","265.0",[272,301],{"points":302,"fill":275},"380.0,269.0 375.0,260.0 385.0,260.0",[227,304],{"x":236,"y":305,"width":238,"height":239,"rx":240,"fill":306,"stroke":307,"style":243},"274.0","#fdefd8","var(--gold,#b4740a)",[245,309,311],{"transform":310},"translate(368.0,287.0) scale(1.000)",[249,312],{"d":313,"fill":252,"stroke":314,"style":254},"M12 3.5l9.5 17h-19z M12 10v5 M12 17.8v.4","var(--gold-ink,#7a4e06)",[19,316,103],{"x":257,"y":317,"style":318},"333.5","font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle",[19,320,322],{"x":257,"y":321,"style":264},"353.0","2,147,483,647 bytes per member",[47,324,326],{"id":325},"step-2-reproduce-it-on-a-small-workbook","Step 2 — Reproduce it on a small workbook",[14,328,330],{"className":107,"code":329,"language":109,"meta":20,"style":20},"import xlsxwriter\nfrom xlsxwriter.exceptions import FileSizeError\n\ndef write_rows(path, rows, **options):\n    wb = xlsxwriter.Workbook(path, options)\n    ws = wb.add_worksheet()\n    for r in range(rows):\n        ws.write_row(r, 0, [r, r * 1.5, f\"item {r % 50}\"])\n    wb.close()\n\nreal_limit = zipfile.ZIP64_LIMIT\nzipfile.ZIP64_LIMIT = 50_000            # pretend the limit is 50 KB\ntry:\n    write_rows(\"export.xlsx\", 5_000)\nexcept FileSizeError as exc:\n    print(\"FileSizeError:\", exc)\n    print(\"caused by:\", type(exc.__context__).__name__)\nfinally:\n    zipfile.ZIP64_LIMIT = real_limit\n",[22,331,332,339,352,356,374,386,397,415,458,464,469,483,500,509,525,540,554,577,585],{"__ignoreMap":20},[59,333,334,336],{"class":61,"line":62},[59,335,117],{"class":116},[59,337,338],{"class":120}," xlsxwriter\n",[59,340,341,344,347,349],{"class":61,"line":124},[59,342,343],{"class":116},"from",[59,345,346],{"class":120}," xlsxwriter.exceptions ",[59,348,117],{"class":116},[59,350,351],{"class":120}," FileSizeError\n",[59,353,354],{"class":61,"line":131},[59,355,128],{"emptyLinePlaceholder":127},[59,357,359,362,366,369,371],{"class":61,"line":358},4,[59,360,361],{"class":116},"def",[59,363,365],{"class":364},"s_Opv"," write_rows",[59,367,368],{"class":120},"(path, rows, ",[59,370,178],{"class":116},[59,372,373],{"class":120},"options):\n",[59,375,377,380,383],{"class":61,"line":376},5,[59,378,379],{"class":120},"    wb ",[59,381,382],{"class":116},"=",[59,384,385],{"class":120}," xlsxwriter.Workbook(path, options)\n",[59,387,389,392,394],{"class":61,"line":388},6,[59,390,391],{"class":120},"    ws ",[59,393,382],{"class":116},[59,395,396],{"class":120}," wb.add_worksheet()\n",[59,398,400,403,406,409,412],{"class":61,"line":399},7,[59,401,402],{"class":116},"    for",[59,404,405],{"class":120}," r ",[59,407,408],{"class":116},"in",[59,410,411],{"class":134}," range",[59,413,414],{"class":120},"(rows):\n",[59,416,418,421,423,426,429,432,435,437,440,442,445,448,451,453,455],{"class":61,"line":417},8,[59,419,420],{"class":120},"        ws.write_row(r, ",[59,422,230],{"class":134},[59,424,425],{"class":120},", [r, r ",[59,427,428],{"class":116},"*",[59,430,431],{"class":134}," 1.5",[59,433,434],{"class":120},", ",[59,436,141],{"class":116},[59,438,439],{"class":69},"\"item ",[59,441,148],{"class":147},[59,443,444],{"class":120},"r ",[59,446,447],{"class":116},"%",[59,449,450],{"class":134}," 50",[59,452,160],{"class":147},[59,454,144],{"class":69},[59,456,457],{"class":120},"])\n",[59,459,461],{"class":61,"line":460},9,[59,462,463],{"class":120},"    wb.close()\n",[59,465,467],{"class":61,"line":466},10,[59,468,128],{"emptyLinePlaceholder":127},[59,470,472,475,477,480],{"class":61,"line":471},11,[59,473,474],{"class":120},"real_limit ",[59,476,382],{"class":116},[59,478,479],{"class":120}," zipfile.",[59,481,482],{"class":134},"ZIP64_LIMIT\n",[59,484,486,488,490,493,496],{"class":61,"line":485},12,[59,487,151],{"class":120},[59,489,154],{"class":134},[59,491,492],{"class":116}," =",[59,494,495],{"class":134}," 50_000",[59,497,499],{"class":498},"s-wDw","            # pretend the limit is 50 KB\n",[59,501,503,506],{"class":61,"line":502},13,[59,504,505],{"class":116},"try",[59,507,508],{"class":120},":\n",[59,510,512,515,518,520,523],{"class":61,"line":511},14,[59,513,514],{"class":120},"    write_rows(",[59,516,517],{"class":69},"\"export.xlsx\"",[59,519,434],{"class":120},[59,521,522],{"class":134},"5_000",[59,524,192],{"class":120},[59,526,528,531,534,537],{"class":61,"line":527},15,[59,529,530],{"class":116},"except",[59,532,533],{"class":120}," FileSizeError ",[59,535,536],{"class":116},"as",[59,538,539],{"class":120}," exc:\n",[59,541,543,546,548,551],{"class":61,"line":542},16,[59,544,545],{"class":134},"    print",[59,547,138],{"class":120},[59,549,550],{"class":69},"\"FileSizeError:\"",[59,552,553],{"class":120},", exc)\n",[59,555,557,559,561,564,566,569,572,575],{"class":61,"line":556},17,[59,558,545],{"class":134},[59,560,138],{"class":120},[59,562,563],{"class":69},"\"caused by:\"",[59,565,434],{"class":120},[59,567,568],{"class":134},"type",[59,570,571],{"class":120},"(exc.__context__).",[59,573,574],{"class":134},"__name__",[59,576,192],{"class":120},[59,578,580,583],{"class":61,"line":579},18,[59,581,582],{"class":116},"finally",[59,584,508],{"class":120},[59,586,588,591,593,595],{"class":61,"line":587},19,[59,589,590],{"class":120},"    zipfile.",[59,592,154],{"class":134},[59,594,492],{"class":116},[59,596,597],{"class":120}," real_limit\n",[10,599,600,601,603,604,607,608,610],{},"The sheet's XML for 5,000 rows is well over 50 KB, so ",[22,602,202],{}," raises exactly the production error, with ",[22,605,606],{},"zipfile.LargeZipFile"," as the underlying cause. Restoring the real limit in ",[22,609,582],{}," matters — the constant is global for the whole process.",[47,612,614],{"id":613},"step-3-turn-on-zip64","Step 3 — Turn on ZIP64",[10,616,617,618,104],{},"XlsxWriter allows ZIP64 through a constructor option or a method; either must be set before ",[22,619,202],{},[14,621,623],{"className":107,"code":622,"language":109,"meta":20,"style":20},"zipfile.ZIP64_LIMIT = 50_000\ntry:\n    write_rows(\"export_zip64.xlsx\", 5_000, use_zip64=True)\n    print(\"written with ZIP64\")\nfinally:\n    zipfile.ZIP64_LIMIT = real_limit\n\nfrom openpyxl import load_workbook\nprint(\"rows read back:\", load_workbook(\"export_zip64.xlsx\", read_only=True).active.max_row)\n",[22,624,625,636,642,666,677,683,693,697,709],{"__ignoreMap":20},[59,626,627,629,631,633],{"class":61,"line":62},[59,628,151],{"class":120},[59,630,154],{"class":134},[59,632,492],{"class":116},[59,634,635],{"class":134}," 50_000\n",[59,637,638,640],{"class":61,"line":124},[59,639,505],{"class":116},[59,641,508],{"class":120},[59,643,644,646,649,651,653,655,659,661,664],{"class":61,"line":131},[59,645,514],{"class":120},[59,647,648],{"class":69},"\"export_zip64.xlsx\"",[59,650,434],{"class":120},[59,652,522],{"class":134},[59,654,434],{"class":120},[59,656,658],{"class":657},"sa561","use_zip64",[59,660,382],{"class":116},[59,662,663],{"class":134},"True",[59,665,192],{"class":120},[59,667,668,670,672,675],{"class":61,"line":358},[59,669,545],{"class":134},[59,671,138],{"class":120},[59,673,674],{"class":69},"\"written with ZIP64\"",[59,676,192],{"class":120},[59,678,679,681],{"class":61,"line":376},[59,680,582],{"class":116},[59,682,508],{"class":120},[59,684,685,687,689,691],{"class":61,"line":388},[59,686,590],{"class":120},[59,688,154],{"class":134},[59,690,492],{"class":116},[59,692,597],{"class":120},[59,694,695],{"class":61,"line":399},[59,696,128],{"emptyLinePlaceholder":127},[59,698,699,701,704,706],{"class":61,"line":417},[59,700,343],{"class":116},[59,702,703],{"class":120}," openpyxl ",[59,705,117],{"class":116},[59,707,708],{"class":120}," load_workbook\n",[59,710,711,713,715,718,721,723,725,728,730,732],{"class":61,"line":460},[59,712,135],{"class":134},[59,714,138],{"class":120},[59,716,717],{"class":69},"\"rows read back:\"",[59,719,720],{"class":120},", load_workbook(",[59,722,648],{"class":69},[59,724,434],{"class":120},[59,726,727],{"class":657},"read_only",[59,729,382],{"class":116},[59,731,663],{"class":134},[59,733,734],{"class":120},").active.max_row)\n",[10,736,737,740,741,744],{},[22,738,739],{},"Workbook(path, {\"use_zip64\": True})"," and calling ",[22,742,743],{},"workbook.use_zip64()"," after creating the workbook are equivalent. The output is a valid ZIP64 package; current Excel versions, LibreOffice, openpyxl and pandas read it. XlsxWriter keeps ZIP64 off by default because some older ZIP readers do not understand the extension, so enable it for the exports that need it rather than everywhere, and open one such file in the oldest Excel your recipients use before relying on it.",[10,746,747,748,104],{},"From pandas, pass the option through ",[22,749,750],{},"engine_kwargs",[14,752,754],{"className":107,"code":753,"language":109,"meta":20,"style":20},"import pandas as pd\n\ndf = pd.DataFrame({\"id\": range(5_000), \"value\": [i * 1.5 for i in range(5_000)]})\nzipfile.ZIP64_LIMIT = 50_000\ntry:\n    with pd.ExcelWriter(\"pandas_zip64.xlsx\", engine=\"xlsxwriter\",\n                        engine_kwargs={\"options\": {\"use_zip64\": True}}) as xw:\n        df.to_excel(xw, index=False)\n    print(\"pandas export written\")\nfinally:\n    zipfile.ZIP64_LIMIT = real_limit\n",[22,755,756,768,772,825,835,841,865,895,910,921,927],{"__ignoreMap":20},[59,757,758,760,763,765],{"class":61,"line":62},[59,759,117],{"class":116},[59,761,762],{"class":120}," pandas ",[59,764,536],{"class":116},[59,766,767],{"class":120}," pd\n",[59,769,770],{"class":61,"line":124},[59,771,128],{"emptyLinePlaceholder":127},[59,773,774,777,779,782,785,788,791,793,795,798,801,804,806,808,811,814,816,818,820,822],{"class":61,"line":131},[59,775,776],{"class":120},"df ",[59,778,382],{"class":116},[59,780,781],{"class":120}," pd.DataFrame({",[59,783,784],{"class":69},"\"id\"",[59,786,787],{"class":120},": ",[59,789,790],{"class":134},"range",[59,792,138],{"class":120},[59,794,522],{"class":134},[59,796,797],{"class":120},"), ",[59,799,800],{"class":69},"\"value\"",[59,802,803],{"class":120},": [i ",[59,805,428],{"class":116},[59,807,431],{"class":134},[59,809,810],{"class":116}," for",[59,812,813],{"class":120}," i ",[59,815,408],{"class":116},[59,817,411],{"class":134},[59,819,138],{"class":120},[59,821,522],{"class":134},[59,823,824],{"class":120},")]})\n",[59,826,827,829,831,833],{"class":61,"line":358},[59,828,151],{"class":120},[59,830,154],{"class":134},[59,832,492],{"class":116},[59,834,635],{"class":134},[59,836,837,839],{"class":61,"line":376},[59,838,505],{"class":116},[59,840,508],{"class":120},[59,842,843,846,849,852,854,857,859,862],{"class":61,"line":388},[59,844,845],{"class":116},"    with",[59,847,848],{"class":120}," pd.ExcelWriter(",[59,850,851],{"class":69},"\"pandas_zip64.xlsx\"",[59,853,434],{"class":120},[59,855,856],{"class":657},"engine",[59,858,382],{"class":116},[59,860,861],{"class":69},"\"xlsxwriter\"",[59,863,864],{"class":120},",\n",[59,866,867,870,872,874,877,880,883,885,887,890,892],{"class":61,"line":399},[59,868,869],{"class":657},"                        engine_kwargs",[59,871,382],{"class":116},[59,873,148],{"class":120},[59,875,876],{"class":69},"\"options\"",[59,878,879],{"class":120},": {",[59,881,882],{"class":69},"\"use_zip64\"",[59,884,787],{"class":120},[59,886,663],{"class":134},[59,888,889],{"class":120},"}}) ",[59,891,536],{"class":116},[59,893,894],{"class":120}," xw:\n",[59,896,897,900,903,905,908],{"class":61,"line":417},[59,898,899],{"class":120},"        df.to_excel(xw, ",[59,901,902],{"class":657},"index",[59,904,382],{"class":116},[59,906,907],{"class":134},"False",[59,909,192],{"class":120},[59,911,912,914,916,919],{"class":61,"line":460},[59,913,545],{"class":134},[59,915,138],{"class":120},[59,917,918],{"class":69},"\"pandas export written\"",[59,920,192],{"class":120},[59,922,923,925],{"class":61,"line":466},[59,924,582],{"class":116},[59,926,508],{"class":120},[59,928,929,931,933,935],{"class":61,"line":471},[59,930,590],{"class":120},[59,932,154],{"class":134},[59,934,492],{"class":116},[59,936,597],{"class":120},[47,938,940],{"id":939},"step-4-predict-when-an-export-will-hit-the-limit","Step 4 — Predict when an export will hit the limit",[10,942,943,944,947],{},"Measure how many bytes of XML one cell of ",[36,945,946],{},"your"," data produces, then extrapolate. A sample of 20,000 rows is enough:",[14,949,951],{"className":107,"code":950,"language":109,"meta":20,"style":20},"import random\n\nrandom.seed(0)\nsample_rows, cols = 20_000, 20\nwb = xlsxwriter.Workbook(\"sample.xlsx\", {\"constant_memory\": True})\nws = wb.add_worksheet()\nfor r in range(sample_rows):\n    ws.write_row(r, 0, [random.random() * 10_000 for _ in range(15)] + [f\"cat{random.randint(1, 50)}\" for _ in range(5)])\nwb.close()\npart = zipfile.ZipFile(\"sample.xlsx\").getinfo(\"xl\u002Fworksheets\u002Fsheet1.xml\")\nper_cell = part.file_size \u002F (sample_rows * cols)\nprint(f\"{per_cell:.1f} bytes per cell; compressed {part.file_size \u002F part.compress_size:.1f}:1\")\nprint(f\"cells per sheet before the limit: {real_limit \u002F per_cell:,.0f}\")\nprint(f\"columns that fit in 1,048,576 rows: {real_limit \u002F per_cell \u002F 1_048_576:.0f}\")\n",[22,952,953,960,964,973,988,1014,1023,1037,1116,1121,1141,1162,1204,1233],{"__ignoreMap":20},[59,954,955,957],{"class":61,"line":62},[59,956,117],{"class":116},[59,958,959],{"class":120}," random\n",[59,961,962],{"class":61,"line":124},[59,963,128],{"emptyLinePlaceholder":127},[59,965,966,969,971],{"class":61,"line":131},[59,967,968],{"class":120},"random.seed(",[59,970,230],{"class":134},[59,972,192],{"class":120},[59,974,975,978,980,983,985],{"class":61,"line":358},[59,976,977],{"class":120},"sample_rows, cols ",[59,979,382],{"class":116},[59,981,982],{"class":134}," 20_000",[59,984,434],{"class":120},[59,986,987],{"class":134},"20\n",[59,989,990,993,995,998,1001,1004,1007,1009,1011],{"class":61,"line":376},[59,991,992],{"class":120},"wb ",[59,994,382],{"class":116},[59,996,997],{"class":120}," xlsxwriter.Workbook(",[59,999,1000],{"class":69},"\"sample.xlsx\"",[59,1002,1003],{"class":120},", {",[59,1005,1006],{"class":69},"\"constant_memory\"",[59,1008,787],{"class":120},[59,1010,663],{"class":134},[59,1012,1013],{"class":120},"})\n",[59,1015,1016,1019,1021],{"class":61,"line":388},[59,1017,1018],{"class":120},"ws ",[59,1020,382],{"class":116},[59,1022,396],{"class":120},[59,1024,1025,1028,1030,1032,1034],{"class":61,"line":399},[59,1026,1027],{"class":116},"for",[59,1029,405],{"class":120},[59,1031,408],{"class":116},[59,1033,411],{"class":134},[59,1035,1036],{"class":120},"(sample_rows):\n",[59,1038,1039,1042,1044,1047,1049,1052,1054,1057,1059,1061,1063,1066,1069,1072,1075,1077,1080,1082,1085,1088,1090,1093,1096,1098,1100,1102,1104,1106,1108,1110,1113],{"class":61,"line":417},[59,1040,1041],{"class":120},"    ws.write_row(r, ",[59,1043,230],{"class":134},[59,1045,1046],{"class":120},", [random.random() ",[59,1048,428],{"class":116},[59,1050,1051],{"class":134}," 10_000",[59,1053,810],{"class":116},[59,1055,1056],{"class":120}," _ ",[59,1058,408],{"class":116},[59,1060,411],{"class":134},[59,1062,138],{"class":120},[59,1064,1065],{"class":134},"15",[59,1067,1068],{"class":120},")] ",[59,1070,1071],{"class":116},"+",[59,1073,1074],{"class":120}," [",[59,1076,141],{"class":116},[59,1078,1079],{"class":69},"\"cat",[59,1081,148],{"class":147},[59,1083,1084],{"class":120},"random.randint(",[59,1086,1087],{"class":134},"1",[59,1089,434],{"class":120},[59,1091,1092],{"class":134},"50",[59,1094,1095],{"class":120},")",[59,1097,160],{"class":147},[59,1099,144],{"class":69},[59,1101,810],{"class":116},[59,1103,1056],{"class":120},[59,1105,408],{"class":116},[59,1107,411],{"class":134},[59,1109,138],{"class":120},[59,1111,1112],{"class":134},"5",[59,1114,1115],{"class":120},")])\n",[59,1117,1118],{"class":61,"line":460},[59,1119,1120],{"class":120},"wb.close()\n",[59,1122,1123,1126,1128,1131,1133,1136,1139],{"class":61,"line":466},[59,1124,1125],{"class":120},"part ",[59,1127,382],{"class":116},[59,1129,1130],{"class":120}," zipfile.ZipFile(",[59,1132,1000],{"class":69},[59,1134,1135],{"class":120},").getinfo(",[59,1137,1138],{"class":69},"\"xl\u002Fworksheets\u002Fsheet1.xml\"",[59,1140,192],{"class":120},[59,1142,1143,1146,1148,1151,1154,1157,1159],{"class":61,"line":471},[59,1144,1145],{"class":120},"per_cell ",[59,1147,382],{"class":116},[59,1149,1150],{"class":120}," part.file_size ",[59,1152,1153],{"class":116},"\u002F",[59,1155,1156],{"class":120}," (sample_rows ",[59,1158,428],{"class":116},[59,1160,1161],{"class":120}," cols)\n",[59,1163,1164,1166,1168,1170,1172,1174,1177,1180,1182,1185,1187,1190,1192,1195,1197,1199,1202],{"class":61,"line":485},[59,1165,135],{"class":134},[59,1167,138],{"class":120},[59,1169,141],{"class":116},[59,1171,144],{"class":69},[59,1173,148],{"class":147},[59,1175,1176],{"class":120},"per_cell",[59,1178,1179],{"class":116},":.1f",[59,1181,160],{"class":147},[59,1183,1184],{"class":69}," bytes per cell; compressed ",[59,1186,148],{"class":147},[59,1188,1189],{"class":120},"part.file_size ",[59,1191,1153],{"class":116},[59,1193,1194],{"class":120}," part.compress_size",[59,1196,1179],{"class":116},[59,1198,160],{"class":147},[59,1200,1201],{"class":69},":1\"",[59,1203,192],{"class":120},[59,1205,1206,1208,1210,1212,1215,1217,1219,1221,1224,1227,1229,1231],{"class":61,"line":502},[59,1207,135],{"class":134},[59,1209,138],{"class":120},[59,1211,141],{"class":116},[59,1213,1214],{"class":69},"\"cells per sheet before the limit: ",[59,1216,148],{"class":147},[59,1218,474],{"class":120},[59,1220,1153],{"class":116},[59,1222,1223],{"class":120}," per_cell",[59,1225,1226],{"class":116},":,.0f",[59,1228,160],{"class":147},[59,1230,144],{"class":69},[59,1232,192],{"class":120},[59,1234,1235,1237,1239,1241,1244,1246,1248,1250,1253,1255,1258,1261,1263,1265],{"class":61,"line":511},[59,1236,135],{"class":134},[59,1238,138],{"class":120},[59,1240,141],{"class":116},[59,1242,1243],{"class":69},"\"columns that fit in 1,048,576 rows: ",[59,1245,148],{"class":147},[59,1247,474],{"class":120},[59,1249,1153],{"class":116},[59,1251,1252],{"class":120}," per_cell ",[59,1254,1153],{"class":116},[59,1256,1257],{"class":134}," 1_048_576",[59,1259,1260],{"class":116},":.0f",[59,1262,160],{"class":147},[59,1264,144],{"class":69},[59,1266,192],{"class":120},[10,1268,1269],{},"With this mix of decimals and short text, each cell costs about 45 bytes of XML, so a sheet reaches 2 GiB at roughly 48 million cells — a full-height sheet of 1,048,576 rows with around 45 columns. Long text, many-digit floats and cell formats push the number per cell up; small integers push it down. Run the estimate on a sample of your real data before the export grows into the limit.",[208,1271,217,1277,217,1280,217,1283,217,1288,217,1295,217,1301,217,1308,217,1313,217,1316,217,1320,217,1324,217,1329,217,1332,217,1336,217,1339,217,1344],{"viewBox":1272,"role":211,"ariaLabelledBy":1273,"xmlns":215,"style":1276},"4 0 743 166",[1274,1275],"zip64-cells-t","zip64-cells-d","width:100%;max-width:743px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[219,1278,1279],{"id":1274},"Rough cell counts that reach 2 GiB of sheet XML",[223,1281,1282],{"id":1275},"Estimated cells per sheet before the 2 GiB limit, by average XML bytes per cell. At 30 bytes per cell about 72 million cells fit, at 45 bytes about 48 million, and at 80 bytes about 27 million.",[227,1284],{"x":1285,"y":230,"width":1286,"height":1287,"fill":233},"4","743","166",[227,1289],{"x":1290,"y":237,"width":1291,"height":1292,"rx":1293,"fill":241,"stroke":242,"style":1294},"20.0","221.9","28.0","7","stroke-width:1px",[19,1296,1300],{"x":1297,"y":1298,"style":1299},"131.0","34.5","font-size:12.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","30 bytes \u002F cell (small ints)",[227,1302],{"x":1303,"y":237,"width":1304,"height":1292,"rx":1293,"fill":1305,"stroke":1306,"style":1307},"251.9","398.3","#d9f4f1","var(--teal,#0f9488)","stroke-width:1.5px",[19,1309,1312],{"x":1310,"y":1298,"style":1311},"658.2","font-size:12px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:start","≈ 72 M cells",[227,1314],{"x":1290,"y":1315,"width":1291,"height":1292,"rx":1293,"fill":241,"stroke":242,"style":1294},"56.0",[19,1317,1319],{"x":1297,"y":1318,"style":1299},"74.5","45 bytes \u002F cell (measured mix)",[227,1321],{"x":1303,"y":1315,"width":1322,"height":1292,"rx":1293,"fill":1323,"stroke":270,"style":1307},"265.5","#f0f4ff",[19,1325,1328],{"x":1326,"y":1318,"style":1327},"525.5","font-size:12px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:start","≈ 48 M cells",[227,1330],{"x":1290,"y":1331,"width":1291,"height":1292,"rx":1293,"fill":241,"stroke":242,"style":1294},"96.0",[19,1333,1335],{"x":1297,"y":1334,"style":1299},"114.5","80 bytes \u002F cell (long text)",[227,1337],{"x":1303,"y":1331,"width":1338,"height":1292,"rx":1293,"fill":306,"stroke":307,"style":1307},"149.4",[19,1340,1343],{"x":1341,"y":1334,"style":1342},"409.3","font-size:12px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:start","≈ 27 M cells",[19,1345,1348],{"x":257,"y":1346,"style":1347},"146.0","font-size:12.5px;font-weight:400;fill:var(--muted,#5b6780);text-anchor:middle","A full sheet is 1,048,576 rows, so 48 M cells is about 45 columns at full height.",[47,1350,1352],{"id":1351},"step-5-consider-a-smaller-workbook-instead","Step 5 — Consider a smaller workbook instead",[10,1354,1355],{},"Turning on ZIP64 makes the file writable; it does not make it usable. A worksheet with tens of millions of cells opens slowly, strains Excel's memory and is close to the sheet's row limit anyway. Often the better fix is structural:",[1357,1358,1359,1371,1381,1387],"ul",{},[1360,1361,1362,1366,1367,45],"li",{},[1363,1364,1365],"strong",{},"Split across sheets"," — one sheet per month or region keeps each part well under the limit; see ",[41,1368,1370],{"href":1369},"\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",[1360,1372,1373,1376,1377,45],{},[1363,1374,1375],{},"Split across files"," — one workbook per period or customer, as in ",[41,1378,1380],{"href":1379},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-large-excel-files-in-python\u002Fsplit-a-large-excel-file-into-files-of-n-rows\u002F","Split a Large Excel File into Files of N Rows",[1360,1382,1383,1386],{},[1363,1384,1385],{},"Summarise"," — ship the pivot, not the raw rows, and put the detail in Parquet or a database for whoever needs it.",[1360,1388,1389,1392,1393,45],{},[1363,1390,1391],{},"Change format"," — machine consumers are better served by CSV or Parquet, compared in ",[41,1394,1396],{"href":1395},"\u002Fgetting-started-with-python-excel-automation\u002Fchoosing-a-python-excel-library\u002Fexcel-vs-csv-vs-parquet-for-python-data-pipelines\u002F","Excel vs CSV vs Parquet for Python Data Pipelines",[208,1398,217,1404,217,1407,217,1410,217,1414,217,1418,217,1424,217,1428,217,1432,217,1436,217,1439,217,1442,217,1450,217,1454,217,1458,217,1465,217,1470,217,1474,217,1476,217,1479,217,1483,217,1486,217,1489,217,1495,217,1497,217,1500,217,1502,217,1505,217,1509,217,1512,217,1515,217,1521,217,1524],{"viewBox":1399,"role":211,"ariaLabelledBy":1400,"xmlns":215,"style":1403},"4 0 752 272",[1401,1402],"zip64-choice-t","zip64-choice-d","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[219,1405,1406],{"id":1401},"Turn on ZIP64 or reshape the export?",[223,1408,1409],{"id":1402},"If people will open the workbook in Excel, split or summarise it so each sheet stays small. If a program consumes it and must be xlsx, enable use_zip64. If the consumer can accept another format, write Parquet or CSV.",[227,1411],{"x":1285,"y":230,"width":1412,"height":1413,"fill":233},"752","272",[227,1415],{"x":1416,"y":237,"width":1417,"height":258,"rx":240,"fill":1323,"stroke":270,"style":243},"240.0","280.0",[245,1419,1420],{"transform":247},[249,1421],{"d":1422,"fill":252,"stroke":1423,"style":254},"M9 11a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7z M2.5 20c0-3.6 2.9-6 6.5-6s6.5 2.4 6.5 6 M16 4.5a3.3 3.3 0 0 1 0 6.3 M18 14.3c2.2.7 3.5 2.8 3.5 5.7","var(--brand-strong,#4338ca)",[19,1425,1427],{"x":257,"y":258,"style":1426},"font-size:13.5px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Who uses the export?",[61,1429],{"x1":257,"y1":1430,"x2":257,"y2":1431,"stroke":270,"style":243},"91.5","111.5",[61,1433],{"x1":1434,"y1":1431,"x2":1435,"y2":1431,"stroke":270,"style":243},"134.7","625.3",[61,1437],{"x1":1434,"y1":1431,"x2":1434,"y2":1438,"stroke":270,"style":243},"157.5",[272,1440],{"points":1441,"fill":275},"134.7,161.5 129.7,152.5 139.7,152.5",[227,1443],{"x":1444,"y":1445,"width":1446,"height":1447,"rx":1448,"fill":233,"stroke":242,"style":1449},"81.3","121.5","106.7","21.0","10","stroke-width:1.2px",[19,1451,1453],{"x":1434,"y":269,"style":1452},"font-size:11.5px;font-weight:700;fill:var(--muted,#5b6780);text-anchor:middle","people in Excel",[227,1455],{"x":1290,"y":1456,"width":1457,"height":239,"rx":240,"fill":1305,"stroke":1306,"style":243},"163.5","229.3",[245,1459,1461],{"transform":1460},"translate(122.7,176.5) scale(1.000)",[249,1462],{"d":1463,"fill":252,"stroke":1464,"style":254},"M4 12h6 M10 12l6-6h4 M10 12l6 6h4 M17 3l3 3-3 3 M17 15l3 3-3 3","var(--teal-ink,#0b6157)",[19,1466,1469],{"x":1434,"y":1467,"style":1468},"223.0","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Split or summarise",[19,1471,1473],{"x":1434,"y":1472,"style":264},"242.5","smaller sheets open faster",[61,1475],{"x1":257,"y1":1431,"x2":257,"y2":1438,"stroke":270,"style":243},[272,1477],{"points":1478,"fill":275},"380.0,161.5 375.0,152.5 385.0,152.5",[227,1480],{"x":1481,"y":1445,"width":1482,"height":1447,"rx":1448,"fill":233,"stroke":242,"style":1449},"301.9","156.1",[19,1484,1485],{"x":257,"y":269,"style":1452},"a program needing xlsx",[227,1487],{"x":1488,"y":1456,"width":1457,"height":239,"rx":240,"fill":1323,"stroke":270,"style":243},"265.3",[245,1490,1492],{"transform":1491},"translate(368.0,176.5) scale(1.000)",[249,1493],{"d":1494,"fill":252,"stroke":1423,"style":254},"M12 2.5l8.5 4.7v9.6L12 21.5l-8.5-4.7V7.2z M3.5 7.2l8.5 4.7 8.5-4.7 M12 11.9v9.6",[19,1496,658],{"x":257,"y":1467,"style":1426},[19,1498,1499],{"x":257,"y":1472,"style":264},"one option, valid ZIP64",[61,1501],{"x1":1435,"y1":1431,"x2":1435,"y2":1438,"stroke":270,"style":243},[272,1503],{"points":1504,"fill":275},"625.3,161.5 620.3,152.5 630.3,152.5",[227,1506],{"x":1507,"y":1445,"width":1508,"height":1447,"rx":1448,"fill":233,"stroke":242,"style":1449},"586.1","78.4",[19,1510,1511],{"x":1435,"y":269,"style":1452},"a program",[227,1513],{"x":1514,"y":1456,"width":1457,"height":239,"rx":240,"fill":241,"stroke":242,"style":243},"510.7",[245,1516,1518],{"transform":1517},"translate(613.3,176.5) scale(1.000)",[249,1519],{"d":1520,"fill":252,"stroke":253,"style":254},"M5 6c0-1.7 3.1-3 7-3s7 1.3 7 3-3.1 3-7 3-7-1.3-7-3z M5 6v12c0 1.7 3.1 3 7 3s7-1.3 7-3V6 M5 12c0 1.7 3.1 3 7 3s7-1.3 7-3",[19,1522,1523],{"x":1435,"y":1467,"style":259},"Parquet or CSV",[19,1525,1526],{"x":1435,"y":1472,"style":264},"no size ceiling worth worrying about",[47,1528,1530],{"id":1529},"step-6-decide-before-writing-not-after","Step 6 — Decide before writing, not after",[10,1532,1533],{},"The worst property of this error is its timing: it arrives after the whole export has been generated. A pre-flight check using the bytes-per-cell estimate from Step 4 lets the job choose ZIP64 — or a split — before it starts:",[14,1535,1537],{"className":107,"code":1536,"language":109,"meta":20,"style":20},"def needs_zip64(n_rows, n_cols, bytes_per_cell=per_cell, margin=1.25):\n    return n_rows * n_cols * bytes_per_cell * margin > real_limit\n\nfor rows, cols in [(500_000, 20), (1_048_576, 30), (1_048_576, 60)]:\n    print(f\"{rows:>9,} x {cols:>2} -> use_zip64={needs_zip64(rows, cols)}\")\n",[22,1538,1539,1562,1590,1594,1636],{"__ignoreMap":20},[59,1540,1541,1543,1546,1549,1551,1554,1556,1559],{"class":61,"line":62},[59,1542,361],{"class":116},[59,1544,1545],{"class":364}," needs_zip64",[59,1547,1548],{"class":120},"(n_rows, n_cols, bytes_per_cell",[59,1550,382],{"class":116},[59,1552,1553],{"class":120},"per_cell, margin",[59,1555,382],{"class":116},[59,1557,1558],{"class":134},"1.25",[59,1560,1561],{"class":120},"):\n",[59,1563,1564,1567,1570,1572,1575,1577,1580,1582,1585,1588],{"class":61,"line":124},[59,1565,1566],{"class":116},"    return",[59,1568,1569],{"class":120}," n_rows ",[59,1571,428],{"class":116},[59,1573,1574],{"class":120}," n_cols ",[59,1576,428],{"class":116},[59,1578,1579],{"class":120}," bytes_per_cell ",[59,1581,428],{"class":116},[59,1583,1584],{"class":120}," margin ",[59,1586,1587],{"class":116},">",[59,1589,597],{"class":120},[59,1591,1592],{"class":61,"line":131},[59,1593,128],{"emptyLinePlaceholder":127},[59,1595,1596,1598,1601,1603,1606,1609,1611,1614,1617,1620,1622,1624,1626,1628,1630,1633],{"class":61,"line":358},[59,1597,1027],{"class":116},[59,1599,1600],{"class":120}," rows, cols ",[59,1602,408],{"class":116},[59,1604,1605],{"class":120}," [(",[59,1607,1608],{"class":134},"500_000",[59,1610,434],{"class":120},[59,1612,1613],{"class":134},"20",[59,1615,1616],{"class":120},"), (",[59,1618,1619],{"class":134},"1_048_576",[59,1621,434],{"class":120},[59,1623,181],{"class":134},[59,1625,1616],{"class":120},[59,1627,1619],{"class":134},[59,1629,434],{"class":120},[59,1631,1632],{"class":134},"60",[59,1634,1635],{"class":120},")]:\n",[59,1637,1638,1640,1642,1644,1646,1648,1651,1654,1656,1659,1661,1664,1667,1669,1672,1674,1677,1679,1681],{"class":61,"line":376},[59,1639,545],{"class":134},[59,1641,138],{"class":120},[59,1643,141],{"class":116},[59,1645,144],{"class":69},[59,1647,148],{"class":147},[59,1649,1650],{"class":120},"rows",[59,1652,1653],{"class":116},":>9,",[59,1655,160],{"class":147},[59,1657,1658],{"class":69}," x ",[59,1660,148],{"class":147},[59,1662,1663],{"class":120},"cols",[59,1665,1666],{"class":116},":>2",[59,1668,160],{"class":147},[59,1670,1671],{"class":69}," -> use_zip64=",[59,1673,148],{"class":147},[59,1675,1676],{"class":120},"needs_zip64(rows, cols)",[59,1678,160],{"class":147},[59,1680,144],{"class":69},[59,1682,192],{"class":120},[10,1684,1685,1686,1689],{},"The 25% margin covers the variation between your sample and the full data. Feeding the result straight into the workbook options — ",[22,1687,1688],{},"xlsxwriter.Workbook(path, {\"use_zip64\": needs_zip64(len(df), df.shape[1])})"," — keeps small exports on the most compatible format and turns ZIP64 on only for the large ones. Log the decision, so that a recipient who reports a problem opening the file can be matched to the exports that used the extension.",[47,1691,1693],{"id":1692},"performance-notes","Performance notes",[10,1695,1696,1697,1700],{},"Exports of this size are where XlsxWriter's ",[22,1698,1699],{},"constant_memory"," option earns its keep: rows are flushed to the temporary file as they are written, so memory stays flat instead of growing with the sheet. It requires writing rows in order, top to bottom. The ZIP64 option itself costs nothing measurable. The time goes into generating and compressing gigabytes of XML — expect several minutes for a sheet near the limit — which is one more argument for splitting very large exports or moving them to Parquet.",[47,1702,1704],{"id":1703},"common-pitfalls","Common pitfalls",[1357,1706,1707,1713,1725,1736,1746],{},[1360,1708,1709,1712],{},[1363,1710,1711],{},"Judging by the final file size."," The limit is on the uncompressed sheet XML, roughly four times the size of the compressed workbook.",[1360,1714,1715,1718,1719,1721,1722,1724],{},[1363,1716,1717],{},"Setting the option too late."," ",[22,1720,658],{}," must be set before ",[22,1723,202],{},", and for pandas before the writer closes.",[1360,1726,1727,1730,1731,1733,1734,45],{},[1363,1728,1729],{},"Leaving a patched limit in place."," If you lower ",[22,1732,103],{}," in a test, restore it in ",[22,1735,582],{},[1360,1737,1738,1741,1742,1745],{},[1363,1739,1740],{},"Shared strings."," Huge amounts of unique text can push ",[22,1743,1744],{},"sharedStrings.xml"," over the limit instead of the sheet; the same option fixes it.",[1360,1747,1748,1751,1752,45],{},[1363,1749,1750],{},"Hitting the row limit next."," 1,048,576 rows per sheet still applies; see ",[41,1753,1755],{"href":1754},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-this-sheet-is-too-large-error\u002F","Fix \"This sheet is too large\" Error",[47,1757,1759],{"id":1758},"conclusion","Conclusion",[10,1761,1762,1765,1766,1768,1769,1771,1772,1775],{},[22,1763,1764],{},"FileSizeError: Filesize would require ZIP64 extensions"," (or ",[22,1767,606],{},") means one XML part of the workbook exceeds 2 GiB uncompressed — typically a sheet with tens of millions of cells. Enable ZIP64 with ",[22,1770,739],{}," or, from pandas, ",[22,1773,1774],{},"engine_kwargs={\"options\": {\"use_zip64\": True}}",". Estimate bytes per cell on a sample to see the limit coming, and when people will open the file, prefer splitting or summarising over a single enormous sheet.",[47,1777,1779],{"id":1778},"frequently-asked-questions","Frequently asked questions",[10,1781,1782,1785],{},[1363,1783,1784],{},"What does \"Filesize would require ZIP64 extensions\" mean in XlsxWriter?","\nOne part of the .xlsx package, usually a worksheet's XML, is larger than 2 GiB before compression. Python's zipfile needs the ZIP64 extension for that, and XlsxWriter only allows it when you enable use_zip64.",[10,1787,1788,1791],{},[1363,1789,1790],{},"How do I enable ZIP64 in XlsxWriter?","\nPass {\"use_zip64\": True} as the options argument of xlsxwriter.Workbook, or call workbook.use_zip64() before closing the workbook.",[10,1793,1794,1797],{},[1363,1795,1796],{},"How do I fix LargeZipFile when writing Excel with pandas?","\nUse the xlsxwriter engine and pass engine_kwargs={\"options\": {\"use_zip64\": True}} to pd.ExcelWriter, then write the DataFrame as usual.",[10,1799,1800,1803],{},[1363,1801,1802],{},"My .xlsx would be 500 MB — why does it hit a 2 GB limit?","\nThe limit applies to each XML part before compression. Sheet XML compresses roughly four to one, so a 2 GiB sheet part becomes a workbook of around 500 MB.",[47,1805,1807],{"id":1806},"related","Related",[1357,1809,1810,1816,1823,1830],{},[1360,1811,1812,1813,1815],{},"Up one level: ",[41,1814,44],{"href":43}," — fixes for common failures.",[1360,1817,1818,1822],{},[41,1819,1821],{"href":1820},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fbuilding-excel-reports-with-xlsxwriter\u002Fwrite-a-million-rows-to-excel-with-xlsxwriter-constant-memory\u002F","Write a Million Rows to Excel with xlsxwriter constant_memory"," — keeping big exports within memory.",[1360,1824,1825,1829],{},[41,1826,1828],{"href":1827},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-large-excel-files-in-python\u002F","Working with Large Excel Files in Python"," — reading and writing at scale.",[1360,1831,1832,1836],{},[41,1833,1835],{"href":1834},"\u002Fgetting-started-with-python-excel-automation\u002Fhandling-excel-file-formats-and-conversions\u002Finspect-the-xml-inside-an-xlsx-file-with-python\u002F","Inspect the XML Inside an .xlsx File with Python"," — measuring the parts yourself.",[1838,1839,1840],"style",{},"html pre.shiki code .sMTad, html code.shiki .sMTad{--shiki-default:#6F42C1;--shiki-dark:#FFB757}html pre.shiki code .srMev, html code.shiki .srMev{--shiki-default:#032F62;--shiki-dark:#ADDCFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s-kum, html code.shiki .s-kum{--shiki-default:#D73A49;--shiki-dark:#FF9492}html pre.shiki code .skGVy, html code.shiki .skGVy{--shiki-default:#24292E;--shiki-dark:#F0F3F6}html pre.shiki code .sP0c6, html code.shiki .sP0c6{--shiki-default:#005CC5;--shiki-dark:#91CBFF}html pre.shiki code .sSjpA, html code.shiki .sSjpA{--shiki-default:#005CC5;--shiki-dark:#FF9492}html pre.shiki code .s_Opv, html code.shiki .s_Opv{--shiki-default:#6F42C1;--shiki-dark:#DBB7FF}html pre.shiki code .s-wDw, html code.shiki .s-wDw{--shiki-default:#6A737D;--shiki-dark:#BDC4CC}html pre.shiki code .sa561, html code.shiki .sa561{--shiki-default:#E36209;--shiki-dark:#FFB757}",{"title":20,"searchDepth":124,"depth":124,"links":1842},[1843,1844,1845,1846,1847,1848,1849,1850,1851,1852,1853,1854],{"id":49,"depth":124,"text":50},{"id":86,"depth":124,"text":87},{"id":325,"depth":124,"text":326},{"id":613,"depth":124,"text":614},{"id":939,"depth":124,"text":940},{"id":1351,"depth":124,"text":1352},{"id":1529,"depth":124,"text":1530},{"id":1692,"depth":124,"text":1693},{"id":1703,"depth":124,"text":1704},{"id":1758,"depth":124,"text":1759},{"id":1778,"depth":124,"text":1779},{"id":1806,"depth":124,"text":1807},"2026-10-02","Very large exports fail at close() with xlsxwriter.exceptions.FileSizeError: Filesize would require ZIP64 extensions, raised from zipfile.LargeZipFile. Learn what crosses the limit (one XML part over 2 GiB, not the .xlsx file size), estimate when your export will hit it, turn on use_zip64 in XlsxWriter or through pandas, and when to split the data or choose another format instead.","md",[1859,1861,1863,1865],{"q":1784,"a":1860},"One part of the .xlsx package, usually a worksheet's XML, is larger than 2 GiB before compression. Python's zipfile needs the ZIP64 extension for that, and XlsxWriter only allows it when you enable use_zip64.",{"q":1790,"a":1862},"Pass {\"use_zip64\": True} as the options argument of xlsxwriter.Workbook, or call workbook.use_zip64() before closing the workbook.",{"q":1796,"a":1864},"Use the xlsxwriter engine and pass engine_kwargs={\"options\": {\"use_zip64\": True}} to pd.ExcelWriter, then write the DataFrame as usual.",{"q":1802,"a":1866},"The limit applies to each XML part before compression. Sheet XML compresses roughly four to one, so a 2 GiB sheet part becomes a workbook of around 500 MB.","fix largezipfile error in xlsxwriter",null,{"breadcrumb":1870},[1871,1873,1876],{"name":1872,"item":1153},"Home",{"name":1874,"item":1875},"Getting Started with Python Excel Automation","\u002Fgetting-started-with-python-excel-automation\u002F",{"name":44,"item":43},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter",{"title":1879,"description":1880},"Fix XlsxWriter \"Filesize would require ZIP64 extensions\"","XlsxWriter FileSizeError \u002F zipfile.LargeZipFile explained: the 2 GiB per-part limit, how many cells reach it, use_zip64 in Workbook options and pandas engine_kwargs, and splitting large exports across sheets, files or Parquet.","fix-largezipfile-error-in-xlsxwriter","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-largezipfile-error-in-xlsxwriter\u002Findex",[1884,1885,1886],"troubleshooting","xlsxwriter","large-files","how-to","yvllK5sLcCtzEy0aneJdtwQNSCmhmD2wkP82uGOs_I4",[1890,1894],{"title":1891,"path":1892,"stem":1893,"children":-1},"Fix KeyError from Spaces in Excel Column Names","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-keyerror-from-spaces-in-excel-column-names","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-keyerror-from-spaces-in-excel-column-names\u002Findex",{"title":1895,"path":1896,"stem":1897,"children":-1},"Fix Long ID Numbers Losing Digits or Turning into 1.23E+18 in Excel","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-long-id-numbers-losing-digits-in-excel","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-long-id-numbers-losing-digits-in-excel\u002Findex",[1899,1901],{"path":1900,"title":1874},"\u002Fgetting-started-with-python-excel-automation",{"path":1902,"title":44},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors",[],[1905,1909,1912,1915,1918,1921],{"path":1906,"title":1907,"kind":1908},"\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":1910,"title":1911,"kind":1887},"\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":1913,"title":1914,"kind":1908},"\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":1916,"title":1917,"kind":1887},"\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":1919,"title":1920,"kind":1887},"\u002Fautomating-reporting-workflows\u002Fautomating-excel-online-with-microsoft-graph\u002Fhandle-microsoft-graph-throttling-for-excel","Handle Microsoft Graph Throttling in Excel Automation",{"path":1922,"title":1923,"kind":1924},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation","Error Handling and Logging in Excel Automation","guide",1790972065895]