该脚本似乎运行没有错误,但在文本文件中看不到任何输出(尽管我可以看到该文件已在修改日期之前进行了编辑)。我对 python 很陌生,所以对任何明显的错误表示歉意。谢谢你的帮助。我最初使用 xlrd 但由于可能与 .xlsm 文件不兼容而改为 openpyxl(这是真的吗)def list_files(directory, extension): from os import listdir return (f for f in listdir(directory) if f.endswith('.' + extension))def scrape(xlpath, name, crit, row, column): from openpyxl import load_workbook directory = os.getcwd() #discover values loc = xlpath wb = load_workbook(loc) sheet = wb.get_sheet_by_name(name) place = row+","+column data = sheet.cell(place).value #transfer to text file print("\n ", crit, " : ", data.cells.value, file=open("info.txt", "a"))def presenting(pth): scrape(pth, 'generic val1', 'Sheet1', '7', '1') scrape(pth, 'generic val2', 'Sheet1', '0', '1') scrape(pth, 'generic val3', 'Sheet1', '8', '1') scrape(pth, 'generic val4', 'Sheet1', '29', '4') scrape(pth, 'generic val5', 'Sheet2', '21', '6') scrape(pth, 'generic val6', 'Sheet2', '22', '6') scrape(pth, 'generic val7', 'Sheet2', '56', '19') scrape(pth, 'generic val8', 'Sheet2', '56', '20') scrape(pth, 'generic val9', 'Sheet2', '56', '21') scrape(pth, 'generic val10', 'Sheet2', '36', '14') scrape(pth, 'generic val11', 'Sheet2', '37', '14')def process(): import os directory = os.getcwd() files = list_files(directory, "xlsm") for f in files: pth = str(f) print("\n", pth, file=open("info.txt", "a")) presenting(pth)import osdirectory = os.getcwd()open('info.txt', 'w').close()process()预期结果是从本地文件夹(工作目录)中的所有 excel 文件中检索到的通用变量及其各自值的列表。实际结果只是本地文件夹中第一个(3 个)excel 文件的名称。
添加回答
举报
0/150
提交
取消