如何使用pyxl或excel的pyxl文件更新现有的pyxl表

2024-09-24 22:28:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python来更新用于跟踪每周趋势/指标的xlsx电子表格。这个特殊的xlsx文件有4张表在“第一张”上,我有52张表,一年中每周一张。每个表都命名为“table1-table52”,我想在工作表中搜索当前周的相应表,只更新该表。我使用了下面的代码来写入一个文件,但是它去掉了我为自动填充其他工作表而设置的所有现有格式和公式。它也不会写入现有的文件,它的输出是一个全新的文件。在

因此,在一个螺母外壳中,我想打开test1.xlsx读取表1找到表3并更新(RR、OVP、CVP、TVC和PP)或哪一个更容易。我肯定我错过了一些简单的东西。在

我已经附上了xlsx文件和python code的图片。我看过numpy、openpyxl、pandas和xlsxwriter。我愿意使用这些模块中的任何一个

test1.xlsx

#How to update an existing row or table of an existing file using pyexcel for python
import pyexcel as pe
import pyexcel.ext.xls

RR1 ="Null"
OVC1 =1
CVC1 =1
TVC1 =1
PP1 =1

sheet = pe.get_sheet(file_name="test1.xlsx") # Original file.
sheet.row[3] = [RR1 , OVC1 , CVC1 , TVC1 , PP1] # Parameters I wish to use to update original file.
sheet.save_as("test.xlsx") # This is a different file
print pe.get_sheet(file_name="test.xlsx")

Tags: 文件toimportanasupdatepyexcelxlsx