您可以提供的任何帮助将非常有帮助!
以下是我的代码.这是我得到的错误
Traceback(最近一次调用最后一次):
文件“/Path/Path/Path/extractData.py”,第50行,in
destSheet.cell(row = rowNum,column = 1).value = masterList1
文件“/library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/openpyxl/cell/cell.py”,第313行,价值
self._bind_value(值)
在_bind_value中输入文件“/library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/openpyxl/cell/cell.py”,第217行
引发ValueError(“无法将{0}转换为Excel”.format(value))
ValueError:无法转换[‘Reinsurer’,’Market 1′,’Market 2′,’Market 3′,’Market 4′,’Market 5′,’市场4′,’市场5′,[‘市场1′,’市场2′,’市场3′,’市场5’]]到Excel
import openpyxl#Open source data filesourcefile = 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 datanewList1 = []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 databasedestfile = 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 workbookmasterList1 = []masterList2 = []masterList3 = []#grab master spreadsheet data and write to Listfor 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 ListmasterList1.append(newList1)masterList2.append(newList2)masterList3.append(newList3)#write new master List to a new filefor rowNum in range(2,len(masterList1)): destSheet.cell(row=rowNum,column=1).value = masterList1destSheet.save("updatedTest.xlsx")解决方法 您可能打算使用masterList1 [rowNum]作为值,而不是将每个单元格的值分配给masterList1:
for rowNum in range(2,column=1).value = masterList1[rowNum]
另外,正如@mgrant指出的那样,你应该先扩展(不附加)主列表:
masterList1.extend(newList1)总结
以上是内存溢出为你收集整理的Python openpyxl写入列表到Excel错误全部内容,希望文章能够帮你解决Python openpyxl写入列表到Excel错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)