How To Copy/Paste/Cut and Delete Cells Using xlwings?

Method

RangeObject.PasteSpecial(Paste, Operation, SkipBlanks, Transpose)

xlPasteColumnWidths    Copy column widths

Name

Value

Description

xlPasteSpecialOperationAdd

2

Data will be added to the target cell’s value

xlPasteSpecialOperationDivide

5

Data will divide the value in the target cell

xlPasteSpecialOperationMultiply

4

Data will multiply with the value in the target cell

xlPasteSpecialOperationNone

-4142

No operation performed during paste

xlPasteSpecialOperationSubtract

3

Data will subtract from the target cell’s value

Copy

#xlwings API

sht.api.Range(‘C2’).Copy(sht.api.Range(‘G2’))

#sht.api.Range(‘B2’).CurrentRegion.Copy(sht.api.Range(‘G2’))

 

Special Paste options

#sht.api.Range(‘B2:D5’).Copy()

#sht.api.Range(‘G2:I5’).PasteSpecial(Paste=xw.constants.PasteType.xlPasteValues)

 

Comments

#sht.api.Range(‘B2:D5’).Copy()

#sht.api.Range(‘G2:I5’).PasteSpecial(Paste=xw.constants.PasteType.xlPasteComments)

 

Formatting

#sht.api.Range(‘B2:D5’).Copy()

#sht.api.Range(‘A6:E6’).PasteSpecial(Paste=xw.constants.PasteType.xlPasteFormats)

 

Cutting cells

#xlwings API

#sht.api.Range(‘B2:D5’).Cut(Destination=sht.api.Range(‘G2’))

#sht.api.Range(‘B2:D5’).Cut(sht.api.Range(‘G2’))

 

Deleting cells

#xlwings

#sht[‘C2′].delete(shift=’up’)

#sht[‘B2:D5’].delete()

 

#xlwings API

#sht.api.Range(‘C2’).Delete(Shift=xw.constants.DeleteShiftDirection.xlShiftToUp)

#sht.api.Range(‘B2:D5’).Delete()

Sample Code

#Copying/Pasting/Cutting and Deleting Cells

import xlwings as xw    #Import the xlwings package

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

#xlwings API
sht.api.Range('C2').Copy(sht.api.Range('G2'))
#sht.api.Range('B2').CurrentRegion.Copy(sht.api.Range('G2'))

#Special Paste options
#sht.api.Range('B2:D5').Copy()
#sht.api.Range('G2:I5').PasteSpecial(Paste=xw.constants.PasteType.xlPasteValues)

#Comments 
#sht.api.Range('B2:D5').Copy()
#sht.api.Range('G2:I5').PasteSpecial(Paste=xw.constants.PasteType.xlPasteComments)

#Formatting
#sht.api.Range('B2:D5').Copy()
#sht.api.Range('A6:E6').PasteSpecial(Paste=xw.constants.PasteType.xlPasteFormats)

#Cutting cells
#xlwings API
#sht.api.Range('B2:D5').Cut(Destination=sht.api.Range('G2'))
#sht.api.Range('B2:D5').Cut(sht.api.Range('G2'))

#Deleting cells
#xlwings
#sht['C2'].delete(shift='up')
#sht['B2:D5'].delete()

#xlwings API
#sht.api.Range('C2').Delete(Shift=xw.constants.DeleteShiftDirection.xlShiftToUp)
#sht.api.Range('B2:D5').Delete()

#bk.close()
#app.kill()
Copy/Paste/Cut and Delete Cells Using xlwings
February 5, 2026 (0)


Leave a Reply

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