...
/Interacting with Excel and Finishing the Program
Interacting with Excel and Finishing the Program
Interact with Excel and complete the program.
We'll cover the following...
We'll cover the following...
Learning about Openpyxl
Lastly, you need to interact with Excel via the Openpyxl library. Below is sample code for interacting with a standard Excel workbook:
import openpyxlworkbook = openpyxl.Workbook()worksheet = workbook.active # or worksheet = workbook['sheet1']# directly assign a cell a valueworksheet["A1"] = 'Start Here'# orworksheet.cell(row=1, column=1, value="Start Here")# get the value of a cellx = worksheet["A1"].value# orx = worksheet.cell(row=1, column=1).value
The functionality to assign a value to a cell by the exact cell name (A1) or by its row and column coordinates is a handy way to iterate through a list and dynamically assign the row and column with the for loop counter variables. With a double nested for loop, the outer for loop can keep track of the row number, and the inner for loop can keep track of the column number and keep ...