openpyxl is a Python library. openpyxl is used when working with Excel files.
Since it is a library specialized for Excel operations, it has the advantage of being lightweight and easy to use.
The contents of sample.xlsx
If
wb = openpyxl.load_workbook('sample.xlsx')
You can get the Workbook object by doing. further
ws = wb['sheet1']
You can get the Worksheet object by doing. Now the information of the sheet name'sheet1' of sample.xlsx is in ws.
main.py
import openpyxl
wb = openpyxl.load_workbook('sample.xlsx')
ws = wb['sheet1']
So far, it is common.
main.py
cell = ws['A2'] # A
main.py
cell = ws.cell(row=2, column=1) # B
The cell value (value) of A and B is "1" for both.
main.py
print(cell.value) #1 is displayed
I introduced how to read an Excel file using OpenPyXL. It's a perfect library for working with Excel files in Python, so please use it.
Recommended Posts