< /p>
kopieren. Wenn wir beispielsweise die Szenario -Spaltenzelle A1.Results filtern. the long cell (partition column)
**
[*]Input Table

Expected Result Output Tabelle
Bitte schlagen Sie vor, wie wir die Zellen für jeden Test < /p>
< /li>
< /ul>
kopieren können.
Code: Select all
import openpyxl as op
import os
import datetime
input_file_path = r"C:\deleteme_flat"
result_filename = "Report_Summary_" + datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + ".xlsx"
result_file_path = os.path.join(input_file_path, result_filename)
results = list()
def job_summary_gen():
# this is the extension you want to detect
extension = '.xlsx'
file_list = []
i = 0
new_wb = op.Workbook()
# sheet name update
new_wb['Sheet'].title = "Summary"
# wb2 = op.load_workbook(result_file_path)
ws2 = new_wb['Summary']
# If there are any rows already populated in the destination sheet start at next row otherwise start at row 1
if ws2.max_row == 1:
new_row = ws2.max_row
else:
new_row = ws2.max_row + 1
for root, dirs_list, files_list in os.walk(input_file_path):
for file_name in files_list:
if os.path.splitext(file_name)[-1] == extension and file_name == 'testReport.xlsx':
file_name_path = os.path.join(root, file_name)
print(file_name_path) # This is the full path of the filter file
file_list.append(file_name_path)
file_dir = os.path.dirname(file_name_path)
folder_name = os.path.basename(file_dir)
print(folder_name)
wb1 = op.load_workbook(file_name_path)
ws1 = wb1['Summary']
# read flat Report
for cell in ws1.iter_rows(min_col=3, max_col=3):
# print(cell[0].value)
# creating the header
if 'Partition' in cell[0].value.lower() and i < 1:
# print("header workbook"),
# Add 'File #' to first cell in destination row using row number as #
ws2.cell(row=new_row, column=1).value = "File Name"
for x in range(2, ws1.max_column + 1):
# Read each cell from col 1 to last used col
cell_value = ws1.cell(row=cell[0].row, column=x)
# Write last read cell to next empty row
ws2.cell(row=new_row, column=x).value = cell_value.value
# Increment to next unused row
new_row += 1
i += 1
# search for 'long' lower case against the cell value converted to lower case
if 'Partition' not in cell[0].value.lower() and 'long' in cell[0].value.lower():
# Add 'File name' to first cell in destination row using row number as #
ws2.cell(row=new_row, column=1).value = folder_name
# Copy cells Temp1 to Temp5
for x in range(2, ws1.max_column + 1):
# Logic to copy cells Temp1 to Temp5 from the long row to test row
# Increment to next unused row
new_row += 1
new_wb.save(result_file_path)
# create_report()
job_summary_gen()