Question: Is there a way to speed this up or use better methodology?
请尝试以下操作以查看此操作是否可以提高性能:Note: Didn't know the Values of col and max_column!
My Example uses 4 Columns and skips Column C.
Data:
['A1', 'B1', 'C1', 'D1'],
['A2', 'B2', 'C2', 'D2']from openpyxl.utils import range_boundaries
min_col, min_row, max_col, max_row = range_boundaries('A1:D2')
for row_cells in ws.iter_rows(min_col=min_col, min_row=min_row,
max_col=max_col, max_row=max_row):
# Slice Column Values up to B
data = [cell.value for cell in row_cells[:2]]
# Extend List with sliced Column Values from D up to End
data.extend([cell.value for cell in row_cells[3:]])
# Append db.get(Column A.value)
data.append(db.get(row_cells[0].value, "notfound"))
# Join all List Values delimited with \t
print('{}'.format('\t'.join(data)))
# Write to CSV
#w.write(data)Output:
A1 B1 D1 notfound
A2 B2 D2 notfound
使用Python:3.4.2-openpyxl:2.4.1进行测试