【发布时间】:2019-06-18 21:19:31
【问题描述】:
我正在尝试使用 openpyxl 工作簿写入 Excel 工作表中的特定单元格。起初我无法写入已包含数据的单元格,而现在我根本无法写入(或者我快疯了)。
这是我的代码:
wb = load_workbook("..\\..\\Decision Tree Classifier TPS\\Decision Tree Classifier TPS\\TestData.xlsx")
ws1 = wb.get_sheet_by_name("Sheet1")
#this works
print(ws1.cell(row=1, column=1).value)
#these do not
ws1['D3'] = 5
ws1.cell(row=5, column=1).value = "SomeValue2"
ws1.cell(row=7, column=1,value='Hey')
ws1.cell(row=6, column=1).value = 'TEST'
wb.save("TestData.xlsx")
我没有收到任何错误,打印行有效,写入行无效。
Writing data into Excel-Sheet using openpyxl isn't working 这里有类似的问题,除了我有保存功能。
什么给了?
【问题讨论】:
-
“不工作”是什么意思?
标签: python excel python-3.x openpyxl