A custom-built module via Openpyxl
Shift is a Python Class that works with the openpyxl library to insert and remove rows and columns in Excel.
- Python 3 (download it here)
- Openpyxl Library
-
Users will first have to import the openpyxl library on their system using pip. You can install in the terminal by inputting
pip install openpyxl
. Alternative installations are available here -
Once openpyxl is installed, you can download the Shift module manually, or input
git clone git@github.com:alexrogers823/openpyxl-shift.git
into the desired folder on your terminal.
When using class Shift in your program, you need your workbook and the specific row or column that you want to apply.
Example 1: Inserting
import openpyxl
from Shift.shift import Shift
workbook = openpyxl.load_workbook("Hello_World.xlsx")
worksheet = workbook["Python"]
# Insert row at row 9 of worksheet
row_nine = Shift(worksheet, 9)
row_nine.insert_row()
Example 2: Removing
import openpyxl
from Shift.shift import Shift
workbook = openpyxl.load_workbook("Hello_World.xlsx")
worksheet = workbook[Python]
# Delete column at column E (5th column) of worksheet
column_E = Shift(worksheet, 5)
column_E.remove_column()
Once your program saves and opens excel, you will see the changes reflected.
Module written by Alex Rogers
Special thanks to Al Sweigart, author of Automate the Boring Stuff with Python. The chapter on openpyxl is what inspired me to write this module.