editing existing excel workbook using xlrd, xlwt a

2019-07-28 08:07发布

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.

2条回答
The star\"
2楼-- · 2019-07-28 08:54

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.

查看更多
趁早两清
3楼-- · 2019-07-28 08:58

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.

查看更多
登录 后发表回答