I have one xls file named template.xls,which has some style and values,i want to insert a value in template.xls.How can i do this?
Asked
Active
Viewed 1,827 times
0
-
https://stackoverflow.com/questions/26957831/edit-existing-excel-workbooks-and-sheets-with-xlrd-and-xlwt – joaquinn Oct 10 '17 at 09:45
-
Maybe this guide can help you: https://automatetheboringstuff.com/chapter12/ – Anton vBR Oct 10 '17 at 10:04
-
My .xls file has some style.It does not affect on copied xls file – Ashok Oct 10 '17 at 10:52
-
Possible duplicate of [Edit existing excel workbooks and sheets with xlrd and xlwt](https://stackoverflow.com/questions/26957831/edit-existing-excel-workbooks-and-sheets-with-xlrd-and-xlwt) – toonarmycaptain Oct 10 '17 at 11:56
-
Colors not affect on copied xls file – Ashok Oct 10 '17 at 13:16
1 Answers
-1
There's already a thread related to your specific question.
https://stackoverflow.com/a/26958437/8751278
You should utilize this (from abaldwin99):
#xlrd, xlutils and xlwt modules need to be installed.
#Can be done via pip install <module>
from xlrd import open_workbook
from xlutils.copy import copy
rb = open_workbook("names.xls")
wb = copy(rb)
s = wb.get_sheet(0)
s.write(0,0,'A1')
wb.save('names.xls')
However, you need to install the modules before it works.
It pretty much replaces the very top-left value and sets it to 'A1'.
You, of course, need to change 'names.xls' with your own file's name.

Jakob Staudal
- 9
- 2
-
worth to note that this method will not conserve color formatting and formulas in the spreadsheet – joaquinn Oct 10 '17 at 09:54