[{"data":1,"prerenderedAt":1479},["ShallowReactive",2],{"doc:\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-excel-cells-as-currency-with-python":3,"surround:\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-excel-cells-as-currency-with-python":1471},{"id":4,"title":5,"body":6,"dateModified":1449,"datePublished":1449,"description":1450,"extension":1451,"faq":1452,"meta":1463,"navigation":228,"path":1464,"seo":1465,"slug":1467,"stem":1468,"type":1469,"__hash__":1470},"docs\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-excel-cells-as-currency-with-python\u002Findex.md","Format Excel Cells as Currency with Python",{"type":7,"value":8,"toc":1430},"minimark",[9,28,135,140,164,174,178,200,330,343,347,358,558,565,569,572,739,761,765,772,918,933,937,949,1152,1164,1168,1285,1289,1307,1311,1316,1325,1329,1339,1343,1352,1356,1363,1367,1380,1384,1401,1405,1426],[10,11,12,13,17,18,23,24,27],"p",{},"A column of bare floats like ",[14,15,16],"code",{},"1234.5"," reads as raw data, not money. Currency formatting adds the symbol, thousands separators, and a fixed two decimals — without changing the stored number. This guide, part of ",[19,20,22],"a",{"href":21},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002F","Applying Number and Date Formats in Excel",", walks through formatting single cells, whole columns, foreign symbols, accounting negatives, and a pandas-exported column reopened with ",[14,25,26],{},"openpyxl",". Every snippet is runnable.",[29,30,38,39,38,43,38,47,38,57,38,64,38,68,38,74,38,80,38,84,38,89,38,97,38,101,38,106,38,110,38,114,38,122,38,127,38,132],"svg",{"viewBox":31,"role":32,"ariaLabelledBy":33,"xmlns":36,"style":37},"0 0 760 210","img",[34,35],"cur-t","cur-d","http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","width:100%;max-width:760px;height:auto;display:block;margin:1.5rem auto;font-family:Inter,ui-sans-serif,system-ui,sans-serif","\n  ",[40,41,42],"title",{"id":34},"A raw number plus a currency format code produces a money display",[44,45,46],"desc",{"id":35},"The raw number 1234.5 combined with the format code dollar-hash-comma-zero produces the display $1,234.50, while the stored value stays unchanged.",[48,49],"rect",{"x":50,"y":51,"width":52,"height":53,"rx":54,"fill":55,"stroke":56},"30","64","170","60","12","var(--surface-muted,#eef2ff)","var(--line,#cdd5e6)",[58,59,63],"text",{"x":60,"y":61,"style":62},"115","52","font-size:12px;font-weight:600;fill:var(--muted,#5b6780);text-anchor:middle","Raw number",[58,65,16],{"x":60,"y":66,"style":67},"102","font-size:18px;font-weight:700;fill:var(--text,#172033);text-anchor:middle",[58,69,73],{"x":70,"y":71,"style":72},"290","84","font-size:20px;font-weight:700;fill:var(--muted,#5b6780);text-anchor:middle","+",[48,75],{"x":76,"y":51,"width":77,"height":53,"rx":54,"fill":78,"stroke":79},"330","180","var(--brand,#5b5cf0)","var(--brand-strong,#4338ca)",[58,81,83],{"x":82,"y":61,"style":62},"420","Format code",[58,85,88],{"x":82,"y":86,"style":87},"101","font-size:15px;font-weight:700;fill:#ffffff;text-anchor:middle","$#,##0.00",[90,91],"line",{"x1":92,"y1":93,"x2":94,"y2":93,"stroke":95,"style":96},"512","94","588","var(--teal,#0f9488)","stroke-width:2px",[98,99],"polygon",{"points":100,"fill":95},"588,94 578,89 578,99",[48,102],{"x":103,"y":51,"width":104,"height":53,"rx":54,"fill":105,"stroke":95},"592","160","rgba(15,148,136,0.12)",[58,107,109],{"x":108,"y":61,"style":62},"672","Displayed",[58,111,113],{"x":108,"y":66,"style":112},"font-size:18px;font-weight:700;fill:var(--teal,#0f9488);text-anchor:middle","$1,234.50",[48,115],{"x":116,"y":117,"width":118,"height":119,"rx":120,"fill":121},"280","158","200","34","17","var(--brand-soft,rgba(91,92,240,0.12))",[58,123,126],{"x":124,"y":77,"style":125},"380","font-size:12px;font-weight:600;fill:var(--brand-strong,#4338ca);text-anchor:middle","value 1234.5 unchanged",[90,128],{"x1":60,"y1":129,"x2":130,"y2":117,"stroke":56,"style":131},"126","300","stroke-width:1.5px",[90,133],{"x1":108,"y1":129,"x2":134,"y2":117,"stroke":56,"style":131},"460",[136,137,139],"h2",{"id":138},"prerequisites-and-install","Prerequisites and install",[141,142,147],"pre",{"className":143,"code":144,"language":145,"meta":146,"style":146},"language-bash shiki shiki-themes github-light github-dark","pip install openpyxl\n","bash","",[14,148,149],{"__ignoreMap":146},[150,151,153,157,161],"span",{"class":90,"line":152},1,[150,154,156],{"class":155},"sScJk","pip",[150,158,160],{"class":159},"sZZnC"," install",[150,162,163],{"class":159}," openpyxl\n",[10,165,166,167,170,171,173],{},"For the pandas section: ",[14,168,169],{},"pip install pandas openpyxl",". You need a working Python 3.8+ and the ability to write a file in the current directory. Nothing else — ",[14,172,26],{}," does not need Excel installed.",[136,175,177],{"id":176},"step-1-format-a-single-cell-as-currency","Step 1: Format a single cell as currency",[10,179,180,181,183,184,187,188,191,192,195,196,199],{},"Assign the format code ",[14,182,88],{}," to ",[14,185,186],{},"cell.number_format",". The ",[14,189,190],{},"$"," is a literal symbol, ",[14,193,194],{},"#,##0"," groups thousands, and ",[14,197,198],{},".00"," forces two decimals. The value must be numeric for the format to apply.",[141,201,205],{"className":202,"code":203,"language":204,"meta":146,"style":146},"language-python shiki shiki-themes github-light github-dark","from openpyxl import Workbook\n\nwb = Workbook()\nws = wb.active\nws[\"A1\"] = 1234.5\nws[\"A1\"].number_format = \"$#,##0.00\"   # displays $1,234.50\n\nprint(\"Stored:\", ws[\"A1\"].value)        # 1234.5 — unchanged\nwb.save(\"currency_single.xlsx\")\n","python",[14,206,207,223,230,242,253,271,290,295,318],{"__ignoreMap":146},[150,208,209,213,217,220],{"class":90,"line":152},[150,210,212],{"class":211},"szBVR","from",[150,214,216],{"class":215},"sVt8B"," openpyxl ",[150,218,219],{"class":211},"import",[150,221,222],{"class":215}," Workbook\n",[150,224,226],{"class":90,"line":225},2,[150,227,229],{"emptyLinePlaceholder":228},true,"\n",[150,231,233,236,239],{"class":90,"line":232},3,[150,234,235],{"class":215},"wb ",[150,237,238],{"class":211},"=",[150,240,241],{"class":215}," Workbook()\n",[150,243,245,248,250],{"class":90,"line":244},4,[150,246,247],{"class":215},"ws ",[150,249,238],{"class":211},[150,251,252],{"class":215}," wb.active\n",[150,254,256,259,262,265,267],{"class":90,"line":255},5,[150,257,258],{"class":215},"ws[",[150,260,261],{"class":159},"\"A1\"",[150,263,264],{"class":215},"] ",[150,266,238],{"class":211},[150,268,270],{"class":269},"sj4cs"," 1234.5\n",[150,272,274,276,278,281,283,286],{"class":90,"line":273},6,[150,275,258],{"class":215},[150,277,261],{"class":159},[150,279,280],{"class":215},"].number_format ",[150,282,238],{"class":211},[150,284,285],{"class":159}," \"$#,##0.00\"",[150,287,289],{"class":288},"sJ8bj","   # displays $1,234.50\n",[150,291,293],{"class":90,"line":292},7,[150,294,229],{"emptyLinePlaceholder":228},[150,296,298,301,304,307,310,312,315],{"class":90,"line":297},8,[150,299,300],{"class":269},"print",[150,302,303],{"class":215},"(",[150,305,306],{"class":159},"\"Stored:\"",[150,308,309],{"class":215},", ws[",[150,311,261],{"class":159},[150,313,314],{"class":215},"].value)        ",[150,316,317],{"class":288},"# 1234.5 — unchanged\n",[150,319,321,324,327],{"class":90,"line":320},9,[150,322,323],{"class":215},"wb.save(",[150,325,326],{"class":159},"\"currency_single.xlsx\"",[150,328,329],{"class":215},")\n",[10,331,332,333,335,336,339,340,342],{},"Excel renders ",[14,334,113],{},", but ",[14,337,338],{},"cell.value"," is still ",[14,341,16],{},". The format is purely visual.",[136,344,346],{"id":345},"step-2-apply-currency-down-a-column","Step 2: Apply currency down a column",[10,348,349,350,353,354,357],{},"Reports format an entire column of amounts. Loop the column's cells and set the same code on each, skipping the header. ",[14,351,352],{},"ws[\"C\"]"," yields every cell in column C; ",[14,355,356],{},"[1:]"," drops the header cell.",[141,359,361],{"className":202,"code":360,"language":204,"meta":146,"style":146},"from openpyxl import Workbook\n\nwb = Workbook()\nws = wb.active\nws.append([\"Date\", \"Region\", \"Revenue\"])\nws.append([\"2024-01-05\", \"North\", 23990.5])\nws.append([\"2024-01-06\", \"South\", 12475.0])\nws.append([\"2024-01-07\", \"West\", 1599.2])\n\nfor cell in ws[\"C\"][1:]:               # column C, skip header\n    cell.number_format = \"$#,##0.00\"\n\nwb.save(\"currency_column.xlsx\")\nprint(\"Formatted\", ws.max_row - 1, \"amounts\")\n",[14,362,363,373,377,385,393,415,434,453,472,476,506,517,522,532],{"__ignoreMap":146},[150,364,365,367,369,371],{"class":90,"line":152},[150,366,212],{"class":211},[150,368,216],{"class":215},[150,370,219],{"class":211},[150,372,222],{"class":215},[150,374,375],{"class":90,"line":225},[150,376,229],{"emptyLinePlaceholder":228},[150,378,379,381,383],{"class":90,"line":232},[150,380,235],{"class":215},[150,382,238],{"class":211},[150,384,241],{"class":215},[150,386,387,389,391],{"class":90,"line":244},[150,388,247],{"class":215},[150,390,238],{"class":211},[150,392,252],{"class":215},[150,394,395,398,401,404,407,409,412],{"class":90,"line":255},[150,396,397],{"class":215},"ws.append([",[150,399,400],{"class":159},"\"Date\"",[150,402,403],{"class":215},", ",[150,405,406],{"class":159},"\"Region\"",[150,408,403],{"class":215},[150,410,411],{"class":159},"\"Revenue\"",[150,413,414],{"class":215},"])\n",[150,416,417,419,422,424,427,429,432],{"class":90,"line":273},[150,418,397],{"class":215},[150,420,421],{"class":159},"\"2024-01-05\"",[150,423,403],{"class":215},[150,425,426],{"class":159},"\"North\"",[150,428,403],{"class":215},[150,430,431],{"class":269},"23990.5",[150,433,414],{"class":215},[150,435,436,438,441,443,446,448,451],{"class":90,"line":292},[150,437,397],{"class":215},[150,439,440],{"class":159},"\"2024-01-06\"",[150,442,403],{"class":215},[150,444,445],{"class":159},"\"South\"",[150,447,403],{"class":215},[150,449,450],{"class":269},"12475.0",[150,452,414],{"class":215},[150,454,455,457,460,462,465,467,470],{"class":90,"line":297},[150,456,397],{"class":215},[150,458,459],{"class":159},"\"2024-01-07\"",[150,461,403],{"class":215},[150,463,464],{"class":159},"\"West\"",[150,466,403],{"class":215},[150,468,469],{"class":269},"1599.2",[150,471,414],{"class":215},[150,473,474],{"class":90,"line":320},[150,475,229],{"emptyLinePlaceholder":228},[150,477,479,482,485,488,491,494,497,500,503],{"class":90,"line":478},10,[150,480,481],{"class":211},"for",[150,483,484],{"class":215}," cell ",[150,486,487],{"class":211},"in",[150,489,490],{"class":215}," ws[",[150,492,493],{"class":159},"\"C\"",[150,495,496],{"class":215},"][",[150,498,499],{"class":269},"1",[150,501,502],{"class":215},":]:               ",[150,504,505],{"class":288},"# column C, skip header\n",[150,507,509,512,514],{"class":90,"line":508},11,[150,510,511],{"class":215},"    cell.number_format ",[150,513,238],{"class":211},[150,515,516],{"class":159}," \"$#,##0.00\"\n",[150,518,520],{"class":90,"line":519},12,[150,521,229],{"emptyLinePlaceholder":228},[150,523,525,527,530],{"class":90,"line":524},13,[150,526,323],{"class":215},[150,528,529],{"class":159},"\"currency_column.xlsx\"",[150,531,329],{"class":215},[150,533,535,537,539,542,545,548,551,553,556],{"class":90,"line":534},14,[150,536,300],{"class":269},[150,538,303],{"class":215},[150,540,541],{"class":159},"\"Formatted\"",[150,543,544],{"class":215},", ws.max_row ",[150,546,547],{"class":211},"-",[150,549,550],{"class":269}," 1",[150,552,403],{"class":215},[150,554,555],{"class":159},"\"amounts\"",[150,557,329],{"class":215},[10,559,560,561,564],{},"To format an arbitrary range instead of a full column, iterate ",[14,562,563],{},"ws.iter_rows(min_row=2, min_col=3, max_col=3)"," and set the format on each cell.",[136,566,568],{"id":567},"step-3-other-currency-symbols-and-locale-notes","Step 3: Other currency symbols (€, £) and locale notes",[10,570,571],{},"Swap the literal symbol in the format string. For currencies that trail the amount, put the symbol after the number with a non-breaking space.",[141,573,575],{"className":202,"code":574,"language":204,"meta":146,"style":146},"from openpyxl import Workbook\n\nwb = Workbook()\nws = wb.active\nws.append([\"Currency\", \"Amount\"])\nws.append([\"USD\", 1234.5])\nws.append([\"EUR\", 1234.5])\nws.append([\"GBP\", 1234.5])\n\nws[\"B2\"].number_format = \"$#,##0.00\"      # $1,234.50\nws[\"B3\"].number_format = \"€#,##0.00\"      # €1,234.50\nws[\"B4\"].number_format = \"£#,##0.00\"      # £1,234.50\n\nwb.save(\"currency_symbols.xlsx\")\nprint(\"Applied $, €, and £ formats\")\n",[14,576,577,587,591,599,607,621,634,647,660,664,680,697,714,718,727],{"__ignoreMap":146},[150,578,579,581,583,585],{"class":90,"line":152},[150,580,212],{"class":211},[150,582,216],{"class":215},[150,584,219],{"class":211},[150,586,222],{"class":215},[150,588,589],{"class":90,"line":225},[150,590,229],{"emptyLinePlaceholder":228},[150,592,593,595,597],{"class":90,"line":232},[150,594,235],{"class":215},[150,596,238],{"class":211},[150,598,241],{"class":215},[150,600,601,603,605],{"class":90,"line":244},[150,602,247],{"class":215},[150,604,238],{"class":211},[150,606,252],{"class":215},[150,608,609,611,614,616,619],{"class":90,"line":255},[150,610,397],{"class":215},[150,612,613],{"class":159},"\"Currency\"",[150,615,403],{"class":215},[150,617,618],{"class":159},"\"Amount\"",[150,620,414],{"class":215},[150,622,623,625,628,630,632],{"class":90,"line":273},[150,624,397],{"class":215},[150,626,627],{"class":159},"\"USD\"",[150,629,403],{"class":215},[150,631,16],{"class":269},[150,633,414],{"class":215},[150,635,636,638,641,643,645],{"class":90,"line":292},[150,637,397],{"class":215},[150,639,640],{"class":159},"\"EUR\"",[150,642,403],{"class":215},[150,644,16],{"class":269},[150,646,414],{"class":215},[150,648,649,651,654,656,658],{"class":90,"line":297},[150,650,397],{"class":215},[150,652,653],{"class":159},"\"GBP\"",[150,655,403],{"class":215},[150,657,16],{"class":269},[150,659,414],{"class":215},[150,661,662],{"class":90,"line":320},[150,663,229],{"emptyLinePlaceholder":228},[150,665,666,668,671,673,675,677],{"class":90,"line":478},[150,667,258],{"class":215},[150,669,670],{"class":159},"\"B2\"",[150,672,280],{"class":215},[150,674,238],{"class":211},[150,676,285],{"class":159},[150,678,679],{"class":288},"      # $1,234.50\n",[150,681,682,684,687,689,691,694],{"class":90,"line":508},[150,683,258],{"class":215},[150,685,686],{"class":159},"\"B3\"",[150,688,280],{"class":215},[150,690,238],{"class":211},[150,692,693],{"class":159}," \"€#,##0.00\"",[150,695,696],{"class":288},"      # €1,234.50\n",[150,698,699,701,704,706,708,711],{"class":90,"line":519},[150,700,258],{"class":215},[150,702,703],{"class":159},"\"B4\"",[150,705,280],{"class":215},[150,707,238],{"class":211},[150,709,710],{"class":159}," \"£#,##0.00\"",[150,712,713],{"class":288},"      # £1,234.50\n",[150,715,716],{"class":90,"line":524},[150,717,229],{"emptyLinePlaceholder":228},[150,719,720,722,725],{"class":90,"line":534},[150,721,323],{"class":215},[150,723,724],{"class":159},"\"currency_symbols.xlsx\"",[150,726,329],{"class":215},[150,728,730,732,734,737],{"class":90,"line":729},15,[150,731,300],{"class":269},[150,733,303],{"class":215},[150,735,736],{"class":159},"\"Applied $, €, and £ formats\"",[150,738,329],{"class":215},[10,740,741,742,745,746,749,750,754,755,757,758,760],{},"The symbol is just text inside the format string, so any Unicode currency glyph works. Note that the format does not convert exchange rates or follow a system locale — it only displays the symbol you type. If you need European-style separators (",[14,743,744],{},"."," for thousands, ",[14,747,748],{},","," for decimals), that depends on the ",[751,752,753],"em",{},"reader's"," Excel regional settings; the stored format code uses ",[14,756,748],{}," and ",[14,759,744],{}," as the structural placeholders regardless.",[136,762,764],{"id":763},"step-4-accounting-format-with-parentheses-for-negatives","Step 4: Accounting format with parentheses for negatives",[10,766,767,768,771],{},"Accounting layouts show losses in parentheses and often align the symbol to the left. Use a two-section code separated by a semicolon: positive section, then negative section. Add ",[14,769,770],{},"[Red]"," to color negatives.",[141,773,775],{"className":202,"code":774,"language":204,"meta":146,"style":146},"from openpyxl import Workbook\n\nwb = Workbook()\nws = wb.active\nws.append([\"Account\", \"Balance\"])\nws.append([\"Operating\", 8200.40])\nws.append([\"Overdraft\", -1530.75])\n\ncode = \"$#,##0.00;[Red]($#,##0.00)\"\nfor cell in ws[\"B\"][1:]:\n    cell.number_format = code\n\nwb.save(\"currency_accounting.xlsx\")\nprint(\"8200.40 → $8,200.40 ; -1530.75 → red ($1,530.75)\")\n",[14,776,777,787,791,799,807,821,835,851,855,865,885,894,898,907],{"__ignoreMap":146},[150,778,779,781,783,785],{"class":90,"line":152},[150,780,212],{"class":211},[150,782,216],{"class":215},[150,784,219],{"class":211},[150,786,222],{"class":215},[150,788,789],{"class":90,"line":225},[150,790,229],{"emptyLinePlaceholder":228},[150,792,793,795,797],{"class":90,"line":232},[150,794,235],{"class":215},[150,796,238],{"class":211},[150,798,241],{"class":215},[150,800,801,803,805],{"class":90,"line":244},[150,802,247],{"class":215},[150,804,238],{"class":211},[150,806,252],{"class":215},[150,808,809,811,814,816,819],{"class":90,"line":255},[150,810,397],{"class":215},[150,812,813],{"class":159},"\"Account\"",[150,815,403],{"class":215},[150,817,818],{"class":159},"\"Balance\"",[150,820,414],{"class":215},[150,822,823,825,828,830,833],{"class":90,"line":273},[150,824,397],{"class":215},[150,826,827],{"class":159},"\"Operating\"",[150,829,403],{"class":215},[150,831,832],{"class":269},"8200.40",[150,834,414],{"class":215},[150,836,837,839,842,844,846,849],{"class":90,"line":292},[150,838,397],{"class":215},[150,840,841],{"class":159},"\"Overdraft\"",[150,843,403],{"class":215},[150,845,547],{"class":211},[150,847,848],{"class":269},"1530.75",[150,850,414],{"class":215},[150,852,853],{"class":90,"line":297},[150,854,229],{"emptyLinePlaceholder":228},[150,856,857,860,862],{"class":90,"line":320},[150,858,859],{"class":215},"code ",[150,861,238],{"class":211},[150,863,864],{"class":159}," \"$#,##0.00;[Red]($#,##0.00)\"\n",[150,866,867,869,871,873,875,878,880,882],{"class":90,"line":478},[150,868,481],{"class":211},[150,870,484],{"class":215},[150,872,487],{"class":211},[150,874,490],{"class":215},[150,876,877],{"class":159},"\"B\"",[150,879,496],{"class":215},[150,881,499],{"class":269},[150,883,884],{"class":215},":]:\n",[150,886,887,889,891],{"class":90,"line":508},[150,888,511],{"class":215},[150,890,238],{"class":211},[150,892,893],{"class":215}," code\n",[150,895,896],{"class":90,"line":519},[150,897,229],{"emptyLinePlaceholder":228},[150,899,900,902,905],{"class":90,"line":524},[150,901,323],{"class":215},[150,903,904],{"class":159},"\"currency_accounting.xlsx\"",[150,906,329],{"class":215},[150,908,909,911,913,916],{"class":90,"line":534},[150,910,300],{"class":269},[150,912,303],{"class":215},[150,914,915],{"class":159},"\"8200.40 → $8,200.40 ; -1530.75 → red ($1,530.75)\"",[150,917,329],{"class":215},[10,919,920,921,924,925,928,929,932],{},"The positive value shows as ",[14,922,923],{},"$8,200.40","; the negative shows as a red ",[14,926,927],{},"($1,530.75)",". The stored value of the second cell is still ",[14,930,931],{},"-1530.75",", so totals compute correctly.",[136,934,936],{"id":935},"step-5-format-a-pandas-exported-column","Step 5: Format a pandas-exported column",[10,938,939,942,943,945,946,948],{},[14,940,941],{},"df.to_excel()"," writes values but no currency formatting. The clean pattern is: export with pandas, reopen the file with ",[14,944,26],{},", format the money column, and save. This keeps pandas for the data and ",[14,947,26],{}," for presentation.",[141,950,952],{"className":202,"code":951,"language":204,"meta":146,"style":146},"import pandas as pd\nfrom openpyxl import load_workbook\n\ndf = pd.DataFrame({\n    \"Region\": [\"North\", \"South\", \"West\"],\n    \"Revenue\": [23990.5, 12475.0, 1599.2],\n})\ndf.to_excel(\"pandas_report.xlsx\", index=False, sheet_name=\"Sales\")\n\nwb = load_workbook(\"pandas_report.xlsx\")\nws = wb[\"Sales\"]\nfor cell in ws[\"B\"][1:]:               # Revenue is column B; header in row 1\n    cell.number_format = \"$#,##0.00\"\n\nwb.save(\"pandas_report.xlsx\")\nprint(\"Reopened pandas output and formatted the Revenue column\")\n",[14,953,954,967,978,982,992,1013,1032,1037,1068,1072,1085,1099,1120,1128,1132,1140],{"__ignoreMap":146},[150,955,956,958,961,964],{"class":90,"line":152},[150,957,219],{"class":211},[150,959,960],{"class":215}," pandas ",[150,962,963],{"class":211},"as",[150,965,966],{"class":215}," pd\n",[150,968,969,971,973,975],{"class":90,"line":225},[150,970,212],{"class":211},[150,972,216],{"class":215},[150,974,219],{"class":211},[150,976,977],{"class":215}," load_workbook\n",[150,979,980],{"class":90,"line":232},[150,981,229],{"emptyLinePlaceholder":228},[150,983,984,987,989],{"class":90,"line":244},[150,985,986],{"class":215},"df ",[150,988,238],{"class":211},[150,990,991],{"class":215}," pd.DataFrame({\n",[150,993,994,997,1000,1002,1004,1006,1008,1010],{"class":90,"line":255},[150,995,996],{"class":159},"    \"Region\"",[150,998,999],{"class":215},": [",[150,1001,426],{"class":159},[150,1003,403],{"class":215},[150,1005,445],{"class":159},[150,1007,403],{"class":215},[150,1009,464],{"class":159},[150,1011,1012],{"class":215},"],\n",[150,1014,1015,1018,1020,1022,1024,1026,1028,1030],{"class":90,"line":273},[150,1016,1017],{"class":159},"    \"Revenue\"",[150,1019,999],{"class":215},[150,1021,431],{"class":269},[150,1023,403],{"class":215},[150,1025,450],{"class":269},[150,1027,403],{"class":215},[150,1029,469],{"class":269},[150,1031,1012],{"class":215},[150,1033,1034],{"class":90,"line":292},[150,1035,1036],{"class":215},"})\n",[150,1038,1039,1042,1045,1047,1051,1053,1056,1058,1061,1063,1066],{"class":90,"line":297},[150,1040,1041],{"class":215},"df.to_excel(",[150,1043,1044],{"class":159},"\"pandas_report.xlsx\"",[150,1046,403],{"class":215},[150,1048,1050],{"class":1049},"s4XuR","index",[150,1052,238],{"class":211},[150,1054,1055],{"class":269},"False",[150,1057,403],{"class":215},[150,1059,1060],{"class":1049},"sheet_name",[150,1062,238],{"class":211},[150,1064,1065],{"class":159},"\"Sales\"",[150,1067,329],{"class":215},[150,1069,1070],{"class":90,"line":320},[150,1071,229],{"emptyLinePlaceholder":228},[150,1073,1074,1076,1078,1081,1083],{"class":90,"line":478},[150,1075,235],{"class":215},[150,1077,238],{"class":211},[150,1079,1080],{"class":215}," load_workbook(",[150,1082,1044],{"class":159},[150,1084,329],{"class":215},[150,1086,1087,1089,1091,1094,1096],{"class":90,"line":508},[150,1088,247],{"class":215},[150,1090,238],{"class":211},[150,1092,1093],{"class":215}," wb[",[150,1095,1065],{"class":159},[150,1097,1098],{"class":215},"]\n",[150,1100,1101,1103,1105,1107,1109,1111,1113,1115,1117],{"class":90,"line":519},[150,1102,481],{"class":211},[150,1104,484],{"class":215},[150,1106,487],{"class":211},[150,1108,490],{"class":215},[150,1110,877],{"class":159},[150,1112,496],{"class":215},[150,1114,499],{"class":269},[150,1116,502],{"class":215},[150,1118,1119],{"class":288},"# Revenue is column B; header in row 1\n",[150,1121,1122,1124,1126],{"class":90,"line":524},[150,1123,511],{"class":215},[150,1125,238],{"class":211},[150,1127,516],{"class":159},[150,1129,1130],{"class":90,"line":534},[150,1131,229],{"emptyLinePlaceholder":228},[150,1133,1134,1136,1138],{"class":90,"line":729},[150,1135,323],{"class":215},[150,1137,1044],{"class":159},[150,1139,329],{"class":215},[150,1141,1143,1145,1147,1150],{"class":90,"line":1142},16,[150,1144,300],{"class":269},[150,1146,303],{"class":215},[150,1148,1149],{"class":159},"\"Reopened pandas output and formatted the Revenue column\"",[150,1151,329],{"class":215},[10,1153,1154,1155,1158,1159,1163],{},"Exporting without the index (here ",[14,1156,1157],{},"index=False",") keeps the money column at B; see ",[19,1160,1162],{"href":1161},"\u002Fgetting-started-with-python-excel-automation\u002Fwriting-dataframes-to-excel-with-pandas\u002Fwrite-pandas-dataframe-to-excel-without-index\u002F","Write a Pandas DataFrame to Excel Without the Index"," for why the index column shifts everything right if you leave it in.",[136,1165,1167],{"id":1166},"common-pitfalls","Common pitfalls",[1169,1170,1171,1187],"table",{},[1172,1173,1174],"thead",{},[1175,1176,1177,1181,1184],"tr",{},[1178,1179,1180],"th",{},"Symptom",[1178,1182,1183],{},"Cause",[1178,1185,1186],{},"Fix",[1188,1189,1190,1218,1231,1245,1265],"tbody",{},[1175,1191,1192,1196,1203],{},[1193,1194,1195],"td",{},"Format appears to do nothing",[1193,1197,1198,1199,1202],{},"The cell holds text, e.g. ",[14,1200,1201],{},"\"1234.5\"",", not a number",[1193,1204,1205,1206,1209,1210,1213,1214,1217],{},"Write a real ",[14,1207,1208],{},"float","\u002F",[14,1211,1212],{},"int",", or convert with ",[14,1215,1216],{},"float(value)"," before assigning",[1175,1219,1220,1223,1226],{},[1193,1221,1222],{},"Value changed when I formatted it",[1193,1224,1225],{},"It did not — you are reading the rendered display",[1193,1227,1228,1230],{},[14,1229,338],{}," still returns the raw number; the format is display-only",[1175,1232,1233,1236,1239],{},[1193,1234,1235],{},"Negatives show a minus, not parentheses",[1193,1237,1238],{},"Single-section format code",[1193,1240,1241,1242],{},"Add a negative section: ",[14,1243,1244],{},"$#,##0.00;($#,##0.00)",[1175,1246,1247,1250,1256],{},[1193,1248,1249],{},"Symbol missing after a pandas export",[1193,1251,1252,1255],{},[14,1253,1254],{},"to_excel"," writes no formatting",[1193,1257,1258,1259,1261,1262],{},"Reopen with ",[14,1260,26],{}," and set ",[14,1263,1264],{},"number_format",[1175,1266,1267,1270,1279],{},[1193,1268,1269],{},"Thousands separator absent",[1193,1271,1272,1273,1276,1277],{},"Used ",[14,1274,1275],{},"$0.00"," instead of ",[14,1278,88],{},[1193,1280,1281,1282,1284],{},"Include the ",[14,1283,194],{}," grouping in the code",[136,1286,1288],{"id":1287},"a-note-on-the-underlying-value","A note on the underlying value",[10,1290,1291,1292,1294,1295,1298,1299,1302,1303,1306],{},"Currency formatting never rounds or alters the stored number. A cell showing ",[14,1293,113],{}," may hold ",[14,1296,1297],{},"1234.4999","; the display rounds, the value does not. If you need the value itself rounded, do it in Python with ",[14,1300,1301],{},"round(value, 2)"," before writing — formatting alone will not change what ",[14,1304,1305],{},"=SUM()"," or a later read returns.",[136,1308,1310],{"id":1309},"frequently-asked-questions","Frequently asked questions",[1312,1313,1315],"h3",{"id":1314},"why-does-my-currency-format-have-no-effect","Why does my currency format have no effect?",[10,1317,1318,1319,1321,1322,1324],{},"The cell contains a string, not a number. Currency codes only format numeric values. Convert the value to ",[14,1320,1208],{}," or ",[14,1323,1212],{}," before assigning it to the cell.",[1312,1326,1328],{"id":1327},"does-formatting-as-currency-change-the-stored-amount","Does formatting as currency change the stored amount?",[10,1330,1331,1332,1335,1336,1338],{},"No. The number is untouched. Excel rounds the ",[751,1333,1334],{},"display"," to two decimals, but ",[14,1337,338],{}," and all formulas use the full-precision number.",[1312,1340,1342],{"id":1341},"how-do-i-format-an-entire-column-at-once","How do I format an entire column at once?",[10,1344,1345,1346,1261,1349,1351],{},"Loop ",[14,1347,1348],{},"for cell in ws[\"B\"][1:]:",[14,1350,186],{}," on each cell, skipping the header. There is no single \"format this column\" call; you assign the code per cell.",[1312,1353,1355],{"id":1354},"can-i-show-negative-amounts-in-red-parentheses","Can I show negative amounts in red parentheses?",[10,1357,1358,1359,1362],{},"Yes. Use a two-section code like ",[14,1360,1361],{},"$#,##0.00;[Red]($#,##0.00)",". The part after the semicolon styles negatives.",[1312,1364,1366],{"id":1365},"how-do-i-format-money-in-a-pandas-export","How do I format money in a pandas export?",[10,1368,1369,1370,1372,1373,1376,1377,1379],{},"Write the DataFrame with ",[14,1371,1254],{},", then reopen the file with ",[14,1374,1375],{},"openpyxl.load_workbook",", loop the money column, set ",[14,1378,1264],{},", and save again.",[136,1381,1383],{"id":1382},"conclusion","Conclusion",[10,1385,1386,1387,1389,1390,1393,1394,1321,1397,1400],{},"Currency formatting in ",[14,1388,26],{}," is one assignment: ",[14,1391,1392],{},"cell.number_format = \"$#,##0.00\"",". Loop a column to format a report, swap the literal symbol for ",[14,1395,1396],{},"€",[14,1398,1399],{},"£",", and add a negative section for accounting parentheses. The value never changes — so reopen pandas output and format freely, knowing your totals and exports still see the real numbers.",[136,1402,1404],{"id":1403},"where-to-go-next","Where to go next",[1406,1407,1408,1414,1421],"ul",{},[1409,1410,1411,1413],"li",{},[19,1412,22],{"href":21}," — the parent cluster: separators, percentages, and format-code reference.",[1409,1415,1416,1420],{},[19,1417,1419],{"href":1418},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-dates-in-excel-cells-with-python\u002F","Format Dates in Excel Cells with Python"," — the date-formatting companion to this guide.",[1409,1422,1423,1425],{},[19,1424,1162],{"href":1161}," — keep your money column where you expect it after export.",[1427,1428,1429],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}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 .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":146,"searchDepth":225,"depth":225,"links":1431},[1432,1433,1434,1435,1436,1437,1438,1439,1440,1447,1448],{"id":138,"depth":225,"text":139},{"id":176,"depth":225,"text":177},{"id":345,"depth":225,"text":346},{"id":567,"depth":225,"text":568},{"id":763,"depth":225,"text":764},{"id":935,"depth":225,"text":936},{"id":1166,"depth":225,"text":1167},{"id":1287,"depth":225,"text":1288},{"id":1309,"depth":225,"text":1310,"children":1441},[1442,1443,1444,1445,1446],{"id":1314,"depth":232,"text":1315},{"id":1327,"depth":232,"text":1328},{"id":1341,"depth":232,"text":1342},{"id":1354,"depth":232,"text":1355},{"id":1365,"depth":232,"text":1366},{"id":1382,"depth":225,"text":1383},{"id":1403,"depth":225,"text":1404},"2026-06-18","Format Excel cells as currency with openpyxl: set $#,##0.00, apply it across a column, use €\u002F£ symbols, accounting parentheses for negatives, and post-process pandas output.","md",[1453,1455,1457,1459,1461],{"q":1315,"a":1454},"The cell contains a string, not a number. Currency codes only format numeric values. Convert the value to float or int before assigning it to the cell.",{"q":1328,"a":1456},"No. The number is untouched. Excel rounds the *display* to two decimals, but cell.value and all formulas use the full-precision number.",{"q":1342,"a":1458},"Loop for cell in ws[\"B\"][1:]: and set cell.number_format on each cell, skipping the header. There is no single \"format this column\" call; you assign the code per cell.",{"q":1355,"a":1460},"Yes. Use a two-section code like $#,##0.00;Red. The part after the semicolon styles negatives.",{"q":1366,"a":1462},"Write the DataFrame with to_excel, then reopen the file with openpyxl.load_workbook, loop the money column, set number_format, and save again.",{},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-excel-cells-as-currency-with-python",{"title":5,"description":1466},"Step-by-step openpyxl currency formatting: dollar\u002Feuro\u002Fpound symbols, whole-column ranges, accounting negatives in parentheses, and styling a pandas-exported column.","format-excel-cells-as-currency-with-python","formatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-excel-cells-as-currency-with-python\u002Findex","long_tail","8RTGYTWvl5iMaVipCyaSpZ2_ZNcd7wIRhiYCj5papNI",[1472,1475],{"title":1419,"path":1473,"stem":1474,"children":-1},"\u002Fformatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-dates-in-excel-cells-with-python","formatting-and-charting-excel-reports-with-python\u002Fapplying-number-and-date-formats-in-excel\u002Fformat-dates-in-excel-cells-with-python\u002Findex",{"title":1476,"path":1477,"stem":1478,"children":-1},"Creating Charts in Excel with openpyxl","\u002Fformatting-and-charting-excel-reports-with-python\u002Fcreating-charts-in-excel-with-openpyxl","formatting-and-charting-excel-reports-with-python\u002Fcreating-charts-in-excel-with-openpyxl\u002Findex",1781795518821]