2

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?
sazr
  • 24,984
  • 66
  • 194
  • 362

2 Answers2

4

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

John Machin
  • 81,303
  • 11
  • 141
  • 189
2

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

YusuMishi
  • 2,317
  • 1
  • 18
  • 8