{"id":180,"date":"2026-01-19T11:25:55","date_gmt":"2026-01-19T03:25:55","guid":{"rendered":"https:\/\/openpyxl.com\/blog\/?p=180"},"modified":"2026-01-16T05:28:25","modified_gmt":"2026-01-16T05:28:25","slug":"how-to-create-save-and-close-a-workbook-using-openpyxl","status":"publish","type":"post","link":"https:\/\/openpyxl.com\/blog\/how-to-create-save-and-close-a-workbook-using-openpyxl.html","title":{"rendered":"How To Create, Save and Close a Workbook Using OpenPyXL?"},"content":{"rendered":"<h2>Method<\/h2>\n<h3>Creating a Workbook Object:<\/h3>\n<p>import openpyxl as pyxl<br \/>wb = pyxl.Workbook()<br \/># Or<br \/>from openpyxl import Workbook<br \/>wb = Workbook()<\/p>\n<h3>Saving a Workbook:<\/h3>\n<p>wb.save(&#8216;test.xlsx&#8217;)<\/p>\n<h3>Saving As:<\/h3>\n<p>wb.save(&#8216;test2.xlsx&#8217;)<\/p>\n<h3>Saving as a Template:<\/h3>\n<p>wb.template = True<br \/>wb.save(&#8216;temp.xltx&#8217;)<\/p>\n<h3>Closing a Workbook:<\/h3>\n<p>wb.close()<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Creating, Saving, and Closing a Workbook\n\n#Import the openpyxl package with alias pyxl\nimport openpyxl as pyxl\n\n#Create a new workbook\nwb=pyxl.Workbook()\n\n#Or import the Workbook function\n#from openpyxl import Workbook\n#Create a new workbook\n#wb=Workbook()\n\n#Save the workbook\nwb.save('test.xlsx')\n\n#Save as a template\nwb.template = True\nwb.save('temp.xltx')\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=\"626\" height=\"285\" src=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/1-1.png\" alt=\"\" class=\"wp-image-191\" srcset=\"https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/1-1.png 626w, https:\/\/openpyxl.com\/blog\/wp-content\/uploads\/2026\/01\/1-1-300x137.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p># Method:<\/p>\n<p>## Creating a Workbook Object:<br \/>\nimport openpyxl as pyxl<br \/>\nwb = pyxl.Workbook()<br \/>\n# Or<br \/>\nfrom ope&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","category-openpyxl-workbook"],"_links":{"self":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/180","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=180"}],"version-history":[{"count":2,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/posts\/180\/revisions\/192"}],"wp:attachment":[{"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openpyxl.com\/blog\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}