How To Insert Cells or Ranges Using xlwings?

Method

RangeObject.Insert(Shift, CopyOrigin)

 

Shift:

xlShiftDown

xlShiftToRight

CopyOrigin:

xlFormatFromLeftOrAbove

xlFormatFromRightOrBelow

 

#xlwings

sht.range(‘C3‘).insert(shift=’down’,copy_origin=’format_from_left_or_above’)

sht.range(‘B3:C5′).insert()

 

#xlwings API

#sht.api.Range(‘C3‘).Insert(Shift=xw.constants.InsertShiftDirection.xlShiftDown, CopyOrigin=xw.constants.InsertFormatOrigin.xlFormatFromLeftOrAbove)

#sht.api.Range(‘B3:C5′).Insert()

Sample Code

#Inserting Cells or Ranges

import xlwings as xw    #Import the xlwings package

app=xw.App()
bk=app.books.open('insert.xlsx')
sht=bk.sheets.active    #Get the active worksheet

#xlwings
sht.range('C3').insert(shift='down',copy_origin='format_from_left_or_above')
#sht.range('B3:C5').insert()

#xlwings API
#sht.api.Range('A2').Insert(Shift=xw.constants.InsertShiftDirection.xlShiftDown, CopyOrigin=xw.constants.InsertFormatOrigin.xlFormatFromLeftOrAbove)
#sht.api.Range('B4:C5').Insert()

#bk.close()
#app.kill()
How To Insert Cells or Ranges Using xlwings?
February 4, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *