2013-07-27 55 views
-1

我使用蟒2.7 我試圖這樣重寫excel文件的細胞而不影響其他片

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和剩餘的單元格被刪除。有沒有辦法保持所有的細胞不受影響?

回答

1

由於您在調用add_sheet,因此會一直創建一個NEW BLANK表單,嘗試將其註釋掉。

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)