简体   繁体   中英

How to Update xls file using python?

我有一个名为template.xls的xls文件,它具有一些样式和值,我想在template.xls中插入一个值。我该怎么做?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM