您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将值写入python中pandas表中的特定单元格

将值写入python中pandas表中的特定单元格

我无法使用熊猫来完成我在问题中提出的要求,但是可以使用来解决Openpyxl

我将编写一些代码片段,以帮助实现所要求的内容

import openpyxl

srcfile = openpyxl.load_workbook('docname.xlsx',read_only=False, keep_vba= True)#to open the excel sheet and if it has macros

sheetname = srcfile.get_sheet_by_name('sheetname')#get sheetname from the file
sheetname['B2']= str('write something') #write something in B2 cell of the supplied sheet
sheetname.cell(row=1,column=1).value = "something" #write to row 1,col 1 explicitly, this type of writing is useful to write something in loops

srcfile.save('newfile.xlsm')#save it as a new file, the original file is untouched and here I am saving it as xlsm(m here denotes macros).

python 2022/1/1 18:25:02 有165人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶