简体   繁体   English

使用Python编辑Excel文件并将其保存到新文件

[英]Editing an Excel file and saving it to a new file with Python

I want to go into my current folder and edit whatever files is in the folder with the string "test" onto cell 0,0 and then save it as book1.xlsx but my code is giving me an error. 我想进入当前文件夹并使用字符串“ test”将文件夹中的任何文件编辑到单元格0,0上,然后将其另存为book1.xlsx,但是我的代码给我一个错误。 Can anyone help? 有人可以帮忙吗?

import xlrd
import os
import glob
from xlutils.copy import copy

fileDir = os.getcwd()
fileLocation = glob.glob("*.xlsx")



x = copy(fileLocation)
x.get_sheet(0).write(0,0,"test")
x.save('book1.xlsx')

glob.glob("*.xlsx") must return a list, so I think the error is on the copy statement. glob.glob(“ *。xlsx”)必须返回一个列表,因此我认为错误在于复制语句。

Try with : 尝试:

x = copy(fileLocation[0])

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

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