January 2019
Beginner
318 pages
8h 23m
English
In this section, we will learn to create a new Excel file using openpyxl. Create a script called create_excel.py and write the following content in it:
from openpyxl import Workbookbook_obj = Workbook()excel_sheet = book_obj.activeexcel_sheet['A1'] = 'Name'excel_sheet['A2'] = 'student'excel_sheet['B1'] = 'age'excel_sheet['B2'] = '24'book_obj.save("test.xlsx")print("Excel created successfully")
Run the script and you will get the following output:
student@ubuntu:~/work$ python3 create_excel.py
Following is the output:
Excel created successfully
Now, check your current working directory and you will find that test.xlsx has been created successfully. In the preceding example, we write data into four cells. Then, from ...
Read now
Unlock full access