I am new to Python and working on my first project. I am trying to get my code to copy columns of data from one spreadsheet and append it to data that currently exists in a master sheet. I am able to capture the data in each of the sheets and create a new master list which combines both data sets, but I am having trouble writing it to a file. When I test print the combined lists they appear correct, but when I add the code to write the lists to a file it gets hung up.
Any assistance you can provide will be extremely helpful!
Below is my code. Here's the error I'm getting
Traceback (most recent call last): File "/Path/Path/Path/extractData.py", line 50, in destSheet.cell(row=rowNum, column=1).value = masterList1
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/openpyxl/cell/cell.py", line 313, in value self._bind_value(value)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/openpyxl/cell/cell.py", line 217, in _bind_value raise ValueError("Cannot convert {0} to Excel".format(value))
ValueError: Cannot convert ['Reinsurer', 'Market 1', 'Market 2', 'Market 3', 'Market 4', 'Market 5', 'Market 1', 'Market 2', 'Market 3', 'Market 4', 'Market 5', ['Market 1', 'Market 2', 'Market 3', 'Market 4', 'Market 5']] to Excel
import openpyxl
#Open source data file
sourceFile = openpyxl.load_workbook('/Path/Path/Path/testAuth.xlsx')
sourceSheet = sourceFile.get_sheet_by_name('Sheet1')
#read data from source file and create lists of new data
newList1 = []
newList2 = []
newList3 = []
for row in range(2, sourceSheet.get_highest_row()):
data1 = sourceSheet['A' + str(row)].value
newList1.append(data1)
data2 = sourceSheet['B' + str(row)].value
newList2.append(data2)
data3 = sourceSheet['C' + str(row)].value
newList3.append(data3)
#open destination workbook that includes the master database
destFile = openpyxl.load_workbook('/Path/Path/Path/testHist.xlsx')
destSheet = destFile.get_sheet_by_name('Sheet1')
#create empty lists for copying the historical data already in the workbook
masterList1 = []
masterList2 = []
masterList3 = []
#grab master spreadsheet data and write to list
for row in range(1, destSheet.get_highest_row()+1):
masterData1 = destSheet['A'+ str(row)].value
masterList1.append(masterData1)
masterData2 = destSheet['B'+ str(row)].value
masterList2.append(masterData2)
masterData3 = destSheet['C'+ str(row)].value
masterList3.append(masterData3)
#append new data to the history list
masterList1.append(newList1)
masterList2.append(newList2)
masterList3.append(newList3)
#write new master list to a new file
for rowNum in range(2, len(masterList1)):
destSheet.cell(row=rowNum, column=1).value = masterList1
destSheet.save("updatedTest.xlsx")