[Easy Python] Reading Excel files with openpyxl

What is OpenPyXL

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.

Read Excel file

The contents of sample.xlsx

bandicam 2020-01-20 16-36-57-804.jpg

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.

Read specified cell

main.py


import openpyxl

wb = openpyxl.load_workbook('sample.xlsx')
ws = wb['sheet1']

So far, it is common.

Get with the specified character string in Excel

main.py


cell = ws['A2'] # A

Get by specifying the row number and column number

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

Summary

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

[Easy Python] Reading Excel files with openpyxl
[Easy Python] Reading Excel files with pandas
Operate Excel with Python openpyxl
Reading .txt files with Python
Handle Excel CSV files with Python
Excel with Python
[Python] Easy reading of serial number image files with OpenCV
Reading and writing JSON files with Python
Handle Excel with python
[Python] Reading CSV files
Read excel with openpyxl
Operate Excel with Python (1)
Operate Excel with Python (2)
Reading and writing fits files with Python (memo)
[Co-occurrence analysis] Easy co-occurrence analysis with Python! [Python]
Let's run Excel with Python
Manipulate excel files from python with xlrd (personal notes)
Easy folder synchronization with Python
Sorting image files with Python (2)
Sort huge files with python
Sorting image files with Python (3)
Sorting image files with Python
Integrate PDF files with Python
Easy Python compilation with NUITKA-Utilities
Easy HTTP server with Python
Improve your productivity by processing huge Excel files with Python
Manipulating EAGLE .brd files with Python
[Python] POST wav files with requests [POST]
Create an Excel file with Python3
Decrypt files encrypted with OpenSSL with Python 3
Let's play with Excel with Python [Beginner]
Easy Python + OpenCV programming with Canopy
Easy email sending with haste python3
Reading and writing NetCDF with Python
Bayesian optimization very easy with Python
Multi-line size specification reading with python
Read files in parallel with Python
Easy data visualization with Python seaborn.
Reading and writing CSV with Python
Easy parallel execution with python subprocess
Easy modeling with Blender and Python
Excel aggregation with Python pandas Part 1
Easy keyword extraction with TermExtract for Python
[Python] Super easy test with assert statement
[Python] Easy argument type check with dataclass
Play audio files from Python with interrupts
"System trade starting with Python3" reading memo
Draw Nozomi Sasaki in Excel with python
Quickly create an excel file with Python #python
Convert Excel data to JSON with python
Easy introduction of speech recognition with Python
Decrypt files encrypted with openssl from python with openssl
Excel aggregation with Python pandas Part 2 Variadic
Download files on the web with Python
Easy web app with Python + Flask + Heroku
Create Excel file with Python + similarity matrix
Easy image processing in Python with Pillow
Convert HEIC files to PNG files with Python
Excel table creation with Python [Progress management table]
Easy web scraping with Python and Ruby
[Python] Easy Reinforcement Learning (DQN) with Keras-RL