Hi I have the following code
wb_obj = openpyxl.load_workbook(path, data_only=True)
worksheet = wb_obj.get_sheet_by_name('Sheet1')
for row_cells in worksheet.iter_rows():
for cell in row_cells:
print('%s: cell.value=%s' % (cell, cell.value) )
it works well. however I do not need it to show the data from the first row which is the header row. How can I change the query to exclude the first row?
The documentation suggests using iter_rows
for row_cells in worksheet.iter_rows(min_row=2):
for cell in row_cells:
print('%s: cell.value=%s' % (cell, cell.value) )
Since iter_rows is a generator, we unfortunately cannot slice out the first line [1:], so this is a hackish but effective way to skip the first row.
for i, row_cells in enumerate(worksheet.iter_rows()):
if i == 0:
continue
for cell in row_cells:
print('%s: cell.value=%s' % (cell, cell.value))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With