editing existing excel workbook using xlrd, xlwt and xlutils

[亡魂溺海] 提交于 2019-12-11 12:08:46

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/14569456/editing-existing-excel-workbook-using-xlrd-xlwt-and-xlutils

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!