Bạn có thể sử dụng Python trong Excel không

Tất cả các bạn chắc hẳn đã từng làm việc với Excel vào một lúc nào đó trong đời và chắc hẳn đã cảm thấy cần phải tự động hóa một số tác vụ lặp đi lặp lại hoặc tẻ nhạt. Đừng lo lắng trong hướng dẫn này, chúng ta sẽ tìm hiểu về cách làm việc với Excel bằng Python hoặc tự động hóa Excel bằng Python. Chúng tôi sẽ trình bày vấn đề này với sự trợ giúp của mô-đun Openpyxl

 

Bắt đầu

Openpyxl là một thư viện Python cung cấp nhiều phương thức khác nhau để tương tác với Tệp Excel bằng Python. Nó cho phép các hoạt động như đọc, viết, phép toán số học, vẽ đồ thị, v.v.

Mô-đun này không được tích hợp sẵn với Python. Để cài đặt loại này, lệnh dưới đây trong thiết bị đầu cuối

pip install openpyxl

Bạn có thể sử dụng Python trong Excel không

Đọc từ bảng tính

Để đọc tệp Excel, bạn phải mở bảng tính bằng phương thức load_workbook(). Sau đó, bạn có thể sử dụng kích hoạt để chọn trang tính đầu tiên có sẵn và thuộc tính ô để chọn ô bằng cách chuyển tham số hàng và cột. Thuộc tính giá trị in giá trị của ô cụ thể. Xem ví dụ bên dưới để hiểu rõ hơn.  

Ghi chú. Số nguyên của hàng hoặc cột đầu tiên là 1, không phải 0

Tập dữ liệu được sử dụng. Nó có thể được tải về từ đây

Bạn có thể sử dụng Python trong Excel không

Thí dụ

Python3




# Python program to read an excel file 

 

# import openpyxl module 

import openpyxl 

 

Name
0

Name
1
Name
2
Name
3

 

Name
5

Name
6

Name
7
Name
2
Name
9

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
1

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
2

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
3
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
5

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
7

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
8

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
9

 

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
1

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
2

 

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
4

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
5

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
6
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
8
Name
2 # Python program to read an excel file 0# Python program to read an excel file 1
Name
2 # Python program to read an excel file 0_______427_______4

 

# Python program to read an excel file 6

# Python program to read an excel file 7

# Python program to read an excel file 8_______427_______9

đầu ra

Name

Đọc từ nhiều ô

Có thể có hai cách đọc từ nhiều ô.  

Phương pháp 1. Chúng ta có thể lấy tổng số hàng và cột bằng cách sử dụng max_row và max_column tương ứng. Chúng ta có thể sử dụng các giá trị này bên trong vòng lặp for để lấy giá trị của hàng hoặc cột mong muốn hoặc bất kỳ ô nào tùy thuộc vào tình huống. Hãy xem cách lấy giá trị của cột đầu tiên và hàng đầu tiên

Thí dụ

Python3




# Python program to read an excel file 

 

# import openpyxl module 

import openpyxl 

 

Name
0

Name
1
Name
2
Name
3

 

Name
5

Name
6

Name
7
Name
2
Name
9

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
1

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
2

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
3
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
5

 

import3

import4

import5____1_______2 import7

import8____1_______2 openpyxl 0

 

# Python program to read an excel file 8_______431_______3openpyxl 4openpyxl 5

# Python program to read an excel file 8_______431_______3openpyxl 8openpyxl 9

 

 1

 2

 3

# Python program to read an excel file 8_______431_______3 6 7

 8  9

Name
00
Name
01openpyxl 3# Python program to read an excel file 0
Name
04
Name
05 # Python program to read an excel file 0
Name
07

Name
08
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
6
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
8_______1_______2
Name
13
Name
2 # Python program to read an excel file 0# Python program to read an excel file 4

Name
08# Python program to read an excel file 8# Python program to read an excel file 9

Name
20

 1

 2

Name
23

# Python program to read an excel file 8_______431_______3

Name
26 7

 8  9

Name
00
Name
01_______431_______3# Python program to read an excel file 0# Python program to read an excel file 1
Name
05 # Python program to read an excel file 0
Name
07

Name
08
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
6
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
8_______1_______2
Name
43# Python program to read an excel file 1
Name
2
Name
46

Name
08# Python program to read an excel file 8
Name
49
Name
2
Name
51 7

đầu ra

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 

Phương pháp 2. Chúng ta cũng có thể đọc từ nhiều ô bằng cách sử dụng tên ô. Đây có thể được coi là danh sách cắt của Python

Python3




# Python program to read an excel file 

 

# import openpyxl module 

import openpyxl 

 

Name
0

Name
1
Name
2
Name
3

 

Name
5

Name
6

Name
7
Name
2
Name
9

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
1

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
2

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
3
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
5

 

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
4

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
5

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
6
Name
2
Name
80
Name
81
Name
82
Name
83
Name
84

 

# Python program to read an excel file 6

# Python program to read an excel file 7

 8

Name
89
Name
00
Name
91

Name
08# Python program to read an excel file 8
Name
94

đầu ra

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech

Tham khảo bài viết dưới đây để biết thông tin chi tiết về cách đọc file excel bằng openpyxl

  • Đọc tệp excel bằng mô-đun Python openpyxl

Viết vào bảng tính

Trước tiên, hãy tạo một bảng tính mới, sau đó chúng tôi sẽ ghi một số dữ liệu vào tệp mới tạo. Một bảng tính trống có thể được tạo bằng phương thức Workbook(). Hãy xem ví dụ dưới đây

Thí dụ

Python3




Name
95
Name
96_______430_______
Name
98

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
00

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
01

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
02____1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
04

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
06

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
07

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
08

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
09

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
10
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
12 7

đầu ra

Bạn có thể sử dụng Python trong Excel không

Sau khi tạo một tệp trống, hãy xem cách thêm một số dữ liệu vào tệp đó bằng Python. Để thêm dữ liệu, trước tiên chúng ta cần chọn trang tính đang hoạt động, sau đó sử dụng phương thức cell(), chúng ta có thể chọn bất kỳ ô cụ thể nào bằng cách chuyển số hàng và cột làm tham số của nó. Chúng ta cũng có thể viết bằng cách sử dụng tên ô. Xem ví dụ dưới đây để hiểu rõ hơn

Thí dụ

Python3




# import openpyxl module 

import openpyxl 

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
18

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
01

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
22

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
24

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
2

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
30

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
8

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
9

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
34

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
35

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
36

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
37
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39_______1_______2 # Python program to read an excel file 0# Python program to read an excel file 1
Name
2 # Python program to read an excel file 0# Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
47

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
48_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
50

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
52_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39_______1_______2 # Python program to read an excel file 0 # Python program to read an excel file 1
Name
2
Name
43# Python program to read an excel file 4

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
61____1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
63

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
65

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
66

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
67

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
68
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
71
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
72

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
73
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
75

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
77

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
78
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
81
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
72

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
83____1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
85

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
06

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
07

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
08

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
09

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____10_______12# Python program to read an excel file 4

đầu ra

Bạn có thể sử dụng Python trong Excel không

Tham khảo bài viết dưới đây để biết thông tin chi tiết về cách viết excel

  • Ghi vào tệp excel bằng mô-đun openpyxl

Thêm vào bảng tính

Trong ví dụ trên, bạn sẽ thấy rằng mỗi khi bạn cố gắng ghi vào bảng tính, dữ liệu hiện có sẽ bị ghi đè và tệp được lưu dưới dạng tệp mới. Điều này xảy ra vì phương thức Workbook() luôn tạo đối tượng tệp sổ làm việc mới. Để ghi vào sổ làm việc hiện có, bạn phải mở tệp bằng phương thức load_workbook(). Chúng tôi sẽ sử dụng sổ làm việc được tạo ở trên

Thí dụ

Python3




# import openpyxl module 

import openpyxl 

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
00
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
12_______427_______4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
08
Name
2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
11
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
72

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
13______1_______2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
15

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____10_______12 7

đầu ra

Bạn có thể sử dụng Python trong Excel không

Chúng ta cũng có thể sử dụng phương thức append() để nối nhiều dữ liệu vào cuối trang tính

Thí dụ

Python3




# import openpyxl module 

import openpyxl 

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
00
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
12_______427_______4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
34______1_______2 openpyxl 3

Name
08openpyxl 3# Python program to read an excel file 0
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40
Name
43
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
43
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
44

Name
08openpyxl 3
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
47
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
49
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
51_______428_______7

 7

 

 8 import5

Name
00
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
58

Name
08
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
60

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____18_______63 7

đầu ra

Bạn có thể sử dụng Python trong Excel không

Phép toán số học trên bảng tính

Các phép toán số học có thể được thực hiện bằng cách nhập công thức vào một ô cụ thể của bảng tính. Ví dụ muốn tính tổng thì sử dụng công thức =Sum() của file excel

Thí dụ

Python3




# import openpyxl module 

import openpyxl 

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
18

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
01

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
22

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
24

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
76

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
81

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70_______1_______81
Name
84
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
86

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70_______10_______71
Name
84
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
91

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70_______18_______11
Name
84
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
96

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70_______18_______98
Name
84
Name
2 # Python program to read an excel file 01

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70_______427_______03
Name
84
Name
2 # Python program to read an excel file 06

 

# Python program to read an excel file 08

# Python program to read an excel file 09

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
70_______427_______11
Name
84
Name
2 # Python program to read an excel file 14

 

# Python program to read an excel file 16

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____427_______18# Python program to read an excel file 4

đầu ra

Bạn có thể sử dụng Python trong Excel không

Tham khảo bài viết dưới đây để biết thông tin chi tiết về các phép toán Số học trên Bảng tính

  • Các phép toán số học trong tệp excel bằng openpyxl

Điều chỉnh hàng và cột

Các đối tượng trang tính có các thuộc tính row_dimensions và column_dimensions kiểm soát chiều cao của hàng và chiều rộng của cột. Row_dimensions và column_dimensions của trang tính là các giá trị giống như từ điển; . Trong row_dimensions, người ta có thể truy cập một trong các đối tượng bằng cách sử dụng số của hàng (trong trường hợp này là 1 hoặc 2). Trong column_dimensions, người ta có thể truy cập một trong các đối tượng bằng chữ cái của cột (trong trường hợp này là A hoặc B)

Thí dụ

Python3




# import openpyxl module 

import openpyxl 

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
18

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
01

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
22

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
24

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
76

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

# Python program to read an excel file 36

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2 # Python program to read an excel file 0# Python program to read an excel file 1
Name
2 # Python program to read an excel file 0# Python program to read an excel file 43
Name
2 # Python program to read an excel file 45

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name
43# Python program to read an excel file 1
Name
2
Name
43# Python program to read an excel file 43
Name
2 # Python program to read an excel file 55

 

# Python program to read an excel file 57

# Python program to read an excel file 58# Python program to read an excel file 0# Python program to read an excel file 60

Name
2 # Python program to read an excel file 62

 

# Python program to read an excel file 64

# Python program to read an excel file 65_______427_______66____427_______67_______1_______2 # Python program to read an excel file 69

 

# Python program to read an excel file 16

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____18_______63# Python program to read an excel file 4

đầu ra

Bạn có thể sử dụng Python trong Excel không

Hợp nhất các ô

Một vùng ô hình chữ nhật có thể được hợp nhất thành một ô duy nhất bằng phương thức trang tính merge_cells(). Đối số cho merge_cells() là một chuỗi gồm các ô trên cùng bên trái và dưới cùng bên phải của vùng hình chữ nhật sẽ được hợp nhất

Thí dụ

Python3




import openpyxl 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
22

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

# Python program to read an excel file 84

# Python program to read an excel file 85

# Python program to read an excel file 86

# Python program to read an excel file 87_______427_______88# Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name
43# Python program to read an excel file 1
Name
2 # Python program to read an excel file 0# Python program to read an excel file 43
Name
2 # Python program to read an excel file 99

 

 01

# Python program to read an excel file 87_______428_______03# Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
51_______427_______1
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
51# Python program to read an excel file 43
Name
2  14

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____18_______63 7

đầu ra

Bạn có thể sử dụng Python trong Excel không

Hợp nhất các ô

Để hủy hợp nhất các ô, hãy gọi phương thức trang tính unmerge_cells()

Thí dụ

Python3




import openpyxl 

 

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
00
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
63# Python program to read an excel file 4

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

 32

 33______427_______88# Python program to read an excel file 4

 

 33______428_______03# Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____18_______63 7

đầu ra

Bạn có thể sử dụng Python trong Excel không

Đặt kiểu phông chữ

Để tùy chỉnh kiểu phông chữ trong các ô, quan trọng, hãy nhập hàm Font() từ openpyxl. mô-đun phong cách

Thí dụ

Python3




import openpyxl 

 

 47

Name
95  49import  51

 

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
22

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
28

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2 # Python program to read an excel file 0# Python program to read an excel file 1
Name
2 # Python program to read an excel file 0# Python program to read an excel file 43
Name
2  69

 

 71

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2 # Python program to read an excel file 0# Python program to read an excel file 1
Name
2 # Python program to read an excel file 0 78
Name
2  80
Name
2  82 # Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name
43# Python program to read an excel file 1
Name
2
Name
43# Python program to read an excel file 43
Name
2  69

 

 95

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name
43# Python program to read an excel file 1
Name
2
Name
43 78
Name
2  80
Name
2  82# import openpyxl module 07
Name
2 # import openpyxl module 09# Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
43# Python program to read an excel file 1
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
43# Python program to read an excel file 43
Name
2  69

 

# import openpyxl module 22

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
43# Python program to read an excel file 1
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
43 78
Name
2  80
Name
2  82# import openpyxl module 34
Name
2 # import openpyxl module 09# Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
47_______427_______1
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
47# Python program to read an excel file 43
Name
2  69

 

# import openpyxl module 49

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
39
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
47_______427_______1
Name
2
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
47 78
Name
2  80
Name
2  82# import openpyxl module 61
Name
2 # import openpyxl module 63# Python program to read an excel file 4

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____18_______63# Python program to read an excel file 4

đầu ra

Bạn có thể sử dụng Python trong Excel không

Tham khảo bài viết dưới đây để biết thông tin chi tiết về điều chỉnh hàng và cột

  • Điều chỉnh các hàng và cột của tệp excel bằng mô-đun openpyxl

vẽ biểu đồ

Biểu đồ bao gồm ít nhất một chuỗi một hoặc nhiều điểm dữ liệu. Bản thân chuỗi bao gồm các tham chiếu đến phạm vi ô. Để vẽ biểu đồ trên trang tính excel, trước tiên, hãy tạo các đối tượng biểu đồ của lớp biểu đồ cụ thể ( i. e Biểu đồ thanh, Biểu đồ đường, v.v. ). Sau khi tạo các đối tượng biểu đồ, hãy chèn dữ liệu vào đó và cuối cùng, thêm đối tượng biểu đồ đó vào đối tượng trang tính

ví dụ 1

Python3




# import openpyxl module 69

import

Name
96

 

# import openpyxl module 73

Name
95 # import openpyxl module 75import # import openpyxl module 77

 

# import openpyxl module 79

# import openpyxl module 80

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20______1_______2 # import openpyxl module 83

 

# import openpyxl module 85

# import openpyxl module 86

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2 # import openpyxl module 89

 

# import openpyxl module 91

 8  9

Name
00
Name
01openpyxl 3# import openpyxl module 97# import openpyxl module 98

Name
08import00

 

import02

import03

Name
2 import05
Name
2# Python program to read an excel file 0import08
Name
2# Python program to read an excel file 0
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40

import12import13

Name
2# Python program to read an excel file 0import16
Name
2# import openpyxl module 97_______428_______7

 

import21

import22

Name
2 import24

 

import26

import27

 

import29

import30

Name
2 import32

 

import34

import35______1_______2 import37

 

import39

import40

Name
2 import42

 

import44

import45

import46

import47____430_______48 7

 

import51

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____10_______12 7

đầu ra

Bạn có thể sử dụng Python trong Excel không

ví dụ 2

Python3




# import openpyxl module 69

import

Name
96

 

import59

Name
95 # import openpyxl module 75import import63

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20______1_______2 # import openpyxl module 83

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2 # import openpyxl module 89

 

# import openpyxl module 91

 8  9

Name
00
Name
01openpyxl 3# import openpyxl module 97# import openpyxl module 98

Name
08import00

 

import03

Name
2 import05
Name
2# Python program to read an excel file 0import08
Name
2# Python program to read an excel file 0
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40

import12import13

Name
2# Python program to read an excel file 0import16
Name
2# import openpyxl module 97_______428_______7

 

openpyxl 01

import22____1_______2 openpyxl 04

 

import27

 

import29

import30

Name
2 openpyxl 11

 

import34

import35______1_______2 openpyxl 16

 

import39

import40

Name
2 openpyxl 21

 

import44

import45

import46

import47____430_______48 7

 

import51

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
91____10_______12 7

đầu ra

Bạn có thể sử dụng Python trong Excel không

Tham khảo các bài viết dưới đây để biết thông tin chi tiết về vẽ đồ thị trong excel bằng Python

  • Vẽ biểu đồ trong bảng excel bằng mô-đun openpyxl. Hiệp 1
  • Vẽ biểu đồ trong bảng excel bằng mô-đun openpyxl. Đặt  2
  • Vẽ biểu đồ trong bảng excel bằng mô-đun openpyxl. bộ 3

Thêm hình ảnh

Với mục đích nhập hình ảnh bên trong trang tính của chúng tôi, chúng tôi sẽ sử dụng openpyxl. đang vẽ. hình ảnh. Hình ảnh. Phương pháp này là một trình bao bọc trên PIL. Phương pháp hình ảnh được tìm thấy trong thư viện PIL (gối). Do đó, cần phải cài đặt thư viện PIL (gối) để sử dụng phương pháp này

Hình ảnh được sử dụng

Bạn có thể sử dụng Python trong Excel không

Thí dụ

Python3




import openpyxl 

Name
95 openpyxl 37import openpyxl 39

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
20_______1_______2
Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
22

 

Total Rows: 6
Total Columns: 4

Value of first column
Name
Ankit
Rahul
Priya
Nikhil
Nisha

Value of first row
Ankit  B.Tech CSE 4 
26______1_______2 # import openpyxl module 89

 

openpyxl 49

openpyxl 50

openpyxl 51_______429_______97

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40openpyxl 54
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40openpyxl 56
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
47
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
40openpyxl 60openpyxl 61

Bạn có thể sử dụng Python trong Excel thay vì VBA không?

CÔNG CỤ MACRO VÀ EXCEL . g. thông qua một nút trên trang tính. Điều này cũng hoạt động tốt cho các ứng dụng web tạo mẫu (Windows & Mac). Write Excel tools with Python instead of VBA and call your code directly from within Excel, e.g. via a button on the sheet. This also works great for prototyping web apps (Windows & Mac).

Python có tốt với Excel không?

Excel có thể là trở ngại lớn khi bạn đang cố tự động hóa một quy trình hoặc chạy nhiều lần cùng một phân tích. Sử dụng Python có thể giúp việc này nhanh hơn nhiều .

Bạn có thể sử dụng Python để tự động hóa Excel không?

Nhìn chung, Tự động hóa Python Excel là một quy trình sáng tạo mà bạn có thể sử dụng để tạo báo cáo trực quan trên Python giống như cách bạn làm trên Excel một cách liền mạch. Organizations can leverage Python Excel Automation to leverage their business tasks according to their needs.

Bạn có thể sử dụng các hàm Python trong Excel không?

Các hàm trang tính Excel hoặc UDF (Hàm do người dùng xác định) là cách trực quan nhất để gọi các hàm Python trong Excel . Chắc hẳn bạn đã quen với việc gọi các hàm trang tính trong Excel rồi. Nếu bạn đã sử dụng SUM để tính tổng một cột số thì bạn đã sử dụng một hàm trang tính.