How To Reference a Set of Cell Ranges Using xlwings?

Method

#xlwings API

#Union of two cell ranges

app.api.Union(sht.api.Range(‘B4:D8’), sht.api.Range(‘C2:F5’)).Select()

#Intersect of two cell ranges

#app.api.Intersect(sht.api.Range(‘B4:D8’), sht.api.Range(‘C2:F5’)).Select()

Sample Code

#Set Operations of 2 Cell Ranges

import xlwings as xw    #Import the xlwings package

app=xw.App()
bk=app.books.active    #Get the active workbook
sht=bk.sheets.active    #Get the active worksheet

#xlwings API
#Union of two cell ranges
#app.api.Union(sht.api.Range('B4:D8'), sht.api.Range('C2:F5')).Select()
#Intersect of two cell ranges
app.api.Intersect(sht.api.Range('B4:D8'), sht.api.Range('C2:F5')).Select()

#bk.close()
#app.kill()
Reference a Set of Cell Ranges Using xlwings
February 1, 2026 (0)


Leave a Reply

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