-1

i'm using python 2.7 I tried like this

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)

If i run this, cell(10,10) of sheet1 is changed to Overwrite cell and remaining cells get deleted. Is there any way to keep all the cells unaffected?

user19911303
  • 449
  • 2
  • 9
  • 34

2 Answers2

1

Since you are calling add_sheet this will create a NEW BLANK sheet all the time, try commenting it out.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73
0

Wouldn't this work?

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)
Lynn
  • 10,425
  • 43
  • 75