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 Show
Bắt đầuOpenpyxl 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 Đọ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 Thí dụ Python3
Name0 Name1 Name2 Name3
Name5 Name6 Name7 Name2 Name9
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 41 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 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 43 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 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 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 48 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 49
Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech1 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech2
Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech4 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech5 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech6 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech8 Name2 # Python program to read an excel file 0# Python program to read an excel file 1Name2 # Python program to read an excel file 0_______427_______4
đầ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
Name0 Name1 Name2 Name3
Name5 Name6 Name7 Name2 Name9
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 41 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 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 43 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 45
Name00 Name01 openpyxl 3# Python program to read an excel file 0Name04 Name05 # Python program to read an excel file 0Name07 Name08 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech6 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech8_______1_______2 Name13 Name2 # Python program to read an excel file 0# Python program to read an excel file 4Name08 # Python program to read an excel file 8# Python program to read an excel file 9Name20
Name23
Name26 7
Name00 Name01_______431_______3 # Python program to read an excel file 0# Python program to read an excel file 1Name05 # Python program to read an excel file 0Name07 Name08 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech6 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech8_______1_______2 Name43 # Python program to read an excel file 1Name2 Name46 Name08 # Python program to read an excel file 8Name49 Name2 Name51 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
Name0 Name1 Name2 Name3
Name5 Name6 Name7 Name2 Name9
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 41 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 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 43 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 45
Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech4 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech5 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech6 Name2 Name80 Name81 Name82 Name83 Name84
Name89 Name00 Name91 Name08 # Python program to read an excel file 8Name94 đầ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
Viết vào bảng tínhTrướ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ụ Python3Name95 Name96_______430_______ Name98
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 400 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 401 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 402____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 404
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 406 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 407 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 408 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 409 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 410 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 412 7đầu ra 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
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 418 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 401 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 420_______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 422
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 424 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 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 426______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 428
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 430 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 48 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 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 434 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 435 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 436 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 437 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439_______1_______2 # Python program to read an excel file 0# Python program to read an excel file 1Name2 # 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 447 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 448_______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 450
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 452_______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 439_______1_______2 # Python program to read an excel file 0 # Python program to read an excel file 1Name2 Name43 # Python program to read an excel file 4Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 461____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 463
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 465 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 466 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 467 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 468 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 471 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 472 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 473 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 475
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 477 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 478 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 481 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 472 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 483____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 485
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 406 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 407 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 408 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 409 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 491____10_______12 # Python program to read an excel file 4đầu ra Tham khảo bài viết dưới đây để biết thông tin chi tiết về cách viết excel
Thêm vào bảng tínhTrong 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
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 420_______1_______2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech00 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 412_______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 426______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 428
Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech08 Name2 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech11 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 472 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech13______1_______2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech15
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 491____10_______12 7đầu ra 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
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 420_______1_______2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech00 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 412_______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 426______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 428
Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech34______1_______2 openpyxl 3Name08 openpyxl 3# Python program to read an excel file 0Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 Name43 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech43 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech44 Name08 openpyxl 3Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech47 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech49 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech51_______428_______7
Name00 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech58 Name08 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech60
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 491____18_______63 7đầu ra Phép toán số học trên bảng tínhCá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
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 418 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 401 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 420_______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 422
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 424 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech76 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 426______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 428
Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech81 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470_______1_______81 Name84 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech86 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470_______10_______71 Name84 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech91 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470_______18_______11 Name84 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech96 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470_______18_______98 Name84 Name2 # Python program to read an excel file 01Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 470_______427_______03 Name84 Name2 # Python program to read an excel file 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 470_______427_______11 Name84 Name2 # Python program to read an excel file 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 491____427_______18 # Python program to read an excel file 4đầu ra 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
Điều chỉnh hàng và cộtCá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
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 418 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 401 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 420_______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 422
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 424 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech76 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 426______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 428
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 # Python program to read an excel file 0# Python program to read an excel file 1Name2 # Python program to read an excel file 0# Python program to read an excel file 43Name2 # 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 439 Name2 Name43 # Python program to read an excel file 1Name2 Name43 # Python program to read an excel file 43Name2 # Python program to read an excel file 55
Name2 # Python program to read an excel file 62
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 491____18_______63 # Python program to read an excel file 4đầu ra 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
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 420_______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 422 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 426______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 428
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 Name43 # Python program to read an excel file 1Name2 # Python program to read an excel file 0# Python program to read an excel file 43Name2 # Python program to read an excel file 99
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech51_______427_______1 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech51 # Python program to read an excel file 43Name2 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 491____18_______63 7đầu ra 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
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 420_______1_______2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech00 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech63 # Python program to read an excel file 4Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 426______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 428
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 491____18_______63 7đầu ra Đặ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
Name95 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 420_______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 422 Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 426______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 428
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 # Python program to read an excel file 0# Python program to read an excel file 1Name2 # Python program to read an excel file 0# Python program to read an excel file 43Name2 69
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 # Python program to read an excel file 0# Python program to read an excel file 1Name2 # Python program to read an excel file 0 78Name2 80Name2 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 439 Name2 Name43 # Python program to read an excel file 1Name2 Name43 # Python program to read an excel file 43Name2 69
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 Name43 # Python program to read an excel file 1Name2 Name43 78Name2 80Name2 82# import openpyxl module 07Name2 # 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 439 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech43 # Python program to read an excel file 1Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech43 # Python program to read an excel file 43Name2 69
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech43 # Python program to read an excel file 1Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech43 78Name2 80Name2 82# import openpyxl module 34Name2 # 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 439 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech47_______427_______1 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech47 # Python program to read an excel file 43Name2 69
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 439 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech47_______427_______1 Name2 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech47 78Name2 80Name2 82# import openpyxl module 61Name2 # 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 491____18_______63 # Python program to read an excel file 4đầu ra 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
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
Name96
Name95 # import openpyxl module 75import # import openpyxl module 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 420______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 426______1_______2 # import openpyxl module 89
Name00 Name01 openpyxl 3# import openpyxl module 97# import openpyxl module 98Name08 import 00
Name2 import 05Name2 # Python program to read an excel file 0import 08Name2 # Python program to read an excel file 0Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40
Name2 # Python program to read an excel file 0import 16Name2 # import openpyxl module 97_______428_______7
Name2 import 24
Name2 import 32
Name2 import 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 491____10_______12 7đầu ra ví dụ 2 Python3
Name96
Name95 # import openpyxl module 75import import 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 420______1_______2 # import openpyxl module 83Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 426______1_______2 # import openpyxl module 89
Name00 Name01 openpyxl 3# import openpyxl module 97# import openpyxl module 98Name08 import 00
Name2 import 05Name2 # Python program to read an excel file 0import 08Name2 # Python program to read an excel file 0Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40
Name2 # Python program to read an excel file 0import 16Name2 # import openpyxl module 97_______428_______7
Name2 openpyxl 11
Name2 openpyxl 21
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 491____10_______12 7đầu ra 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
Thêm hình ảnhVớ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 Thí dụ Python3
Name95 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 420_______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 422
Total Rows: 6 Total Columns: 4 Value of first column Name Ankit Rahul Priya Nikhil Nisha Value of first row Ankit B.Tech CSE 426______1_______2 # import openpyxl module 89
Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 openpyxl 54Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 openpyxl 56Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech47 Name Course Ankit B.Tech Rahul M.Tech Priya MBA Nikhil B.Tech Nisha B.Tech40 openpyxl 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. |