How To Exchange Excel Worksheet and Python Dictionary Data Using xlwings?

Method

Reading

#xlwings

sht.range(‘A1:B2’).options(dict).value

#sht.range(‘A4:B5’).options(dict, transpose=True).value

 

Writing

#xlwings

#dic={ ‘a’: 1.0, ‘b’: 2.0}

#sht.range(‘A1:B2’).options(dict).value=dic

#sht.range(‘A4:B5’).options(dict, transpose=True).value=dic

Sample Code

#Data Read/Write Between Excel Sheets and Python Dictionaries

import xlwings as xw    #Import the xlwings package

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

#Reading
#xlwings
#print(sht.range('A1:B2').options(dict).value)
#print(sht.range('A4:B5').options(dict, transpose=True).value)

#Writing
#xlwings
dic={ 'a': 1.0, 'b': 2.0}
sht.range('A1:B2').options(dict).value=dic
sht.range('A4:B5').options(dict, transpose=True).value=dic

#bk.close()
#app.kill()
Exchange Excel Worksheet and Python Dictionary Data Using xlwings
February 9, 2026 (0)


Leave a Reply

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