Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Tất cả các bạn phải làm việc với Excel tại một số thời điểm trong cuộc sống của bạn và phải cảm thấy cần phải tự động hóa một số nhiệm 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 tôi sẽ tìm hiểu về cách làm việc với Excel bằng cách sử dụng Python hoặc tự động hóa Excel bằng Python. Chúng tôi sẽ đề cập đến điều 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 các phương pháp khác nhau để tương tác với các tệp Excel bằng Python. Nó cho phép các hoạt động như đọc, viết, hoạt động số học, vẽ đồ thị, v.v.is a Python library that provides various methods to interact with Excel Files using Python. It allows operations like reading, writing, arithmetic operations, plotting graphs, etc.

Mô-đun này không được xây dựng 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

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Đọc từ bảng tính

Để đọc một 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 hoạt động để chọn bảng đầ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ụ dưới đây để hiểu rõ hơn. & NBSP;load_workbook() method. After that, you can use the active to select the first sheet available and the cell attribute to select the cell by passing the row and column parameter. The value attribute prints the value of the particular cell. See the below example to get a better understanding. 

Lưu ý: Hàng đầu tiên hoặc số nguyên cột là 1, không phải 0.The first row or column integer is 1, not 0.

Bộ dữ liệu được sử dụng: Nó có thể được tải xuống từ đây. It can be downloaded from here.

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Example:

Python3

import openpyxl 

path = "gfg.xlsx"

wb_obj =

Name
1

Name
2=
Name
4

Name
5=
Name
7=
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 
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 
5

Output:

Name

Đọc từ nhiều ô

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

Phương pháp 1: Chúng ta có thể nhận được số lượng của 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 để có được 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 cùng xem cách nhận được giá trị của cột đầu tiên và hàng đầu tiên.We can get the count of the total rows and columns using the max_row and max_column respectively. We can use these values inside the for loop to get the value of the desired row or column or any cell depending upon the situation. Let’s see how to get the value of the first column and first row.

Example:

Python3

import openpyxl 

path = "gfg.xlsx"

wb_obj =

Name
1

Name
2=
Name
4

Name
5=
Name
7=
Name
9______

Đọc từ nhiều ô

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 
4import4import5import6

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 
4import4import9openpyxl 0

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 
4import4openpyxl 3openpyxl 4

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

Phương pháp 1: Chúng ta có thể nhận được số lượng của 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 để có được 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 cùng xem cách nhận được giá trị của cột đầu tiên và hàng đầu tiên.

path 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 
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 
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 
4import4=9openpyxl 4

Python3

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

import0= import2

Output:

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 

openpyxl 5 openpyxl 6openpyxl 7 openpyxl 8__We can also read from multiple cells using the cell name. This can be seen as the list slicing of Python.

Python3

import openpyxl 

path = "gfg.xlsx"

wb_obj =

Name
1

Name
2=
Name
4

Name
5=
Name
7=
Name
9______

Đọc từ nhiều ô

path 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 
4
Name
30

Output:

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

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

  • Phương pháp 1: Chúng ta có thể nhận được số lượng của 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 để có được 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 cùng xem cách nhận được giá trị của cột đầu tiên và hàng đầu tiên.

Python3

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
7=
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
9Workbook() method. Let’s see the below example.

Example:

Python3

import0= import2

openpyxl 5 openpyxl 6openpyxl 7 openpyxl 8__

Name
38=
Name
40openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

path 5

Name
5=
Name
7= =0__

Example:

Python3

import openpyxl 

path = "gfg.xlsx"

wb_obj =

Name
1

Name
2=
Name
4

Name
5=
Name
7=
Name
9______

Đọc từ nhiều ô

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

Phương pháp 1: Chúng ta có thể nhận được số lượng của 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 để có được 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 cùng xem cách nhận được giá trị của cột đầu tiên và hàng đầu tiên.

Python3

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

import0= import2

Name
90
Name
40
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

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

openpyxl 5 openpyxl 6openpyxl 7 openpyxl 8__

  • path 5
    Name
    5=
    Name
    7= =0__

Nối 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ó bị ghi đè và tệp được lưu dưới dạng tệp mới. Điều này xảy ra bởi vì phương thức Workbook () luôn tạo một đố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 ra ở trên.Workbook() method always creates a new workbook file object. To write to an existing workbook you must open the file with the load_workbook() method. We will use the above-created workbook.

Example:

Python3

import openpyxl 

Name
44=
Name
97
Name
40
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
47=
Name
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 
03=
Name
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 
06
Name
78

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 
10

Name
90
Name
40openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Chúng tôi cũng có thể sử dụng phương thức append () để nối nhiều dữ liệu ở cuối trang.append() method to append multiple data at the end of the sheet.

Example:

Python3

import openpyxl 

Name
44=
Name
97
Name
40
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
47=
Name
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 
03=
Name
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 
06
Name
78

path 5import4

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 
30wb_obj 6
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 
33
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

path 5import4

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
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 
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 
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 
41openpyxl 4

openpyxl 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 
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 
10

path 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 
49

Name
90
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 
51openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Chúng tôi cũng có thể sử dụng phương thức append () để nối nhiều dữ liệu ở cuối trang.

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= import4 =Sum() formula of the excel file is used.

Example:

Python3

import openpyxl 

Name
44=
Name
97
Name
40
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
47=
Name
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 
03=
Name
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 
06
Name
78

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 
10

Chúng tôi cũng có thể sử dụng phương thức append () để nối nhiều dữ liệu ở cuối trang.

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= import4

openpyxl 5

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
7openpyxl 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 
47

Hoạt động số học trên bảng tính

Các hoạt động số học có thể được thực hiện bằng cách gõ công thức trong một ô cụ thể của bảng tính. Ví dụ: nếu chúng ta muốn tìm tổng công thức SUM sau đó = sum () của tệp excel được sử dụng.

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Name
44=
Name
46

  • Name
    76
    Name
    20
    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

Name76Name777____263= 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
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 
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 
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 
75

Example:

Python3

import openpyxl 

Name
44=
Name
97
Name
40
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
47=
Name
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 
03=
Name
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 
06
Name
78

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 
10

Chúng tôi cũng có thể sử dụng phương thức append () để nối nhiều dữ liệu ở cuối trang.

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= import4

Name
90
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 
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 
3

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

openpyxl 5 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech7openpyxl 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 47

Hoạt động số học trên bảng tính

Example:

Python3

import openpyxl 

Name
44=
Name
97
Name
40
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
47=
Name
49

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
41
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
42
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

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 
03=
Name
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 
06
Name
78

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
41
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
54
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

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 
10

Name
90
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 
51openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Chúng tôi cũng có thể sử dụng phương thức append () để nối nhiều dữ liệu ở cuối trang.

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= import4

Example:

Python3

import openpyxl 

openpyxl 5

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
7openpyxl 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 
47

Name
47=
Name
49

Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
78
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
42
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 Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
78
Name Course
Ankit  B.Tech
Rahul M.Tech
Priya MBA
Nikhil B.Tech
Nisha B.Tech
54
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
90
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 
51openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Hoạt động số học trên bảng tính

Các hoạt động số học có thể được thực hiện bằng cách gõ công thức trong một ô cụ thể của bảng tính. Ví dụ: nếu chúng ta muốn tìm tổng công thức SUM sau đó = sum () của tệp excel được sử dụng.Font() function from the openpyxl.styles module.

Example:

Python3

import openpyxl 

Name
44=
Name
46

Name
44=
Name
97
Name
40
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
47=
Name
49

Name
47=
Name
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 
03=
Name
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 
06
Name
78

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 
10

Chúng tôi cũng có thể sử dụng phương thức append () để nối nhiều dữ liệu ở cuối trang.

Name
52=
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 
33______

Name
52=
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 
33______

Name
52=
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
52=
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
90
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 
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 
3

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Tham khảo bài viết dưới đây để có thông tin chi tiết về việc điều chỉnh các 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

Biểu đồ biểu đồ

Biểu đồ bao gồm ít nhất một loạt một hoặc nhiều điểm dữ liệu. Bản thân loạt bao gồm các tài liệu tham khảo về phạm vi ô. Để vẽ các biểu đồ trên một tờ Excel, trước tiên, hãy tạo các đối tượng biểu đồ của lớp biểu đồ cụ thể (tức là Barchart, Linechart, v.v.). Sau khi tạo các đối tượng biểu đồ, 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 import96

Name
31 import98import openpyxl 00

Name
44= openpyxl 03

Name
47= openpyxl 06

openpyxl 5 openpyxl 6openpyxl 7 openpyxl 8import4openpyxl 1212

path 5openpyxl 15

openpyxl 16= openpyxl 18=

Name
9openpyxl 21=
Name
9openpyxl 24

Các

openpyxl 33= openpyxl 35

openpyxl 36

openpyxl 37= openpyxl 39

openpyxl 40= openpyxl 42

openpyxl 43= openpyxl 45

openpyxl 46openpyxl 47openpyxl 4

Name
90
Name
40openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Ví dụ 2:

Python3

import import96

Name
31 import98import openpyxl 00

Name
44= openpyxl 03

Name
47= openpyxl 06

openpyxl 5 openpyxl 6openpyxl 7 openpyxl 8import4openpyxl 1212

path 5openpyxl 15

openpyxl 16= openpyxl 18=

Name
9openpyxl 21=
Name
9openpyxl 24

openpyxl 25openpyxl 26=

Name
9openpyxl 29=openpyxl 12openpyxl 4

Các

openpyxl 36

openpyxl 33= openpyxl 35

openpyxl 37= openpyxl 39

openpyxl 40= openpyxl 42

openpyxl 46openpyxl 47openpyxl 4

Name
90
Name
40openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

openpyxl 43= openpyxl 45

  • Ví dụ 2:
  • Name
    31 import98import openpyxl 57
  • openpyxl 33= openpyxl 92

openpyxl 37= openpyxl 96

openpyxl 40__ openpyxl 99openpyxl.drawing.image.Image. The method is a wrapper over PIL.Image method found in PIL (pillow) library. Due to which it is necessary for the PIL (pillow) library to be installed in order to use this method.

openpyxl 43= path 02

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Example:

Python3

Tham khảo các bài viết dưới đây để có được thông tin chi tiết về âm mưu excel bằng Python.

Biểu đồ biểu đồ trong trang tính Excel bằng mô -đun OpenPyXL | Đặt & nbsp; 1

Biểu đồ biểu đồ trong trang tính Excel bằng mô -đun OpenPyXL | Đặt & NBSP; 2

Name
47= openpyxl 06

openpyxl 5 openpyxl 6openpyxl 7 openpyxl 8import4openpyxl 1212

openpyxl 16= openpyxl 18=

Name
9openpyxl 21=
Name
9openpyxl 24

path 37

Name
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 
3

Name
90
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 
51openpyxl 4

Output:

Hướng dẫn does excel and python work together? - excel và python có hoạt động cùng nhau không?

Các

  • openpyxl 33= openpyxl 35

openpyxl 37= openpyxl 39

  • openpyxl 40= openpyxl 42
  • openpyxl 43= openpyxl 45
  • Ví dụ 2:
  • Name
    31 import98import openpyxl 57