Using Python with Excel Spreadsheets with OpenPyXL

Using Python with Excel Spreadsheets with OpenPyXL

Working with Excel Spreadsheets

SOURCE: https://automatetheboringstuff.com/chapter12/

Ricky’s Example to simply read all the rows in a sheet and print the first two columns of data:

import openpyxl
wb = openpyxl.load_workbook(‘data.xlsx’)
print type(wb)
wb.get_sheet_names()
sheet = wb.get_sheet_by_name(‘sheet1’)
print sheet, ” – “, sheet.title
i = 1
for i in range(1, sheet.max_row + 1):
print ‘{0:5} {1:25} {2:20}’.format(i,sheet.cell(row=i, column=1).value,sheet.cell(row=i, column=2).value)

Comments are closed.