使用xlrd,xlwt和xlutils编辑现有的Excel工作簿 [英] editing existing excel workbook using xlrd, xlwt and xlutils

查看:224
本文介绍了使用xlrd,xlwt和xlutils编辑现有的Excel工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用xlrd,xlwt和xlutils模块在现有的Excel工作簿中编辑和保存数据? 有人可以提供示例代码来编辑数据并将其保存在excel工作簿中吗?

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

如何将这些数据保存在workbook1.xls中?

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.

非常感谢您.

推荐答案

您可以使用wb1.save('workbook1.xls')保存.您可能会得到一个IOError文件已经存在.在这种情况下,请尝试先os.remove()保存文件.

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.

这篇关于使用xlrd,xlwt和xlutils编辑现有的Excel工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆