import openpyxl def main(): numberOfNewAttributes = int(raw_input("How many new attributes are there? -> ")) newAttributes = [] for i in range(numberOfNewAttributes): newAttributes.append(raw_input("What is one of the new attributes? -> ")) try: wb = openpyxl.load_workbook('survey_results.xlsx') except IOError: print "The survey_results.xlsx file does not exist yet. This tool should only be used when upgrading an existing file" raise SystemExit ws = wb.worksheets[0] startOn = ws.max_column - 3 oldData = [[0 for i in range(4)] for j in range(ws.max_row)] for i in range(startOn, ws.max_column + 1): for j in range(1, ws.max_row + 1): oldData[j - 1][i - startOn] = ws.cell(row = j, column = i).value for i in range(startOn, startOn + numberOfNewAttributes): ws.cell(row = 1, column = startOn+i-startOn).value = newAttributes[i - startOn] for i in range(startOn, startOn + numberOfNewAttributes): for j in range(2, ws.max_row + 2): ws.cell(row = j, column = i).value = "" for i in range(startOn + numberOfNewAttributes, startOn + numberOfNewAttributes + 4): for j in range(1, ws.max_row - 2): print "i -> " + str(i - (startOn + numberOfNewAttributes)) print "j -> " + str(j - 1) ws.cell(row = j, column = i).value = oldData[j - 1][i - (startOn + numberOfNewAttributes)] wb.save("survey_results1.xlsx") if __name__ == "__main__": main()