1

How to edit and save the data in an existing excel workbook using xlrd, xlwt and xlutils module? could someone please provide a sample code to edit and save the data in excel workbook?

I am trying to put data from one workbook to another.

import xlrd, xlwt, xlutils

wb1 = xlrd.open_workbook('workbook1.xls', formatting_info=True)
wb2 = xlrd.open_workbook('workbook2.xls', formatting_info=True)

value 1 == wb2.sheet_by_name('Sheet1).cell(2,1).value

wb1.sheet_by_name('Sheet1').cell(2,2).value == value1

How to save this data in workbook1.xls?

Sorry, I asked this before, but I am trying to be more clear about my question this time.

Thank you very much.

Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175
user2001139
  • 49
  • 1
  • 2
  • 7

2 Answers2

1

You can save with wb1.save('workbook1.xls'). You might get an IOError that the file already exists. In that case try to os.remove() the file before saving.

Anthon
  • 69,918
  • 32
  • 186
  • 246
0

I agree with the previous answer of using the xlwt library save method. But you should also do some proof reading of your code. You are missing a closing quote for Sheet1 and variable names cannot have spaces.

Kat
  • 475
  • 1
  • 6
  • 21