How to read/write Excel files in Python
Python
83
excel
16
read
6
write
5
Male avatar

loveprogramming viết ngày 16/05/2021

https://grokonez.com/python/how-to-read-write-excel-files-in-python-openpyxl-module

How to read/write Excel files in Python

In this tutorial, we're gonna look at way to use openpyxl module to read, write Excel spreadsheet files in Python program.

Excel spreadsheet files

An Excel file is called a workbook which is saved on PC as .xlsx extension.
Each workbook contains one or more sheets.
Each sheet has columns (letters: A, B, C...) and rows (numbers: 1, 2, 3...).
A box addressed by [column, row] pair is called a cell.

read-write-excel-files-in-python-openpyxl-module-excel-file

Read/Write Excel files in Python

Install openpyxl module

Open cmd, then run:
pip install openpyxl

Once the installation is successful, we can see openpyxl folder at Python\Python[version]\Lib\site-packages.
(In this tutorial, we use openpyxl 2.5.12)

Now we can import the module by running import openpyxl.

Read Excel file

Open workbook

We use openpyxl.load_workbook(filename) function with input filename to get a Workbook object that represents the Excel file.


>>> import openpyxl
>>> gkzWb = openpyxl.load_workbook('grokonez.xlsx')
>>> type(gkzWb)

Get sheets

We call Workbook's get_sheet_names() method to get list of all the sheet names in the workbook.

More at:

https://grokonez.com/python/how-to-read-write-excel-files-in-python-openpyxl-module

How to read/write Excel files in Python

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

545 bài viết.
97 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 12 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 10 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 10 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/nodejs/nodejsimportexcelfiletomysqlusingreadexcelfilelib Node.js Import Excel File to MySQL – using ReadExcelFile lib In t...
loveprogramming viết 5 tháng trước
0 0
Male avatar
0 0
https://ozenero.com/excelfiledatanodejsexpressrestapidownloadextractexcelxlsxdatafilefrommysql Excel File/Data – Nodejs Express RestAPI – Download...
loveprogramming viết 7 tháng trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
545 bài viết.
97 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!