/openpyxl-shift

This python code works with openpyxl to add/delete rows and columns in Excel

Primary LanguagePython

Shift

A custom-built module via Openpyxl

Summary

Shift is a Python Class that works with the openpyxl library to insert and remove rows and columns in Excel.

Tools

  • Python 3 (download it here)
  • Openpyxl Library

Getting Started

  • 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.

Using the Shift methods

Excel Beginning Result

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.

Excel End Result

Author

Module written by Alex Rogers

Acknowledgements

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.