-1

我正在使用 python 2.7 我试过这样

from xlrd import *
from xlwt import *
file1 = r"abc.xls"
wbfile1 = open_workbook(file1)
file2 = r"xyz.xls"
wbfile2 = Workbook()
SheetName_file2 = wbfile2.add_sheet('sheet1',cell_overwrite_ok=True)
SheetName_file2.write(10,10,"Overwrite cell")
wbfile2.save(file2)

如果我运行它,则 sheet1 的单元格(10,10)将更改为Overwrite cell并删除剩余的单元格。有什么办法可以让所有细胞不受影响?

4

2 回答 2

1

由于您正在调用 add_sheet 这将始终创建一个新的空白表,请尝试将其注释掉。

于 2013-07-27T15:12:01.490 回答
0

这不行吗?

from xlrd import *
from xlwt import *
file1 = r"abc.xls"
file2 = r"xyz.xls"

wbfile1 = open_workbook(file1)
wbfile1.get_sheet(0).write(10,10,"Overwrite cell")
wbfile1.save(file2)
于 2013-07-27T15:13:47.013 回答