{"id":8,"date":"2026-01-21T18:51:20","date_gmt":"2026-01-21T10:51:20","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=8"},"modified":"2026-01-17T04:19:23","modified_gmt":"2026-01-17T04:19:23","slug":"how-to-create-and-reference-worksheets-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-and-reference-worksheets-using-xlwings\/","title":{"rendered":"How To Create and Reference Worksheets Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span lang=\"x-none\">\u3010<\/span><span lang=\"en-US\">xlwings\u3011<\/span><\/p>\n<p lang=\"x-none\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">bk.sheets.add(name=None, before=None, after=None)<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">\u3010xlwings API\u3011<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">bk.WorkSheets.Add(Before, After, Count, Type)<\/p>\n<p style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">bk.sheets.add()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Insert before the 2nd worksheet<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.sheets.add(before=bk.sheets(2))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Insert after the 2nd worksheet<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.sheets.add(after=bk.sheets(2))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Reference a worksheet<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.sheets[0]<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.sheets(1)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht=bk.sheets[&#8216;Sheet1&#8217;]<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht.name=&#8217;MySheet&#8217;<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#xlwings API<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Worksheets.Add()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Insert before the 2nd worksheet<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Worksheets.Add (Before=bk.api.Worksheets(2))<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Insert 3 worksheets at once, place them at the front<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Worksheets.Add(Count=3)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Create a new chart worksheet<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#bk.api.Worksheets.Add(Type=xw.constants.SheetType.xlChart)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 8.0pt;\">\u00a0<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Use the Sheets object<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht=bk.api.Sheets.Add()<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#Reference the worksheet<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht=Worksheets(1)<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">#sht=Worksheets(&#8216;Sheet1&#8217;)<\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Creating and Referencing Worksheets\n\nimport xlwings as xw    #Import the xlwings package\n\napp=xw.App()\nbk=app.books.active    #Get the active workbook\nsht=bk.sheets.active    #Get the active worksheet\n\n#xlwings\nbk.sheets.add()\n#Insert before the 2nd worksheet\n#bk.sheets.add(before=bk.sheets(2))\n#Insert after the 2nd worksheet\n#bk.sheets.add(after=bk.sheets(2))\n#Reference a worksheet \n#bk.sheets&#91;0]\n#bk.sheets(1)\n#sht=bk.sheets&#91;'Sheet1']\n#sht.name='MySheet'\n\n#xlwings API\n#bk.api.Worksheets.Add()\n#Insert before the 2nd worksheet\n#bk.api.Worksheets.Add (Before=bk.api.Worksheets(2))\n#Insert 3 worksheets at once, place them at the front\n#bk.api.Worksheets.Add(Count=3)\n#Create a new chart worksheet\n#bk.api.Worksheets.Add(Type=xw.constants.SheetType.xlChart)\n\n#Use the Sheets object\n#sht=bk.api.Sheets.Add()\n#Reference the worksheet\n#sht=Worksheets(1) \n#sht=Worksheets('Sheet1') \n\nbk.close()\napp.kill()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-xlwings-worksheet"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/8\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}