Код: Выделить всё
open excel file in folder
search all rows
if str(cell value) = "part number"
print("filename" + cell row+1) in another excel file
loop until done
edit:
Файлы, с которыми я работаю, имеют формат .xls, поэтому вместо этого мне пришлось импортировать xlrd.
Я попробовал это
Код: Выделить всё
from xlrd import open_workbook
def do_your_task(filename):
wb = open_workbook(filename = '8307922.xls') # load work book
ws = wb.sheet_by_index(0) # get active work sheet
for row in ws.rows: # iterate over each row
for cell in row: # iterate over each cell in the row
if cell.value == "part number": # find "part number"
return ws.cells(row=cell.row_idx, column=cell.col_idx).value # get the value of the next cell
return None
for root, _, files in os.walk(r'C:\Users\sdiaz\Desktop\Active'):
for file in files:
if file.endswith('.xls'):
print(file, do_your_task(file))
Код: Выделить всё
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [75], in ()
13 for file in files:
14 if file.endswith('.xls'):
---> 15 print(file, do_your_task(file))
Input In [75], in do_your_task(filename)
4 wb = open_workbook(filename = '8307922.xls') # load work book
5 ws = wb.sheet_by_index(0) # get active work sheet
----> 6 for row in ws.rows: # iterate over each row
7 for cell in row: # iterate over each cell in the row
8 if cell.value == "part number": # find "part number"
AttributeError: 'Sheet' object has no attribute 'rows'
Подробнее здесь: https://stackoverflow.com/questions/732 ... next-to-it
Мобильная версия