[{"data":1,"prerenderedAt":2503},["ShallowReactive",2],{"doc:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel":3,"surround:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel":2467,"ancestors:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel":2476,"children:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel":2481,"related:\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel":2482},{"id":4,"title":5,"body":6,"dateModified":2434,"datePublished":2434,"description":2435,"extension":2436,"faq":2437,"keyword":2446,"kind":2447,"meta":2448,"navigation":127,"path":2456,"seo":2457,"slug":2460,"stem":2461,"topics":2462,"type":2465,"__hash__":2466},"docs\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel\u002Findex.md","Fix #### Showing Instead of Values in Excel Output",{"type":7,"value":8,"toc":2421},"minimark",[9,13,24,33,38,67,78,82,85,331,396,403,555,559,567,603,613,617,620,1176,1225,1232,1236,1243,1448,1498,1509,1631,1677,1773,1778,1940,1944,1966,2116,2165,2173,2177,2195,2299,2303,2339,2343,2351,2355,2361,2367,2373,2379,2383,2417],[10,11,12],"p",{},"The report is correct, but half the numbers look like this:",[14,15,21],"pre",{"className":16,"code":18,"language":19,"meta":20},[17],"language-text","#####\n","text","",[22,23,18],"code",{"__ignoreMap":20},[10,25,26,27,32],{},"Excel is not reporting an error. A number or a date must be shown in full or not at all, so when the formatted value is wider than its column, Excel fills the cell with hash marks instead of showing a misleading part of it. Text behaves differently: it spills into an empty neighbour or is cut off. The value is intact; the column is too narrow for the format. Python libraries do not size columns unless told to, so reports written with openpyxl, xlsxwriter or pandas show this constantly. This page shows the causes and three fixes, and how to check the result without opening Excel. It is part of ",[28,29,31],"a",{"href":30},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002F","Troubleshooting Common Python Excel Errors",".",[34,35,37],"h2",{"id":36},"prerequisites","Prerequisites",[14,39,43],{"className":40,"code":41,"language":42,"meta":20,"style":20},"language-bash shiki shiki-themes github-light github-dark-high-contrast","pip install openpyxl xlsxwriter pandas\n","bash",[22,44,45],{"__ignoreMap":20},[46,47,50,54,58,61,64],"span",{"class":48,"line":49},"line",1,[46,51,53],{"class":52},"sMTad","pip",[46,55,57],{"class":56},"srMev"," install",[46,59,60],{"class":56}," openpyxl",[46,62,63],{"class":56}," xlsxwriter",[46,65,66],{"class":56}," pandas\n",[10,68,69,70,73,74,77],{},"The checks use LibreOffice in headless mode to render sheets to PDF and ",[22,71,72],{},"pdftotext"," to read what a reader would see. LibreOffice shows narrow numbers as ",[22,75,76],{},"###"," the same way.",[34,79,81],{"id":80},"step-1-reproduce-it","Step 1 — Reproduce it",[10,83,84],{},"Write a few typical values into columns six characters wide, the width many templates end up with:",[14,86,90],{"className":87,"code":88,"language":89,"meta":20,"style":20},"language-python shiki shiki-themes github-light github-dark-high-contrast","import datetime as dt\nfrom openpyxl import Workbook\n\nwb = Workbook()\nws = wb.active\nws.append([\"Revenue\", \"Invoice date\", \"Customer\", \"Units\", \"Margin\"])\nws.append([1234567.89, dt.date(2026, 9, 28), \"Harbor Foods Ltd\", 48210, 0.1834])\nws[\"A2\"].number_format = \"#,##0.00\"\nws[\"B2\"].number_format = \"dd mmmm yyyy\"\nws[\"D2\"].number_format = \"#,##0\"\nws[\"E2\"].number_format = \"0.0%\"\nfor col in \"ABCDE\":\n    ws.column_dimensions[col].width = 6\nwb.save(\"narrow.xlsx\")\n","python",[22,91,92,108,122,129,141,152,185,228,245,260,275,290,308,319],{"__ignoreMap":20},[46,93,94,98,102,105],{"class":48,"line":49},[46,95,97],{"class":96},"s-kum","import",[46,99,101],{"class":100},"skGVy"," datetime ",[46,103,104],{"class":96},"as",[46,106,107],{"class":100}," dt\n",[46,109,111,114,117,119],{"class":48,"line":110},2,[46,112,113],{"class":96},"from",[46,115,116],{"class":100}," openpyxl ",[46,118,97],{"class":96},[46,120,121],{"class":100}," Workbook\n",[46,123,125],{"class":48,"line":124},3,[46,126,128],{"emptyLinePlaceholder":127},true,"\n",[46,130,132,135,138],{"class":48,"line":131},4,[46,133,134],{"class":100},"wb ",[46,136,137],{"class":96},"=",[46,139,140],{"class":100}," Workbook()\n",[46,142,144,147,149],{"class":48,"line":143},5,[46,145,146],{"class":100},"ws ",[46,148,137],{"class":96},[46,150,151],{"class":100}," wb.active\n",[46,153,155,158,161,164,167,169,172,174,177,179,182],{"class":48,"line":154},6,[46,156,157],{"class":100},"ws.append([",[46,159,160],{"class":56},"\"Revenue\"",[46,162,163],{"class":100},", ",[46,165,166],{"class":56},"\"Invoice date\"",[46,168,163],{"class":100},[46,170,171],{"class":56},"\"Customer\"",[46,173,163],{"class":100},[46,175,176],{"class":56},"\"Units\"",[46,178,163],{"class":100},[46,180,181],{"class":56},"\"Margin\"",[46,183,184],{"class":100},"])\n",[46,186,188,190,194,197,200,202,205,207,210,213,216,218,221,223,226],{"class":48,"line":187},7,[46,189,157],{"class":100},[46,191,193],{"class":192},"sP0c6","1234567.89",[46,195,196],{"class":100},", dt.date(",[46,198,199],{"class":192},"2026",[46,201,163],{"class":100},[46,203,204],{"class":192},"9",[46,206,163],{"class":100},[46,208,209],{"class":192},"28",[46,211,212],{"class":100},"), ",[46,214,215],{"class":56},"\"Harbor Foods Ltd\"",[46,217,163],{"class":100},[46,219,220],{"class":192},"48210",[46,222,163],{"class":100},[46,224,225],{"class":192},"0.1834",[46,227,184],{"class":100},[46,229,231,234,237,240,242],{"class":48,"line":230},8,[46,232,233],{"class":100},"ws[",[46,235,236],{"class":56},"\"A2\"",[46,238,239],{"class":100},"].number_format ",[46,241,137],{"class":96},[46,243,244],{"class":56}," \"#,##0.00\"\n",[46,246,248,250,253,255,257],{"class":48,"line":247},9,[46,249,233],{"class":100},[46,251,252],{"class":56},"\"B2\"",[46,254,239],{"class":100},[46,256,137],{"class":96},[46,258,259],{"class":56}," \"dd mmmm yyyy\"\n",[46,261,263,265,268,270,272],{"class":48,"line":262},10,[46,264,233],{"class":100},[46,266,267],{"class":56},"\"D2\"",[46,269,239],{"class":100},[46,271,137],{"class":96},[46,273,274],{"class":56}," \"#,##0\"\n",[46,276,278,280,283,285,287],{"class":48,"line":277},11,[46,279,233],{"class":100},[46,281,282],{"class":56},"\"E2\"",[46,284,239],{"class":100},[46,286,137],{"class":96},[46,288,289],{"class":56}," \"0.0%\"\n",[46,291,293,296,299,302,305],{"class":48,"line":292},12,[46,294,295],{"class":96},"for",[46,297,298],{"class":100}," col ",[46,300,301],{"class":96},"in",[46,303,304],{"class":56}," \"ABCDE\"",[46,306,307],{"class":100},":\n",[46,309,311,314,316],{"class":48,"line":310},13,[46,312,313],{"class":100},"    ws.column_dimensions[col].width ",[46,315,137],{"class":96},[46,317,318],{"class":192}," 6\n",[46,320,322,325,328],{"class":48,"line":321},14,[46,323,324],{"class":100},"wb.save(",[46,326,327],{"class":56},"\"narrow.xlsx\"",[46,329,330],{"class":100},")\n",[14,332,334],{"className":40,"code":333,"language":42,"meta":20,"style":20},"soffice -env:UserInstallation=file:\u002F\u002F$PWD\u002Flo_profile --headless --convert-to pdf narrow.xlsx > \u002Fdev\u002Fnull 2>&1\npdftotext -layout narrow.pdf - | sed -n '1,2p'\n",[22,335,336,371],{"__ignoreMap":20},[46,337,338,341,344,347,350,353,356,359,362,365,368],{"class":48,"line":49},[46,339,340],{"class":52},"soffice",[46,342,343],{"class":192}," -env:UserInstallation=file:\u002F\u002F",[46,345,346],{"class":100},"$PWD",[46,348,349],{"class":192},"\u002Flo_profile",[46,351,352],{"class":192}," --headless",[46,354,355],{"class":192}," --convert-to",[46,357,358],{"class":56}," pdf",[46,360,361],{"class":56}," narrow.xlsx",[46,363,364],{"class":96}," >",[46,366,367],{"class":56}," \u002Fdev\u002Fnull",[46,369,370],{"class":96}," 2>&1\n",[46,372,373,375,378,381,384,387,390,393],{"class":48,"line":110},[46,374,72],{"class":52},[46,376,377],{"class":192}," -layout",[46,379,380],{"class":56}," narrow.pdf",[46,382,383],{"class":56}," -",[46,385,386],{"class":96}," |",[46,388,389],{"class":52}," sed",[46,391,392],{"class":192}," -n",[46,394,395],{"class":56}," '1,2p'\n",[10,397,398,399,402],{},"The revenue and the date become hash marks; the customer name is cut off at the next column; the units, ",[22,400,401],{},"48,210",", and the percentage just fit. Nothing about the values changed; only their display width did.",[404,405,413,414,413,418,413,422,413,430,413,439,413,443,413,449,413,453,413,457,413,461,413,465,413,469,413,473,413,477,413,481,413,485,413,490,413,495,413,499,413,501,413,504,413,506,413,509,413,511,413,514,413,516,413,519,413,522,413,526,413,530,413,533,413,535,413,537,413,541,413,545,413,547,413,550,413,552],"svg",{"viewBox":406,"role":407,"ariaLabelledBy":408,"xmlns":411,"style":412},"161 0 438 112","img",[409,410],"hm-narrow-t","hm-narrow-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:438px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[415,416,417],"title",{"id":409},"The same row at width 6",[419,420,421],"desc",{"id":410},"A worksheet row with five columns each six characters wide. Revenue formatted with thousands separators and two decimals shows hash marks, the date in long format shows hash marks, the customer name is cut off, and the units 48,210 and the percentage 18.3 percent just fit.",[423,424],"rect",{"x":425,"y":426,"width":427,"height":428,"fill":429},"161","0","438","112","#ffffff",[423,431],{"x":432,"y":433,"width":434,"height":435,"rx":426,"fill":436,"stroke":437,"style":438},"177.3","16.0","32.0","24.0","#e7ebef","var(--line,#cdd5e6)","stroke-width:1px",[423,440],{"x":441,"y":433,"width":442,"height":435,"rx":426,"fill":436,"stroke":437,"style":438},"209.3","73.6",[19,444,448],{"x":445,"y":446,"style":447},"246.1","33.0","font-size:11px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","A",[423,450],{"x":451,"y":433,"width":452,"height":435,"rx":426,"fill":436,"stroke":437,"style":438},"282.9","93.1",[19,454,456],{"x":455,"y":446,"style":447},"329.4","B",[423,458],{"x":459,"y":433,"width":460,"height":435,"rx":426,"fill":436,"stroke":437,"style":438},"376.0","79.6",[19,462,464],{"x":463,"y":446,"style":447},"415.8","C",[423,466],{"x":467,"y":433,"width":468,"height":435,"rx":426,"fill":436,"stroke":437,"style":438},"455.6","63.2",[19,470,472],{"x":471,"y":446,"style":447},"487.2","D",[423,474],{"x":475,"y":433,"width":476,"height":435,"rx":426,"fill":436,"stroke":437,"style":438},"518.9","63.8",[19,478,480],{"x":479,"y":446,"style":447},"550.8","E",[423,482],{"x":432,"y":483,"width":434,"height":484,"rx":426,"fill":436,"stroke":437,"style":438},"40.0","28.0",[19,486,489],{"x":487,"y":488,"style":447},"193.3","59.0","1",[423,491],{"x":441,"y":483,"width":442,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},"#f0f4ff","var(--brand,#5b5cf0)","stroke-width:1.5px",[19,496,498],{"x":445,"y":488,"style":497},"font-size:11px;font-weight:700;fill:var(--brand-strong,#4338ca);text-anchor:middle","Revenue",[423,500],{"x":451,"y":483,"width":452,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},[19,502,503],{"x":455,"y":488,"style":497},"Invoice date",[423,505],{"x":459,"y":483,"width":460,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},[19,507,508],{"x":463,"y":488,"style":497},"Customer",[423,510],{"x":467,"y":483,"width":468,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},[19,512,513],{"x":471,"y":488,"style":497},"Units",[423,515],{"x":475,"y":483,"width":476,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},[19,517,518],{"x":479,"y":488,"style":497},"Margin",[423,520],{"x":432,"y":521,"width":434,"height":484,"rx":426,"fill":436,"stroke":437,"style":438},"68.0",[19,523,525],{"x":487,"y":524,"style":447},"87.0","2",[423,527],{"x":441,"y":521,"width":442,"height":484,"rx":426,"fill":528,"stroke":529,"style":494},"#fce9e9","var(--danger,#dc2626)",[19,531,76],{"x":445,"y":524,"style":532},"font-size:11px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle",[423,534],{"x":451,"y":521,"width":452,"height":484,"rx":426,"fill":528,"stroke":529,"style":494},[19,536,76],{"x":455,"y":524,"style":532},[423,538],{"x":459,"y":521,"width":460,"height":484,"rx":426,"fill":539,"stroke":540,"style":494},"#fdefd8","var(--gold,#b4740a)",[19,542,544],{"x":463,"y":524,"style":543},"font-size:11px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","Harbor",[423,546],{"x":467,"y":521,"width":468,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},[19,548,401],{"x":471,"y":524,"style":549},"font-size:11px;font-weight:400;fill:var(--text,#172033);text-anchor:middle",[423,551],{"x":475,"y":521,"width":476,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},[19,553,554],{"x":479,"y":524,"style":549},"18.3%",[34,556,558],{"id":557},"why-the-width-is-not-enough","Why the width is not enough",[10,560,561,562,566],{},"Excel measures column width in characters of the default font, roughly the width of a digit. What matters is the length of the ",[563,564,565],"em",{},"formatted"," value, which can be much longer than the number:",[568,569,570,584,594],"ul",{},[571,572,573,575,576,579,580,583],"li",{},[22,574,193],{}," with ",[22,577,578],{},"#,##0.00"," is ",[22,581,582],{},"1,234,567.89",", twelve characters;",[571,585,586,587,579,590,593],{},"a date with ",[22,588,589],{},"dd mmmm yyyy",[22,591,592],{},"28 September 2026",", seventeen;",[571,595,596,597,579,600,602],{},"a percentage with ",[22,598,599],{},"0.0%",[22,601,554],{},", five.",[10,604,605,606,608,609,612],{},"A General-format number behaves better than a formatted one: Excel rounds it or switches to scientific notation to fit, so ",[22,607,193],{}," might show as ",[22,610,611],{},"1E+06",", which is arguably worse because it looks like a value.",[34,614,616],{"id":615},"fix-1-set-widths-from-the-formatted-values","Fix 1 — Set widths from the formatted values",[10,618,619],{},"With openpyxl, compute each column's width from the longest formatted value in it. The formatting only has to be approximately right; a small helper covering the formats you use is enough:",[14,621,623],{"className":87,"code":622,"language":89,"meta":20,"style":20},"from openpyxl import load_workbook\n\ndef display_text(cell):\n    v, fmt = cell.value, cell.number_format\n    if v is None:\n        return \"\"\n    if isinstance(v, (dt.date, dt.datetime)):\n        py = fmt.replace(\"yyyy\", \"%Y\").replace(\"mmmm\", \"%B\").replace(\"mmm\", \"%b\").replace(\"dd\", \"%d\").replace(\"mm\", \"%m\")\n        return v.strftime(py)\n    if isinstance(v, (int, float)):\n        if \"%\" in fmt:\n            decimals = len(fmt.split(\".\")[1].rstrip(\"%\")) if \".\" in fmt else 0\n            return f\"{v:.{decimals}%}\"\n        decimals = len(fmt.split(\".\")[1]) if \".\" in fmt else 0\n        return f\"{v:,.{decimals}f}\" if \",\" in fmt else f\"{v:.{decimals}f}\"\n    return str(v)\n\ndef fit_columns(ws, padding=2, max_width=60):\n    widths = {}\n    for row in ws.iter_rows():\n        for c in row:\n            widths[c.column_letter] = max(widths.get(c.column_letter, 0), len(display_text(c)))\n    for letter, w in widths.items():\n        ws.column_dimensions[letter].width = min(w + padding, max_width)\n    return widths\n\nwb = load_workbook(\"narrow.xlsx\")\nprint(fit_columns(wb.active))\nwb.save(\"fitted.xlsx\")\n",[22,624,625,636,640,652,662,678,686,696,767,774,794,808,855,892,924,991,1003,1008,1034,1045,1059,1073,1097,1110,1130,1138,1143,1157,1166],{"__ignoreMap":20},[46,626,627,629,631,633],{"class":48,"line":49},[46,628,113],{"class":96},[46,630,116],{"class":100},[46,632,97],{"class":96},[46,634,635],{"class":100}," load_workbook\n",[46,637,638],{"class":48,"line":110},[46,639,128],{"emptyLinePlaceholder":127},[46,641,642,645,649],{"class":48,"line":124},[46,643,644],{"class":96},"def",[46,646,648],{"class":647},"s_Opv"," display_text",[46,650,651],{"class":100},"(cell):\n",[46,653,654,657,659],{"class":48,"line":131},[46,655,656],{"class":100},"    v, fmt ",[46,658,137],{"class":96},[46,660,661],{"class":100}," cell.value, cell.number_format\n",[46,663,664,667,670,673,676],{"class":48,"line":143},[46,665,666],{"class":96},"    if",[46,668,669],{"class":100}," v ",[46,671,672],{"class":96},"is",[46,674,675],{"class":192}," None",[46,677,307],{"class":100},[46,679,680,683],{"class":48,"line":154},[46,681,682],{"class":96},"        return",[46,684,685],{"class":56}," \"\"\n",[46,687,688,690,693],{"class":48,"line":187},[46,689,666],{"class":96},[46,691,692],{"class":192}," isinstance",[46,694,695],{"class":100},"(v, (dt.date, dt.datetime)):\n",[46,697,698,701,703,706,709,711,714,717,720,722,725,727,730,732,735,739,741,743,746,748,750,753,755,757,760,762,765],{"class":48,"line":230},[46,699,700],{"class":100},"        py ",[46,702,137],{"class":96},[46,704,705],{"class":100}," fmt.replace(",[46,707,708],{"class":56},"\"yyyy\"",[46,710,163],{"class":100},[46,712,713],{"class":56},"\"%Y\"",[46,715,716],{"class":100},").replace(",[46,718,719],{"class":56},"\"mmmm\"",[46,721,163],{"class":100},[46,723,724],{"class":56},"\"%B\"",[46,726,716],{"class":100},[46,728,729],{"class":56},"\"mmm\"",[46,731,163],{"class":100},[46,733,734],{"class":56},"\"",[46,736,738],{"class":737},"sSjpA","%b",[46,740,734],{"class":56},[46,742,716],{"class":100},[46,744,745],{"class":56},"\"dd\"",[46,747,163],{"class":100},[46,749,734],{"class":56},[46,751,752],{"class":737},"%d",[46,754,734],{"class":56},[46,756,716],{"class":100},[46,758,759],{"class":56},"\"mm\"",[46,761,163],{"class":100},[46,763,764],{"class":56},"\"%m\"",[46,766,330],{"class":100},[46,768,769,771],{"class":48,"line":247},[46,770,682],{"class":96},[46,772,773],{"class":100}," v.strftime(py)\n",[46,775,776,778,780,783,786,788,791],{"class":48,"line":262},[46,777,666],{"class":96},[46,779,692],{"class":192},[46,781,782],{"class":100},"(v, (",[46,784,785],{"class":192},"int",[46,787,163],{"class":100},[46,789,790],{"class":192},"float",[46,792,793],{"class":100},")):\n",[46,795,796,799,802,805],{"class":48,"line":277},[46,797,798],{"class":96},"        if",[46,800,801],{"class":56}," \"%\"",[46,803,804],{"class":96}," in",[46,806,807],{"class":100}," fmt:\n",[46,809,810,813,815,818,821,824,827,829,832,835,838,841,844,846,849,852],{"class":48,"line":292},[46,811,812],{"class":100},"            decimals ",[46,814,137],{"class":96},[46,816,817],{"class":192}," len",[46,819,820],{"class":100},"(fmt.split(",[46,822,823],{"class":56},"\".\"",[46,825,826],{"class":100},")[",[46,828,489],{"class":192},[46,830,831],{"class":100},"].rstrip(",[46,833,834],{"class":56},"\"%\"",[46,836,837],{"class":100},")) ",[46,839,840],{"class":96},"if",[46,842,843],{"class":56}," \".\"",[46,845,804],{"class":96},[46,847,848],{"class":100}," fmt ",[46,850,851],{"class":96},"else",[46,853,854],{"class":192}," 0\n",[46,856,857,860,863,865,868,871,874,876,878,881,884,887,889],{"class":48,"line":310},[46,858,859],{"class":96},"            return",[46,861,862],{"class":96}," f",[46,864,734],{"class":56},[46,866,867],{"class":737},"{",[46,869,870],{"class":100},"v",[46,872,873],{"class":96},":",[46,875,32],{"class":100},[46,877,867],{"class":737},[46,879,880],{"class":100},"decimals",[46,882,883],{"class":737},"}",[46,885,886],{"class":96},"%",[46,888,883],{"class":737},[46,890,891],{"class":56},"\"\n",[46,893,894,897,899,901,903,905,907,909,912,914,916,918,920,922],{"class":48,"line":321},[46,895,896],{"class":100},"        decimals ",[46,898,137],{"class":96},[46,900,817],{"class":192},[46,902,820],{"class":100},[46,904,823],{"class":56},[46,906,826],{"class":100},[46,908,489],{"class":192},[46,910,911],{"class":100},"]) ",[46,913,840],{"class":96},[46,915,843],{"class":56},[46,917,804],{"class":96},[46,919,848],{"class":100},[46,921,851],{"class":96},[46,923,854],{"class":192},[46,925,927,929,931,933,935,937,940,942,944,946,948,951,953,955,958,961,963,965,967,969,971,973,975,977,979,981,983,985,987,989],{"class":48,"line":926},15,[46,928,682],{"class":96},[46,930,862],{"class":96},[46,932,734],{"class":56},[46,934,867],{"class":737},[46,936,870],{"class":100},[46,938,939],{"class":96},":,",[46,941,32],{"class":100},[46,943,867],{"class":737},[46,945,880],{"class":100},[46,947,883],{"class":737},[46,949,950],{"class":96},"f",[46,952,883],{"class":737},[46,954,734],{"class":56},[46,956,957],{"class":96}," if",[46,959,960],{"class":56}," \",\"",[46,962,804],{"class":96},[46,964,848],{"class":100},[46,966,851],{"class":96},[46,968,862],{"class":96},[46,970,734],{"class":56},[46,972,867],{"class":737},[46,974,870],{"class":100},[46,976,873],{"class":96},[46,978,32],{"class":100},[46,980,867],{"class":737},[46,982,880],{"class":100},[46,984,883],{"class":737},[46,986,950],{"class":96},[46,988,883],{"class":737},[46,990,891],{"class":56},[46,992,994,997,1000],{"class":48,"line":993},16,[46,995,996],{"class":96},"    return",[46,998,999],{"class":192}," str",[46,1001,1002],{"class":100},"(v)\n",[46,1004,1006],{"class":48,"line":1005},17,[46,1007,128],{"emptyLinePlaceholder":127},[46,1009,1011,1013,1016,1019,1021,1023,1026,1028,1031],{"class":48,"line":1010},18,[46,1012,644],{"class":96},[46,1014,1015],{"class":647}," fit_columns",[46,1017,1018],{"class":100},"(ws, padding",[46,1020,137],{"class":96},[46,1022,525],{"class":192},[46,1024,1025],{"class":100},", max_width",[46,1027,137],{"class":96},[46,1029,1030],{"class":192},"60",[46,1032,1033],{"class":100},"):\n",[46,1035,1037,1040,1042],{"class":48,"line":1036},19,[46,1038,1039],{"class":100},"    widths ",[46,1041,137],{"class":96},[46,1043,1044],{"class":100}," {}\n",[46,1046,1048,1051,1054,1056],{"class":48,"line":1047},20,[46,1049,1050],{"class":96},"    for",[46,1052,1053],{"class":100}," row ",[46,1055,301],{"class":96},[46,1057,1058],{"class":100}," ws.iter_rows():\n",[46,1060,1062,1065,1068,1070],{"class":48,"line":1061},21,[46,1063,1064],{"class":96},"        for",[46,1066,1067],{"class":100}," c ",[46,1069,301],{"class":96},[46,1071,1072],{"class":100}," row:\n",[46,1074,1076,1079,1081,1084,1087,1089,1091,1094],{"class":48,"line":1075},22,[46,1077,1078],{"class":100},"            widths[c.column_letter] ",[46,1080,137],{"class":96},[46,1082,1083],{"class":192}," max",[46,1085,1086],{"class":100},"(widths.get(c.column_letter, ",[46,1088,426],{"class":192},[46,1090,212],{"class":100},[46,1092,1093],{"class":192},"len",[46,1095,1096],{"class":100},"(display_text(c)))\n",[46,1098,1100,1102,1105,1107],{"class":48,"line":1099},23,[46,1101,1050],{"class":96},[46,1103,1104],{"class":100}," letter, w ",[46,1106,301],{"class":96},[46,1108,1109],{"class":100}," widths.items():\n",[46,1111,1113,1116,1118,1121,1124,1127],{"class":48,"line":1112},24,[46,1114,1115],{"class":100},"        ws.column_dimensions[letter].width ",[46,1117,137],{"class":96},[46,1119,1120],{"class":192}," min",[46,1122,1123],{"class":100},"(w ",[46,1125,1126],{"class":96},"+",[46,1128,1129],{"class":100}," padding, max_width)\n",[46,1131,1133,1135],{"class":48,"line":1132},25,[46,1134,996],{"class":96},[46,1136,1137],{"class":100}," widths\n",[46,1139,1141],{"class":48,"line":1140},26,[46,1142,128],{"emptyLinePlaceholder":127},[46,1144,1146,1148,1150,1153,1155],{"class":48,"line":1145},27,[46,1147,134],{"class":100},[46,1149,137],{"class":96},[46,1151,1152],{"class":100}," load_workbook(",[46,1154,327],{"class":56},[46,1156,330],{"class":100},[46,1158,1160,1163],{"class":48,"line":1159},28,[46,1161,1162],{"class":192},"print",[46,1164,1165],{"class":100},"(fit_columns(wb.active))\n",[46,1167,1169,1171,1174],{"class":48,"line":1168},29,[46,1170,324],{"class":100},[46,1172,1173],{"class":56},"\"fitted.xlsx\"",[46,1175,330],{"class":100},[14,1177,1179],{"className":40,"code":1178,"language":42,"meta":20,"style":20},"soffice -env:UserInstallation=file:\u002F\u002F$PWD\u002Flo_profile --headless --convert-to pdf fitted.xlsx > \u002Fdev\u002Fnull 2>&1\npdftotext -layout fitted.pdf - | sed -n '1,2p'\n",[22,1180,1181,1206],{"__ignoreMap":20},[46,1182,1183,1185,1187,1189,1191,1193,1195,1197,1200,1202,1204],{"class":48,"line":49},[46,1184,340],{"class":52},[46,1186,343],{"class":192},[46,1188,346],{"class":100},[46,1190,349],{"class":192},[46,1192,352],{"class":192},[46,1194,355],{"class":192},[46,1196,358],{"class":56},[46,1198,1199],{"class":56}," fitted.xlsx",[46,1201,364],{"class":96},[46,1203,367],{"class":56},[46,1205,370],{"class":96},[46,1207,1208,1210,1212,1215,1217,1219,1221,1223],{"class":48,"line":110},[46,1209,72],{"class":52},[46,1211,377],{"class":192},[46,1213,1214],{"class":56}," fitted.pdf",[46,1216,383],{"class":56},[46,1218,386],{"class":96},[46,1220,389],{"class":52},[46,1222,392],{"class":192},[46,1224,395],{"class":56},[10,1226,1227,1228,1231],{},"Every value now shows in full. The ",[22,1229,1230],{},"max_width"," cap matters for text columns: a description column fitted to its longest entry becomes unreadably wide, and wrapping text is the better answer there.",[34,1233,1235],{"id":1234},"fix-2-let-xlsxwriter-autofit","Fix 2 — Let xlsxwriter autofit",[10,1237,1238,1239,1242],{},"xlsxwriter has ",[22,1240,1241],{},"worksheet.autofit()",", which does the same estimation from the values and formats it wrote. It is the simplest fix when the report is written with xlsxwriter or with pandas using the xlsxwriter engine:",[14,1244,1246],{"className":87,"code":1245,"language":89,"meta":20,"style":20},"import pandas as pd\n\ndf = pd.DataFrame({\"Revenue\": [1234567.89, 98.5], \"Invoice date\": pd.to_datetime([\"2026-09-28\", \"2026-10-01\"]),\n                   \"Customer\": [\"Harbor Foods Ltd\", \"Kestrel\"], \"Units\": [48210, 12]})\nwith pd.ExcelWriter(\"autofit.xlsx\", engine=\"xlsxwriter\", datetime_format=\"dd mmmm yyyy\") as writer:\n    df.to_excel(writer, index=False, sheet_name=\"Report\")\n    ws = writer.sheets[\"Report\"]\n    ws.set_column(\"A:A\", None, writer.book.add_format({\"num_format\": \"#,##0.00\"}))\n    ws.autofit()\n",[22,1247,1248,1260,1264,1305,1335,1375,1400,1415,1443],{"__ignoreMap":20},[46,1249,1250,1252,1255,1257],{"class":48,"line":49},[46,1251,97],{"class":96},[46,1253,1254],{"class":100}," pandas ",[46,1256,104],{"class":96},[46,1258,1259],{"class":100}," pd\n",[46,1261,1262],{"class":48,"line":110},[46,1263,128],{"emptyLinePlaceholder":127},[46,1265,1266,1269,1271,1274,1276,1279,1281,1283,1286,1289,1291,1294,1297,1299,1302],{"class":48,"line":124},[46,1267,1268],{"class":100},"df ",[46,1270,137],{"class":96},[46,1272,1273],{"class":100}," pd.DataFrame({",[46,1275,160],{"class":56},[46,1277,1278],{"class":100},": [",[46,1280,193],{"class":192},[46,1282,163],{"class":100},[46,1284,1285],{"class":192},"98.5",[46,1287,1288],{"class":100},"], ",[46,1290,166],{"class":56},[46,1292,1293],{"class":100},": pd.to_datetime([",[46,1295,1296],{"class":56},"\"2026-09-28\"",[46,1298,163],{"class":100},[46,1300,1301],{"class":56},"\"2026-10-01\"",[46,1303,1304],{"class":100},"]),\n",[46,1306,1307,1310,1312,1314,1316,1319,1321,1323,1325,1327,1329,1332],{"class":48,"line":131},[46,1308,1309],{"class":56},"                   \"Customer\"",[46,1311,1278],{"class":100},[46,1313,215],{"class":56},[46,1315,163],{"class":100},[46,1317,1318],{"class":56},"\"Kestrel\"",[46,1320,1288],{"class":100},[46,1322,176],{"class":56},[46,1324,1278],{"class":100},[46,1326,220],{"class":192},[46,1328,163],{"class":100},[46,1330,1331],{"class":192},"12",[46,1333,1334],{"class":100},"]})\n",[46,1336,1337,1340,1343,1346,1348,1352,1354,1357,1359,1362,1364,1367,1370,1372],{"class":48,"line":143},[46,1338,1339],{"class":96},"with",[46,1341,1342],{"class":100}," pd.ExcelWriter(",[46,1344,1345],{"class":56},"\"autofit.xlsx\"",[46,1347,163],{"class":100},[46,1349,1351],{"class":1350},"sa561","engine",[46,1353,137],{"class":96},[46,1355,1356],{"class":56},"\"xlsxwriter\"",[46,1358,163],{"class":100},[46,1360,1361],{"class":1350},"datetime_format",[46,1363,137],{"class":96},[46,1365,1366],{"class":56},"\"dd mmmm yyyy\"",[46,1368,1369],{"class":100},") ",[46,1371,104],{"class":96},[46,1373,1374],{"class":100}," writer:\n",[46,1376,1377,1380,1383,1385,1388,1390,1393,1395,1398],{"class":48,"line":154},[46,1378,1379],{"class":100},"    df.to_excel(writer, ",[46,1381,1382],{"class":1350},"index",[46,1384,137],{"class":96},[46,1386,1387],{"class":192},"False",[46,1389,163],{"class":100},[46,1391,1392],{"class":1350},"sheet_name",[46,1394,137],{"class":96},[46,1396,1397],{"class":56},"\"Report\"",[46,1399,330],{"class":100},[46,1401,1402,1405,1407,1410,1412],{"class":48,"line":187},[46,1403,1404],{"class":100},"    ws ",[46,1406,137],{"class":96},[46,1408,1409],{"class":100}," writer.sheets[",[46,1411,1397],{"class":56},[46,1413,1414],{"class":100},"]\n",[46,1416,1417,1420,1423,1425,1428,1431,1434,1437,1440],{"class":48,"line":230},[46,1418,1419],{"class":100},"    ws.set_column(",[46,1421,1422],{"class":56},"\"A:A\"",[46,1424,163],{"class":100},[46,1426,1427],{"class":192},"None",[46,1429,1430],{"class":100},", writer.book.add_format({",[46,1432,1433],{"class":56},"\"num_format\"",[46,1435,1436],{"class":100},": ",[46,1438,1439],{"class":56},"\"#,##0.00\"",[46,1441,1442],{"class":100},"}))\n",[46,1444,1445],{"class":48,"line":247},[46,1446,1447],{"class":100},"    ws.autofit()\n",[14,1449,1451],{"className":40,"code":1450,"language":42,"meta":20,"style":20},"soffice -env:UserInstallation=file:\u002F\u002F$PWD\u002Flo_profile --headless --convert-to pdf autofit.xlsx > \u002Fdev\u002Fnull 2>&1\npdftotext -layout autofit.pdf - | sed -n '1,3p'\n",[22,1452,1453,1478],{"__ignoreMap":20},[46,1454,1455,1457,1459,1461,1463,1465,1467,1469,1472,1474,1476],{"class":48,"line":49},[46,1456,340],{"class":52},[46,1458,343],{"class":192},[46,1460,346],{"class":100},[46,1462,349],{"class":192},[46,1464,352],{"class":192},[46,1466,355],{"class":192},[46,1468,358],{"class":56},[46,1470,1471],{"class":56}," autofit.xlsx",[46,1473,364],{"class":96},[46,1475,367],{"class":56},[46,1477,370],{"class":96},[46,1479,1480,1482,1484,1487,1489,1491,1493,1495],{"class":48,"line":110},[46,1481,72],{"class":52},[46,1483,377],{"class":192},[46,1485,1486],{"class":56}," autofit.pdf",[46,1488,383],{"class":56},[46,1490,386],{"class":96},[46,1492,389],{"class":52},[46,1494,392],{"class":192},[46,1496,1497],{"class":56}," '1,3p'\n",[10,1499,1500,1501,1504,1505,1508],{},"Revenue fits, but the dates are hash marks again, in both rows. ",[22,1502,1503],{},"autofit()"," is an estimate, and it does not read number formats: every date is sized as if it were ",[22,1506,1507],{},"mm\u002Fdd\u002Fyyyy",", and numbers are sized by their raw digits rather than their formatted text. A long date format, thousands separators on large numbers, or a currency symbol all come out narrower than they display. Size those columns yourself after calling it:",[14,1510,1512],{"className":87,"code":1511,"language":89,"meta":20,"style":20},"with pd.ExcelWriter(\"autofit.xlsx\", engine=\"xlsxwriter\", datetime_format=\"dd mmmm yyyy\") as writer:\n    df.to_excel(writer, index=False, sheet_name=\"Report\")\n    ws = writer.sheets[\"Report\"]\n    ws.set_column(\"A:A\", None, writer.book.add_format({\"num_format\": \"#,##0.00\"}))\n    ws.autofit()\n    ws.set_column(\"B:B\", len(\"28 September 2026\") + 2)     # autofit assumes mm\u002Fdd\u002Fyyyy\n",[22,1513,1514,1544,1564,1576,1596,1600],{"__ignoreMap":20},[46,1515,1516,1518,1520,1522,1524,1526,1528,1530,1532,1534,1536,1538,1540,1542],{"class":48,"line":49},[46,1517,1339],{"class":96},[46,1519,1342],{"class":100},[46,1521,1345],{"class":56},[46,1523,163],{"class":100},[46,1525,1351],{"class":1350},[46,1527,137],{"class":96},[46,1529,1356],{"class":56},[46,1531,163],{"class":100},[46,1533,1361],{"class":1350},[46,1535,137],{"class":96},[46,1537,1366],{"class":56},[46,1539,1369],{"class":100},[46,1541,104],{"class":96},[46,1543,1374],{"class":100},[46,1545,1546,1548,1550,1552,1554,1556,1558,1560,1562],{"class":48,"line":110},[46,1547,1379],{"class":100},[46,1549,1382],{"class":1350},[46,1551,137],{"class":96},[46,1553,1387],{"class":192},[46,1555,163],{"class":100},[46,1557,1392],{"class":1350},[46,1559,137],{"class":96},[46,1561,1397],{"class":56},[46,1563,330],{"class":100},[46,1565,1566,1568,1570,1572,1574],{"class":48,"line":124},[46,1567,1404],{"class":100},[46,1569,137],{"class":96},[46,1571,1409],{"class":100},[46,1573,1397],{"class":56},[46,1575,1414],{"class":100},[46,1577,1578,1580,1582,1584,1586,1588,1590,1592,1594],{"class":48,"line":131},[46,1579,1419],{"class":100},[46,1581,1422],{"class":56},[46,1583,163],{"class":100},[46,1585,1427],{"class":192},[46,1587,1430],{"class":100},[46,1589,1433],{"class":56},[46,1591,1436],{"class":100},[46,1593,1439],{"class":56},[46,1595,1442],{"class":100},[46,1597,1598],{"class":48,"line":143},[46,1599,1447],{"class":100},[46,1601,1602,1604,1607,1609,1611,1614,1617,1619,1621,1624,1627],{"class":48,"line":154},[46,1603,1419],{"class":100},[46,1605,1606],{"class":56},"\"B:B\"",[46,1608,163],{"class":100},[46,1610,1093],{"class":192},[46,1612,1613],{"class":100},"(",[46,1615,1616],{"class":56},"\"28 September 2026\"",[46,1618,1369],{"class":100},[46,1620,1126],{"class":96},[46,1622,1623],{"class":192}," 2",[46,1625,1626],{"class":100},")     ",[46,1628,1630],{"class":1629},"s-wDw","# autofit assumes mm\u002Fdd\u002Fyyyy\n",[14,1632,1633],{"className":40,"code":1450,"language":42,"meta":20,"style":20},[22,1634,1635,1659],{"__ignoreMap":20},[46,1636,1637,1639,1641,1643,1645,1647,1649,1651,1653,1655,1657],{"class":48,"line":49},[46,1638,340],{"class":52},[46,1640,343],{"class":192},[46,1642,346],{"class":100},[46,1644,349],{"class":192},[46,1646,352],{"class":192},[46,1648,355],{"class":192},[46,1650,358],{"class":56},[46,1652,1471],{"class":56},[46,1654,364],{"class":96},[46,1656,367],{"class":56},[46,1658,370],{"class":96},[46,1660,1661,1663,1665,1667,1669,1671,1673,1675],{"class":48,"line":110},[46,1662,72],{"class":52},[46,1664,377],{"class":192},[46,1666,1486],{"class":56},[46,1668,383],{"class":56},[46,1670,386],{"class":96},[46,1672,389],{"class":52},[46,1674,392],{"class":192},[46,1676,1497],{"class":56},[404,1678,413,1684,413,1687,413,1690,413,1695,413,1699,413,1704,413,1708,413,1712,413,1716,413,1720,413,1723,413,1727,413,1729,413,1732,413,1734,413,1737,413,1740,413,1744,413,1746,413,1749,413,1751,413,1754,413,1757,413,1761,413,1763,413,1766,413,1770],{"viewBox":1679,"role":407,"ariaLabelledBy":1680,"xmlns":411,"style":1683},"176 0 407 144",[1681,1682],"hm-autofit-t","hm-autofit-d","width:100%;max-width:407px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[415,1685,1686],{"id":1681},"What autofit measures and what Excel displays",[419,1688,1689],{"id":1682},"A table comparing autofit's estimate with the displayed text. A date is estimated as mm\u002Fdd\u002Fyyyy, ten characters, but displays as 28 September 2026, seventeen. A number is estimated from its raw digits, 1234567.89, ten characters, but displays as 1,234,567.89, twelve. A text value is measured as written.",[423,1691],{"x":1692,"y":426,"width":1693,"height":1694,"fill":429},"176","407","144",[423,1696],{"x":1697,"y":433,"width":1698,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},"192.9","69.4",[19,1700,1703],{"x":1701,"y":1702,"style":497},"227.7","35.0","Value",[423,1705],{"x":1706,"y":433,"width":1707,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},"262.4","145.2",[19,1709,1711],{"x":1710,"y":1702,"style":497},"335.0","autofit measures",[423,1713],{"x":1714,"y":433,"width":1715,"height":484,"rx":426,"fill":492,"stroke":493,"style":494},"407.6","159.5",[19,1717,1719],{"x":1718,"y":1702,"style":497},"487.3","Excel displays",[423,1721],{"x":1697,"y":1722,"width":1698,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},"44.0",[19,1724,1726],{"x":1701,"y":1725,"style":549},"63.0","Date",[423,1728],{"x":1706,"y":1722,"width":1707,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},[19,1730,1731],{"x":1710,"y":1725,"style":549},"mm\u002Fdd\u002Fyyyy (10)",[423,1733],{"x":1714,"y":1722,"width":1715,"height":484,"rx":426,"fill":528,"stroke":529,"style":494},[19,1735,1736],{"x":1718,"y":1725,"style":532},"28 September 2026 (17)",[423,1738],{"x":1697,"y":1739,"width":1698,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},"72.0",[19,1741,1743],{"x":1701,"y":1742,"style":549},"91.0","Number",[423,1745],{"x":1706,"y":1739,"width":1707,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},[19,1747,1748],{"x":1710,"y":1742,"style":549},"1234567.89 (10)",[423,1750],{"x":1714,"y":1739,"width":1715,"height":484,"rx":426,"fill":539,"stroke":540,"style":494},[19,1752,1753],{"x":1718,"y":1742,"style":543},"1,234,567.89 (12)",[423,1755],{"x":1697,"y":1756,"width":1698,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},"100.0",[19,1758,1760],{"x":1701,"y":1759,"style":549},"119.0","Text",[423,1762],{"x":1706,"y":1756,"width":1707,"height":484,"rx":426,"fill":429,"stroke":437,"style":438},[19,1764,1765],{"x":1710,"y":1759,"style":549},"Harbor Foods Ltd (16)",[423,1767],{"x":1714,"y":1756,"width":1715,"height":484,"rx":426,"fill":1768,"stroke":1769,"style":494},"#d9f4f1","var(--teal,#0f9488)",[19,1771,1765],{"x":1718,"y":1759,"style":1772},"font-size:11px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle",[10,1774,1775,1777],{},[22,1776,1503],{}," must also run after the data is written, and it only knows about what xlsxwriter wrote; formulas contribute nothing because their results are not known when the file is written. For formula columns, set a width yourself.",[404,1779,413,1785,413,1788,413,1791,413,1796,413,1802,413,1813,413,1819,413,1824,413,1828,413,1833,413,1838,413,1841,413,1848,413,1854,413,1858,413,1862,413,1865,413,1868,413,1875,413,1880,413,1883,413,1886,413,1890,413,1893,413,1896,413,1902,413,1906,413,1909,413,1911,413,1915,413,1918,413,1921,413,1928,413,1933,413,1937],{"viewBox":1780,"role":407,"ariaLabelledBy":1781,"xmlns":411,"style":1784},"4 0 752 142",[1782,1783],"hm-fixes-t","hm-fixes-d","width:100%;max-width:752px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif",[415,1786,1787],{"id":1782},"Choosing a fix",[419,1789,1790],{"id":1783},"If the column can be as wide as the data, set its width from the formatted values or call autofit. If the width is fixed by a template or print layout, use a shorter number format or shrink to fit. Then render the sheet to check.",[423,1792],{"x":1793,"y":426,"width":1794,"height":1795,"fill":429},"4","752","142",[423,1797],{"x":1798,"y":433,"width":1799,"height":1800,"rx":1331,"fill":528,"stroke":529,"style":1801},"20.0","115.2","110.5","stroke-width:2px",[1803,1804,1806],"g",{"transform":1805},"translate(65.6,29.0) scale(1.000)",[1807,1808],"path",{"d":1809,"fill":1810,"stroke":1811,"style":1812},"M12 3.5l9.5 17h-19z M12 10v5 M12 17.8v.4","none","var(--accent-ink,#be185d)","stroke-width:1.80px;stroke-linecap:round;stroke-linejoin:round",[19,1814,1818],{"x":1815,"y":1816,"style":1817},"77.6","75.5","font-size:13.5px;font-weight:700;fill:var(--accent-ink,#be185d);text-anchor:middle","#####",[19,1820,1823],{"x":1815,"y":1821,"style":1822},"95.0","font-size:11.5px;font-weight:400;fill:var(--text,#172033);text-anchor:middle","value wider",[19,1825,1827],{"x":1815,"y":1826,"style":1822},"112.5","than column",[48,1829],{"x1":1830,"y1":1831,"x2":1832,"y2":1831,"stroke":493,"style":1801},"140.2","71.2","162.2",[1834,1835],"polygon",{"points":1836,"fill":1837},"166.2,71.2 157.2,76.2 157.2,66.2","#5b5cf0",[423,1839],{"x":1840,"y":433,"width":1799,"height":1800,"rx":1331,"fill":436,"stroke":437,"style":1801},"171.2",[1803,1842,1844],{"transform":1843},"translate(216.8,37.8) scale(1.000)",[1807,1845],{"d":1846,"fill":1810,"stroke":1847,"style":1812},"M11 4a7 7 0 1 0 .01 0z M16 16l5 5","var(--text,#172033)",[19,1849,1853],{"x":1850,"y":1851,"style":1852},"228.8","84.2","font-size:13.5px;font-weight:700;fill:var(--text,#172033);text-anchor:middle","Width free?",[19,1855,1857],{"x":1850,"y":1856,"style":1822},"103.8","yes",[48,1859],{"x1":1860,"y1":1831,"x2":1861,"y2":1831,"stroke":493,"style":1801},"291.4","313.4",[1834,1863],{"points":1864,"fill":1837},"317.4,71.2 308.4,76.2 308.4,66.2",[423,1866],{"x":1867,"y":433,"width":1799,"height":1800,"rx":1331,"fill":1768,"stroke":1769,"style":1801},"322.4",[1803,1869,1871],{"transform":1870},"translate(368.0,29.0) scale(1.000)",[1807,1872],{"d":1873,"fill":1810,"stroke":1874,"style":1812},"M3 5h18v14H3z M3 10h18 M3 15h18 M9 5v14","var(--teal-ink,#0b6157)",[19,1876,1879],{"x":1877,"y":1816,"style":1878},"380.0","font-size:13.5px;font-weight:700;fill:var(--teal-ink,#0b6157);text-anchor:middle","Fit or autofit",[19,1881,1882],{"x":1877,"y":1821,"style":1822},"widths from",[19,1884,1885],{"x":1877,"y":1826,"style":1822},"values",[48,1887],{"x1":1888,"y1":1831,"x2":1889,"y2":1831,"stroke":493,"style":1801},"442.6","464.6",[1834,1891],{"points":1892,"fill":1837},"468.6,71.2 459.6,76.2 459.6,66.2",[423,1894],{"x":1895,"y":433,"width":1799,"height":1800,"rx":1331,"fill":436,"stroke":437,"style":1801},"473.6",[1803,1897,1899],{"transform":1898},"translate(519.2,29.0) scale(1.000)",[1807,1900],{"d":1901,"fill":1810,"stroke":1847,"style":1812},"M4 4h16v16H4z M4 9h16 M4 14h16 M10 4v16",[19,1903,1905],{"x":1904,"y":1816,"style":1852},"531.2","Width fixed?",[19,1907,1908],{"x":1904,"y":1821,"style":1822},"template or",[19,1910,1162],{"x":1904,"y":1826,"style":1822},[48,1912],{"x1":1913,"y1":1831,"x2":1914,"y2":1831,"stroke":493,"style":1801},"593.8","615.8",[1834,1916],{"points":1917,"fill":1837},"619.8,71.2 610.8,76.2 610.8,66.2",[423,1919],{"x":1920,"y":433,"width":1799,"height":1800,"rx":1331,"fill":539,"stroke":540,"style":1801},"624.8",[1803,1922,1924],{"transform":1923},"translate(670.4,29.0) scale(1.000)",[1807,1925],{"d":1926,"fill":1810,"stroke":1927,"style":1812},"M3 5h18l-7 8v6l-4 2v-8z","var(--gold-ink,#7a4e06)",[19,1929,1932],{"x":1930,"y":1816,"style":1931},"682.4","font-size:13.5px;font-weight:700;fill:var(--gold-ink,#7a4e06);text-anchor:middle","Shorter",[19,1934,1936],{"x":1930,"y":1935,"style":1931},"93.0","format",[19,1938,1939],{"x":1930,"y":1826,"style":1822},"or shrink to fit",[34,1941,1943],{"id":1942},"fix-3-when-the-width-is-fixed","Fix 3 — When the width is fixed",[10,1945,1946,1947,1950,1951,1953,1954,1957,1958,1961,1962,1965],{},"Templates and print layouts often fix column widths. Then change what is displayed instead: a shorter number format (",[22,1948,1949],{},"#,##0"," instead of ",[22,1952,578],{},", thousands with ",[22,1955,1956],{},"#,##0,\"k\"",", dates as ",[22,1959,1960],{},"dd\u002Fmm\u002Fyy","), or ",[22,1963,1964],{},"shrink_to_fit",", which reduces the font size until the value fits:",[14,1967,1969],{"className":87,"code":1968,"language":89,"meta":20,"style":20},"from openpyxl.styles import Alignment\n\nwb = load_workbook(\"narrow.xlsx\")\nws = wb.active\nws[\"A2\"].number_format = '#,##0,\"k\"'\nws[\"B2\"].number_format = \"dd\u002Fmm\u002Fyy\"\nws[\"D2\"].alignment = Alignment(shrink_to_fit=True)\nfor col, width in {\"A\": 8, \"B\": 9, \"D\": 6}.items():\n    ws.column_dimensions[col].width = width\nwb.save(\"fixed_width.xlsx\")\n",[22,1970,1971,1983,1987,1999,2007,2020,2033,2056,2098,2107],{"__ignoreMap":20},[46,1972,1973,1975,1978,1980],{"class":48,"line":49},[46,1974,113],{"class":96},[46,1976,1977],{"class":100}," openpyxl.styles ",[46,1979,97],{"class":96},[46,1981,1982],{"class":100}," Alignment\n",[46,1984,1985],{"class":48,"line":110},[46,1986,128],{"emptyLinePlaceholder":127},[46,1988,1989,1991,1993,1995,1997],{"class":48,"line":124},[46,1990,134],{"class":100},[46,1992,137],{"class":96},[46,1994,1152],{"class":100},[46,1996,327],{"class":56},[46,1998,330],{"class":100},[46,2000,2001,2003,2005],{"class":48,"line":131},[46,2002,146],{"class":100},[46,2004,137],{"class":96},[46,2006,151],{"class":100},[46,2008,2009,2011,2013,2015,2017],{"class":48,"line":143},[46,2010,233],{"class":100},[46,2012,236],{"class":56},[46,2014,239],{"class":100},[46,2016,137],{"class":96},[46,2018,2019],{"class":56}," '#,##0,\"k\"'\n",[46,2021,2022,2024,2026,2028,2030],{"class":48,"line":154},[46,2023,233],{"class":100},[46,2025,252],{"class":56},[46,2027,239],{"class":100},[46,2029,137],{"class":96},[46,2031,2032],{"class":56}," \"dd\u002Fmm\u002Fyy\"\n",[46,2034,2035,2037,2039,2042,2044,2047,2049,2051,2054],{"class":48,"line":187},[46,2036,233],{"class":100},[46,2038,267],{"class":56},[46,2040,2041],{"class":100},"].alignment ",[46,2043,137],{"class":96},[46,2045,2046],{"class":100}," Alignment(",[46,2048,1964],{"class":1350},[46,2050,137],{"class":96},[46,2052,2053],{"class":192},"True",[46,2055,330],{"class":100},[46,2057,2058,2060,2063,2065,2068,2071,2073,2076,2078,2081,2083,2085,2087,2090,2092,2095],{"class":48,"line":230},[46,2059,295],{"class":96},[46,2061,2062],{"class":100}," col, width ",[46,2064,301],{"class":96},[46,2066,2067],{"class":100}," {",[46,2069,2070],{"class":56},"\"A\"",[46,2072,1436],{"class":100},[46,2074,2075],{"class":192},"8",[46,2077,163],{"class":100},[46,2079,2080],{"class":56},"\"B\"",[46,2082,1436],{"class":100},[46,2084,204],{"class":192},[46,2086,163],{"class":100},[46,2088,2089],{"class":56},"\"D\"",[46,2091,1436],{"class":100},[46,2093,2094],{"class":192},"6",[46,2096,2097],{"class":100},"}.items():\n",[46,2099,2100,2102,2104],{"class":48,"line":247},[46,2101,313],{"class":100},[46,2103,137],{"class":96},[46,2105,2106],{"class":100}," width\n",[46,2108,2109,2111,2114],{"class":48,"line":262},[46,2110,324],{"class":100},[46,2112,2113],{"class":56},"\"fixed_width.xlsx\"",[46,2115,330],{"class":100},[14,2117,2119],{"className":40,"code":2118,"language":42,"meta":20,"style":20},"soffice -env:UserInstallation=file:\u002F\u002F$PWD\u002Flo_profile --headless --convert-to pdf fixed_width.xlsx > \u002Fdev\u002Fnull 2>&1\npdftotext -layout fixed_width.pdf - | sed -n '1,2p'\n",[22,2120,2121,2146],{"__ignoreMap":20},[46,2122,2123,2125,2127,2129,2131,2133,2135,2137,2140,2142,2144],{"class":48,"line":49},[46,2124,340],{"class":52},[46,2126,343],{"class":192},[46,2128,346],{"class":100},[46,2130,349],{"class":192},[46,2132,352],{"class":192},[46,2134,355],{"class":192},[46,2136,358],{"class":56},[46,2138,2139],{"class":56}," fixed_width.xlsx",[46,2141,364],{"class":96},[46,2143,367],{"class":56},[46,2145,370],{"class":96},[46,2147,2148,2150,2152,2155,2157,2159,2161,2163],{"class":48,"line":110},[46,2149,72],{"class":52},[46,2151,377],{"class":192},[46,2153,2154],{"class":56}," fixed_width.pdf",[46,2156,383],{"class":56},[46,2158,386],{"class":96},[46,2160,389],{"class":52},[46,2162,392],{"class":192},[46,2164,395],{"class":56},[10,2166,2167,2168,2172],{},"Shrinking works for the odd long value; used on a whole column it produces text too small to read, so prefer a shorter format. ",[28,2169,2171],{"href":2170},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-numbers-in-thousands-and-millions-in-excel\u002F","Format Numbers in Thousands and Millions in Excel with Python"," covers the scaling formats.",[34,2174,2176],{"id":2175},"negative-dates-and-times","Negative dates and times",[10,2178,2179,2180,2182,2183,2186,2187,2190,2191,2194],{},"One case is not about width at all. In Excel's default date system, dates and times are positive numbers of days since 1900, and a negative date or time cannot be displayed; Excel shows ",[22,2181,1818],{}," however wide the column. It typically appears when a script writes a time difference that came out negative, for example an end time earlier than a start time, formatted as ",[22,2184,2185],{},"hh:mm",". LibreOffice is more lenient and wraps it around the clock, showing ",[22,2188,2189],{},"-0.25"," days as ",[22,2192,2193],{},"18:00",", which is misleading in a different way. Fix the calculation or write such differences as plain numbers of hours:",[14,2196,2198],{"className":87,"code":2197,"language":89,"meta":20,"style":20},"start, end = dt.datetime(2026, 9, 28, 18, 0), dt.datetime(2026, 9, 28, 12, 0)\nhours = (end - start).total_seconds() \u002F 3600\nprint(f\"{hours:+.2f} hours\")\n",[22,2199,2200,2252,2274],{"__ignoreMap":20},[46,2201,2202,2205,2207,2210,2212,2214,2216,2218,2220,2222,2225,2227,2229,2232,2234,2236,2238,2240,2242,2244,2246,2248,2250],{"class":48,"line":49},[46,2203,2204],{"class":100},"start, end ",[46,2206,137],{"class":96},[46,2208,2209],{"class":100}," dt.datetime(",[46,2211,199],{"class":192},[46,2213,163],{"class":100},[46,2215,204],{"class":192},[46,2217,163],{"class":100},[46,2219,209],{"class":192},[46,2221,163],{"class":100},[46,2223,2224],{"class":192},"18",[46,2226,163],{"class":100},[46,2228,426],{"class":192},[46,2230,2231],{"class":100},"), dt.datetime(",[46,2233,199],{"class":192},[46,2235,163],{"class":100},[46,2237,204],{"class":192},[46,2239,163],{"class":100},[46,2241,209],{"class":192},[46,2243,163],{"class":100},[46,2245,1331],{"class":192},[46,2247,163],{"class":100},[46,2249,426],{"class":192},[46,2251,330],{"class":100},[46,2253,2254,2257,2259,2262,2265,2268,2271],{"class":48,"line":110},[46,2255,2256],{"class":100},"hours ",[46,2258,137],{"class":96},[46,2260,2261],{"class":100}," (end ",[46,2263,2264],{"class":96},"-",[46,2266,2267],{"class":100}," start).total_seconds() ",[46,2269,2270],{"class":96},"\u002F",[46,2272,2273],{"class":192}," 3600\n",[46,2275,2276,2278,2280,2282,2284,2286,2289,2292,2294,2297],{"class":48,"line":124},[46,2277,1162],{"class":192},[46,2279,1613],{"class":100},[46,2281,950],{"class":96},[46,2283,734],{"class":56},[46,2285,867],{"class":737},[46,2287,2288],{"class":100},"hours",[46,2290,2291],{"class":96},":+.2f",[46,2293,883],{"class":737},[46,2295,2296],{"class":56}," hours\"",[46,2298,330],{"class":100},[34,2300,2302],{"id":2301},"common-pitfalls","Common pitfalls",[568,2304,2305,2312,2321,2327,2333],{},[571,2306,2307,2311],{},[2308,2309,2310],"strong",{},"Widening for the header only."," Numbers with formats are usually wider than their headers; measure the formatted values.",[571,2313,2314,2317,2318,2320],{},[2308,2315,2316],{},"Autofitting before writing data."," ",[22,2319,1503],{}," measures what has been written so far.",[571,2322,2323,2326],{},[2308,2324,2325],{},"Formula columns."," Their results are unknown when the file is written; give them explicit widths.",[571,2328,2329,2332],{},[2308,2330,2331],{},"Wide text columns."," Cap widths and wrap text rather than fitting a 300-character comment.",[571,2334,2335,2338],{},[2308,2336,2337],{},"Checking only in LibreOffice."," Font metrics differ slightly; leave a character or two of padding.",[34,2340,2342],{"id":2341},"conclusion","Conclusion",[10,2344,2345,2347,2348,2350],{},[22,2346,1818],{}," means a number or date is wider than its column in its current format, or, in Excel, that a date or time is negative. Set column widths from the formatted values with openpyxl, call ",[22,2349,1503],{}," after writing with xlsxwriter, or, where widths are fixed, use a shorter number format or shrink to fit. Render the sheet with LibreOffice to confirm that no value is hidden before the report goes out.",[34,2352,2354],{"id":2353},"frequently-asked-questions","Frequently asked questions",[10,2356,2357,2360],{},[2308,2358,2359],{},"Why does Excel show ##### instead of my number?","\nThe formatted number or date is wider than the column. Widen the column, use a shorter number format, or turn on shrink to fit. The value in the cell is unchanged.",[10,2362,2363,2366],{},[2308,2364,2365],{},"How do I autofit column widths with openpyxl?","\nopenpyxl has no autofit. Loop over the cells, compute the length of each formatted value, and set the column's width in ws.column_dimensions to the longest plus a little padding.",[10,2368,2369,2372],{},[2308,2370,2371],{},"Does xlsxwriter have autofit?","\nYes, worksheet.autofit() estimates widths from the data written so far. Call it after writing the data. It sizes dates as mm\u002Fdd\u002Fyyyy and numbers by their raw digits, and cannot size formula columns, so widen those yourself.",[10,2374,2375,2378],{},[2308,2376,2377],{},"Why does a time difference show as ##### even in a wide column?","\nIn Excel's default date system, negative dates and times cannot be displayed. Correct the calculation or write the difference as a number of hours.",[34,2380,2382],{"id":2381},"related","Related",[568,2384,2385,2391,2396,2403,2410],{},[571,2386,2387,2388,2390],{},"Up one level: ",[28,2389,31],{"href":30}," — the other common errors.",[571,2392,2393,2395],{},[28,2394,2171],{"href":2170}," — shorter formats for fixed widths.",[571,2397,2398,2402],{},[28,2399,2401],{"href":2400},"\u002Fadvanced-data-transformation-and-cleaning\u002Fworking-with-dates-and-times-in-excel-data\u002Fcalculate-working-hours-between-two-timestamps\u002F","Calculate Working Hours Between Two Timestamps"," — time differences done right.",[571,2404,2405,2409],{},[28,2406,2408],{"href":2407},"\u002Fformatting-and-charting-excel-reports-with-python\u002Finserting-images-and-logos-into-excel\u002Frender-an-excel-range-as-an-image\u002F","Render an Excel Range as an Image"," — seeing a sheet the way readers do.",[571,2411,2412,2416],{},[28,2413,2415],{"href":2414},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-floating-point-noise-in-excel-output\u002F","Fix Floating-Point Noise Like 0.1 + 0.2 ≠ 0.3 in Excel Output"," — another display problem with numbers.",[2418,2419,2420],"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 .s_Opv, html code.shiki .s_Opv{--shiki-default:#6F42C1;--shiki-dark:#DBB7FF}html pre.shiki code .sSjpA, html code.shiki .sSjpA{--shiki-default:#005CC5;--shiki-dark:#FF9492}html pre.shiki code .sa561, html code.shiki .sa561{--shiki-default:#E36209;--shiki-dark:#FFB757}html pre.shiki code .s-wDw, html code.shiki .s-wDw{--shiki-default:#6A737D;--shiki-dark:#BDC4CC}",{"title":20,"searchDepth":110,"depth":110,"links":2422},[2423,2424,2425,2426,2427,2428,2429,2430,2431,2432,2433],{"id":36,"depth":110,"text":37},{"id":80,"depth":110,"text":81},{"id":557,"depth":110,"text":558},{"id":615,"depth":110,"text":616},{"id":1234,"depth":110,"text":1235},{"id":1942,"depth":110,"text":1943},{"id":2175,"depth":110,"text":2176},{"id":2301,"depth":110,"text":2302},{"id":2341,"depth":110,"text":2342},{"id":2353,"depth":110,"text":2354},{"id":2381,"depth":110,"text":2382},"2026-09-29","Numbers and dates written from Python show as ##### in Excel when the column is too narrow for the formatted value, and negative dates and times always show that way in Excel. Set widths from the formatted text, use xlsxwriter's autofit, shrink to fit where space is fixed, and check the result by rendering the sheet.","md",[2438,2440,2442,2444],{"q":2359,"a":2439},"The formatted number or date is wider than the column. Widen the column, use a shorter number format, or turn on shrink to fit. The value in the cell is unchanged.",{"q":2365,"a":2441},"openpyxl has no autofit. Loop over the cells, compute the length of each formatted value, and set the column's width in ws.column_dimensions to the longest plus a little padding.",{"q":2371,"a":2443},"Yes, worksheet.autofit() estimates widths from the data written so far. Call it after writing the data. It sizes dates as mm\u002Fdd\u002Fyyyy and numbers by their raw digits, and cannot size formula columns, so widen those yourself.",{"q":2377,"a":2445},"In Excel's default date system, negative dates and times cannot be displayed. Correct the calculation or write the difference as a number of hours.","fix hash marks showing instead of values in excel",null,{"breadcrumb":2449},[2450,2452,2455],{"name":2451,"item":2270},"Home",{"name":2453,"item":2454},"Getting Started with Python Excel Automation","\u002Fgetting-started-with-python-excel-automation\u002F",{"name":31,"item":30},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel",{"title":2458,"description":2459},"Fix ##### in Excel Cells Written by Python (Column Width)","Why Excel shows ##### instead of numbers and dates written with openpyxl, xlsxwriter or pandas: narrow columns, long number formats, negative times. Fix with widths from formatted values, autofit, shrink_to_fit, and a render check.","fix-hash-marks-showing-instead-of-values-in-excel","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-hash-marks-showing-instead-of-values-in-excel\u002Findex",[2463,2464],"troubleshooting","number-formats","how-to","awSoCb5Y13gMf6BO5uoHz3OlSW5uDmdAROLXUQlOCkM",[2468,2472],{"title":2469,"path":2470,"stem":2471,"children":-1},"Fix Formulas Showing as Text in Excel Output from Python","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-formulas-showing-as-text-in-excel-output","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-formulas-showing-as-text-in-excel-output\u002Findex",{"title":2473,"path":2474,"stem":2475,"children":-1},"Fix IllegalCharacterError When Writing Excel with openpyxl","\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-illegalcharactererror-when-writing-excel-with-openpyxl","getting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors\u002Ffix-illegalcharactererror-when-writing-excel-with-openpyxl\u002Findex",[2477,2479],{"path":2478,"title":2453},"\u002Fgetting-started-with-python-excel-automation",{"path":2480,"title":31},"\u002Fgetting-started-with-python-excel-automation\u002Ftroubleshooting-common-python-excel-errors",[],[2483,2487,2490,2493,2496,2499],{"path":2484,"title":2485,"kind":2486},"\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":2488,"title":2489,"kind":2465},"\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":2491,"title":2492,"kind":2486},"\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":2494,"title":2495,"kind":2465},"\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":2497,"title":2498,"kind":2465},"\u002Fautomating-reporting-workflows\u002Fautomating-excel-online-with-microsoft-graph\u002Fhandle-microsoft-graph-throttling-for-excel","Handle Microsoft Graph Throttling in Excel Automation",{"path":2500,"title":2501,"kind":2502},"\u002Fautomating-reporting-workflows\u002Ferror-handling-and-logging-in-excel-automation","Error Handling and Logging in Excel Automation","guide",1790972065801]