{"id":6,"date":"2026-01-20T18:03:37","date_gmt":"2026-01-20T10:03:37","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=6"},"modified":"2026-01-16T05:39:33","modified_gmt":"2026-01-16T05:39:33","slug":"how-to-create-and-delete-worksheets-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-create-and-delete-worksheets-using-openpyxl.html","title":{"rendered":"How To Create and Delete Worksheets Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<p>To create a new worksheet, use the `create_sheet` method of the workbook object. Its syntax is:<\/p>\n<p><b>ws=wb.create_sheet(title=None, index=None)<\/b><\/p>\n<p>Where `title` is a string representing the name of the new worksheet, and `index` is an integer representing the position at which to insert the worksheet. Both parameters are optional. The method returns a worksheet object, which automatically becomes the active worksheet.<\/p>\n<p><strong>Common attributes:<\/strong><\/p>\n<ul>\n<li>active_cell<\/li>\n<li>selected_cell<\/li>\n<li>rows<\/li>\n<li>columns<\/li>\n<li>dimensions<\/li>\n<li>max_column\u00a0\u00a0\u00a0 #the highest column with data, 1-based index<\/li>\n<li>max_row<\/li>\n<li>min_column<\/li>\n<li>min_row<\/li>\n<li>merged_cell_ranges<\/li>\n<li>show_gridlines<\/li>\n<li>title<\/li>\n<li>Values<\/li>\n<\/ul>\n<p>To delete a specific worksheet, use the `remove` method of the workbook object. For example, to delete the `ws1` worksheet:<\/p>\n<p>wb.remove(ws1)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Create and Delete Worksheets\n\n#Import load_workbook function\nfrom openpyxl import load_workbook\n\n#Load the workbook\nwb=load_workbook(filename='wb2.xlsx')\n#Get the active worksheet\nws=wb.active\n#Output the title of the active worksheet\nprint(ws.title)\n\n#Create a new worksheet with the default name\nws1=wb.create_sheet()\n#Create a new worksheet named `Mysheet2`\nws2=wb.create_sheet('Mysheet2')\n#Create a new worksheet named `Mysheet3`,\n#placing it at the front\nws3=wb.create_sheet('Mysheet3', 0)\n#Create a new worksheet named `Mysheet4`,\n#placing it second to last\nws4=wb.create_sheet('Mysheet4', -1)\n\n#Delete worksheet `ws4`\nwb.remove(ws4)\n#Delete worksheet `ws3`\ndel wb&#91;ws3.title]\n\n#Save the workbook\nwb.save('test.xlsx')\n\n#Close the workbook\nwb.close()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"418\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/2.png\" alt=\"\" class=\"wp-image-202\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/2.png 693w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/2-300x181.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":[1],"tags":[],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-openpyxl-worksheet"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/6","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=6"}],"version-history":[{"count":3,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":203,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions\/203"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}