該腳本似乎運行沒有錯誤,但在文本文件中看不到任何輸出(盡管我可以看到該文件已在修改日期之前進行了編輯)。我對 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
提交
取消