简体   繁体   English

如何使用python更新xls文件?

[英]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 https://stackoverflow.com/a/26958437/8751278

You should utilize this (from abaldwin99): 您应该利用此(来自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'. 它几乎替代了最左上角的值并将其设置为“ A1”。

You, of course, need to change 'names.xls' with your own file's name. 当然,您需要使用自己文件的名称更改“ names.xls”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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