Excel, a component of the Microsoft Office pack, is one of the popular formats in which data is stored and visualized. Since 2010, Office has supported the .xlsx
format. We can read XLSX files using the OpenPyXl and pandas functions.
OpenPyXl is a Python library for reading and writing Excel files. It is an open source project. A new workbook
is created using the following command:
wb = Workbook()
We can access the currently active
sheet by using the following command:
ws = wb.active()
To change the sheet name, use the title
command:
ws.title = "Demo Name"
A single row can be added to the sheet using the append
method:
ws.append()
A new sheet can be created using the create_sheet()
method. An individual cell in the active sheet can be created using the column
and row
values:
# Assigns the cell corresponding to # column A and row 10 a value of 5 ws.['A10'] = 5 #or ws.cell(column=1, row=10, value=5)
A workbook can be saved using the save
method. To load an...