Skip to content

Instantly share code, notes, and snippets.

@ItsCalebJones
Last active November 23, 2017 00:48
Show Gist options
  • Save ItsCalebJones/1e08ded9170b7643dd2ca5c8f86eee0b to your computer and use it in GitHub Desktop.
Save ItsCalebJones/1e08ded9170b7643dd2ca5c8f86eee0b to your computer and use it in GitHub Desktop.
Python script to find empty cells.
from openpyxl import load_workbook
some_array = [1,2,3]
wb = load_workbook(filename = 'your_excel.xlsx')
ws = wb.get_sheet_by_name('Sheet Name')
for row in ws.iter_rows('C{}:C{}'.format(ws.min_row, ws.max_row)):
for cell in row:
print cell.value
## Read the printed value here - then write condition to replace with formula.
## Most likely going to want to look for None or ""
## EXAMPLE - this will find and replace all that are empty.
if cell.value is None:
cell.value = "=SUM(1, 1)"
# or
cell.value = some_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment