-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Extending Excel with Python and R
By :

In this section, we will look at the openpyxl
package, which allows for a more nuanced interaction with Excel when writing data.
To start working with Excel sheets in Python, we need to create a new workbook. openpyxl
provides an intuitive API to create, modify, and save Excel workbooks. Here’s an example code snippet that demonstrates creating a new workbook:
import openpyxl # Create a new workbook workbook = openpyxl.Workbook()
Once again, the preceding code snippet doesn’t return anything but it does have a side effect – it creates the workbook:
Figure 2.4 – Creating a workbook with openpyxl
Once we have a workbook, we can add sheets to it. Adding sheets allows us to organize data into separate sections or categories. openpyxl
provides a simple method, create_sheet()
, to add sheets to a workbook. Let...