假设我有一个名为test.xlsx的excel文件,它是一个有三张工作表的工作簿,其中sheet1被称为hello1,sheet2 2被称为hello2,sheet3被称为bye。
现在,我想读取该文件,然后重新写入相同的文件,但只更改名为hello2的工作表的(B列,第11行)和名为bye的工作表的(d列,第14行)中的值。我要给出的值分别是“test”(字符串)和135(即,在sheet hello2中编写test,在sheet bye中编写14)。
你可能想知道我为什么要问这么奇怪的问题,但基本上我希望获得以下一些技能/知识:
注意:作为参考,我可以在redhat服务器中使用任何版本的python,excel文件是用我的mac生成的,用excelformac2011保存为xlsx格式。版本14.0.1,然后我将excel文件复制到redhat服务器。
我建议使用
xlwt
、xlrd
和xlutils
模块(您可以在这里找到:python-excel.org)。使用
xlrd
、xlwt
和xlutils
,可以使用xlrd
读取工作簿,然后使用xlutils
生成可写副本。因为您所做的工作不依赖于单元格中已有的值,所以除了打开书本之外,您根本不需要使用xlrd
。代码的快速模型如下所示:
相关问题 更多 >
编程相关推荐