我想在Python中现有Excel文件的单个单元格中编辑或插入特定值。我的主要问题是,原始Excel包含一些选择选项单元格、图像和另一张工作表,当我保存新文件时,这些单元格、图像和工作表将消失(只有一个更改的值)。我正在使用openpyxl库,但我不知道它是否最适合这个方案。我把代码留在这里:
import openpyxl
wbkName = "path_to_xlsx_file"
wbk = openpyxl.load_workbook(wbkName)
# Sheet1 is what the sheet is called where is the cell that I want to change
sheet = wbk['Sheet1']
# 54, 6 are the row number and col number of the cell I want to change (insert a 5 in this case)
sheet.cell(54,6).value = 5
wbk.save(wbkName)
wbk.close
目前没有回答
相关问题 更多 >
编程相关推荐