{"id":40,"date":"2026-02-04T11:07:15","date_gmt":"2026-02-04T03:07:15","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=40"},"modified":"2026-01-17T05:15:18","modified_gmt":"2026-01-17T05:15:18","slug":"how-to-insert-cells-or-ranges-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-insert-cells-or-ranges-using-xlwings\/","title":{"rendered":"How To Insert Cells or Ranges Using xlwings?"},"content":{"rendered":"<h2>Method<\/h2>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span lang=\"en-US\">R<\/span><span lang=\"zh-CN\">ange<\/span><span lang=\"en-US\">O<\/span><span lang=\"zh-CN\">bject<\/span><span lang=\"en-US\">.<\/span><span lang=\"en-US\" style=\"font-weight: bold;\">Insert<\/span><span lang=\"en-US\">(Shift, CopyOrigin)<\/span><\/p>\n<p lang=\"en-US\">\u00a0<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">Shift<\/span>:<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">xlShiftDown<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">xlShiftToRight<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span style=\"font-weight: bold;\">CopyOrigin<\/span>:<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">xlFormatFromLeftOrAbove<\/p>\n<p lang=\"en-US\" style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\">xlFormatFromRightOrBelow<\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 10.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;\"><span lang=\"zh-CN\">sht.range(&#8216;<\/span><span lang=\"en-US\">C3<\/span><span lang=\"zh-CN\">&#8216;).insert(shift=&#8217;down&#8217;,copy_origin=&#8217;format_from_left_or_above&#8217;)<\/span><\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span lang=\"zh-CN\">sht.range(&#8216;B<\/span><span lang=\"en-US\">3<\/span><span lang=\"zh-CN\">:C5&#8242;).insert()<\/span><\/p>\n<p lang=\"en-US\" 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;\"><span lang=\"zh-CN\">#sht.api.Range(&#8216;<\/span><span lang=\"en-US\">C3<\/span><span lang=\"zh-CN\">&#8216;).Insert(Shift=xw.constants.InsertShiftDirection.xlShiftDown, CopyOrigin=xw.constants.InsertFormatOrigin.xlFormatFromLeftOrAbove)<\/span><\/p>\n<p style=\"margin: 0in; font-family: \u5fae\u8f6f\u96c5\u9ed1; font-size: 14.0pt;\"><span lang=\"zh-CN\">#sht.api.Range(&#8216;B<\/span><span lang=\"en-US\">3<\/span><span lang=\"zh-CN\">:C5&#8242;).Insert()<\/span><\/p>\n<h2>Sample Code<\/h2>\n\n\n<pre class=\"wp-block-code\"><code>#Inserting Cells or Ranges\n\nimport xlwings as xw    #Import the xlwings package\n\napp=xw.App()\nbk=app.books.open('insert.xlsx')\nsht=bk.sheets.active    #Get the active worksheet\n\n#xlwings\nsht.range('C3').insert(shift='down',copy_origin='format_from_left_or_above')\n#sht.range('B3:C5').insert()\n\n#xlwings API\n#sht.api.Range('A2').Insert(Shift=xw.constants.InsertShiftDirection.xlShiftDown, CopyOrigin=xw.constants.InsertFormatOrigin.xlFormatFromLeftOrAbove)\n#sht.api.Range('B4:C5').Insert()\n\n#bk.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/27.png\" alt=\"How To Insert Cells or Ranges Using xlwings?\" class=\"wp-image-303\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/27.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/27-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/27-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/28.png\" alt=\"\" class=\"wp-image-304\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/28.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/28-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/28-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"482\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/29.png\" alt=\"\" class=\"wp-image-305\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/29.png 883w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/29-300x164.png 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/02\/29-768x419.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/figure>\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":[9],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-xlwings-cell-range"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/40","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=40"}],"version-history":[{"count":3,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":306,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions\/306"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}