简体   繁体   中英

How to add new column and row to .xls file using xlrd

How do you add a new column and/or row to a sheet in xlrd?

I have a .xls file that I read using open_workbook() and I need to add a new column("bouncebacks") to the first sheet then new rows to that sheet but I cannot find any functions in the xlrd documentation that shows how to add new rows and/or columns?

If I cant add a row/column in xlrd is there another way/library that allows me to add a row or column to an .xls file?

Can you show me how I can add a row and column to a sheet?

import xlrd

book = xlrd.open_workbook("abc.xls")
sheet = book.sheet_by_index(0)

# how do I add a new column("bouncebacks") to the sheet?
# how do I add a new row to the sheet?

xlrd reads xls files. xlwt creates new xls files. You need xlutils . Read this . Work through the tutorial that you'll find mentioned there.

xlrd is for reading from an .xls file. for writting to it use xlwt .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM