10

I am trying to write a string in a cell within an excel file. My code is

import xlwt
import xlrd
workbook = xlrd.open_workbook('my_workbook.xls')
worksheet = workbook.sheet_by_index(0)
worksheet.write(0,2,"string")

While I was looking for a solution I leardned that it could be becouse my xlwt library has an old version. However when I checkied it I got xlwt: 0.7.5. And I was once again left clueless. Any help is appreciated.

1
  • This question might help. Commented Jan 20, 2014 at 23:22

1 Answer 1

6

After Looking into the problem I found a solution using the xlwt library to write the data on a virtual workbook and the xlutils library to save it and thus make the virtual workbook into an actual .xls file.

import xlrd
import xlwt
from xlutils.copy import copy
import os.path
rb = xlrd.open_workbook('my_workbook.xls',formatting_info=True)
r_sheet = rb.sheet_by_index(0) 
wb = copy(rb) 
sheet = wb.get_sheet(0) 
sheet.write(5,2,"string")
wb.save('my_workbook.xls')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.