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