{"id":53,"date":"2026-02-13T11:26:19","date_gmt":"2026-02-13T03:26:19","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=53"},"modified":"2026-01-16T07:46:53","modified_gmt":"2026-01-16T07:46:53","slug":"how-to-create-data-bars-for-specified-data-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-create-data-bars-for-specified-data-using-openpyxl.html","title":{"rendered":"How To Create Conditional Formatting Data Bars For Specified Data Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>from openpyxl.formatting.rule import DataBarRule<\/p>\n<p>from openpyxl.styles import colors<\/p>\n<p>\u00a0<\/p>\n<p>workbook= load_workbook(filename=&#8217;wb2.xlsx&#8217;)<\/p>\n<p>sheet= workbook.active<\/p>\n<p>rule= <b>DataBarRule<\/b>(start_type=&#8217;percentile&#8217;, \\<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 start_value=10, \\<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 end_type=&#8217;percentile&#8217;, \\<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 end_value=90, \\<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 color=&#8217;0000FF&#8217;)<\/p>\n<p>sheet.<b>conditional_formatting.add<\/b>(&#8216;B2:B11&#8217;, rule)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Data Bars\n\nfrom openpyxl import load_workbook\nfrom openpyxl.formatting.rule import DataBarRule\nfrom openpyxl.styles import colors\n\n#Load Data\nworkbook= load_workbook(filename='wb2.xlsx')\nsheet= workbook.active\n\n#Draw Data Bars\n#Plot with Percentage Data\nrule= DataBarRule(start_type='percentile', \\\n                    start_value=10, \\\n                    end_type='percentile', \\\n                    end_value=90, \\\n                    color='0000FF')\nsheet.conditional_formatting.add('B2:B11', rule)\nworkbook.save('test.xlsx')\n\nworkbook= load_workbook(filename='wb2.xlsx')\nsheet= workbook.active\n\n#Plot with Actual Data\nrule= DataBarRule(start_type='num', \\\n                    start_value=150000, \\\n                    end_type='num', \\\n                    end_value=1300000, \\\n                    color='FF0000')\nsheet.conditional_formatting.add('A2:A11', rule)\nworkbook.save('test2.xlsx') <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"525\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/35.png\" alt=\"Create Conditional Formatting Data Bars For Specified Data Using OpenPyXL\" class=\"wp-image-329\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/35.png 693w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/35-300x227.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"525\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/36.png\" alt=\"\" class=\"wp-image-330\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/36.png 693w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/02\/36-300x227.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>OpenPyXL<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-openpyxl-conditional-formatting"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":332,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/53\/revisions\/332"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}