I really don’t know how useful this automation is, but okay..

04:07:22 still tired… Korean indie music playing in the background; this is going to be fun.


Note: I did not check to see if the file to be read / workbook already has content in the rows. To do so, I could simply add an if statement against the sheet.max_row (e.g. if max row < 0; stop there).

Hope you like it! Suggestions are welcomed.


#USAGE python blankRowInserter.py <N> <M> <excel sheet path>

import openpyxl, os, sys,logging

logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s");



if len(sys.argv) == 4:
	#TODO: extract N M and file path 
	n, m, filepath = int(sys.argv[1]),int(sys.argv[2]), sys.argv[3]
	#TODO: read file 
	try:
		wb = openpyxl.load_workbook(os.path.abspath(filepath))
		sheet = wb.get_active_sheet()
		#TODO loop M times starting at row N
		for row in range(n, n+m):
			for col in range(1, sheet.max_column+1):
				sheet.cell(row=row, column=col).value = ""
		wb.save(os.path.join(os.path.dirname(os.path.abspath(filepath)), "blankrow.xlsx"))
		wb.close()
	except Exception as err:
		logging.error("Error while opening File: " + str(err))
else:
	logging.error("USAGE python blankRowInserter.py <N> <M> <excel sheet path>")<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>