后来发现:其实并不是莫名丢失,而是里面包含excel函数,比如
=LEFT("1981-12-03",19)
这样的,所以,把LEFT内部数据用re解析一编再设置到表格里输出就好了。
LEFT_FORMULA = r"^=LEFT\s*[(]\s*\"(.+)\"\s*,\s*(\d+)\s*[)]$"
def parsingFormulas(wb):
sheetnames = wb.sheetnames
for sheet_name in sheetnames:
sheet = wb[sheet_name]
rowc = sheet.max_row
colc = sheet.max_column
for rowi in range(rowc):
for coli in range(colc): # 这里的code是字典的key
# val = sheet.cell(row=rowi+1, column=coli+1).value
val = sheet.cell(row=rowi+1, column=coli+1).value
if type(val)==str and re.match(LEFT_FORMULA, val):
vals = re.match(LEFT_FORMULA, val).groups()
sheet.cell(row=rowi+1, column=coli+1).value = vals[0][0:int(vals[1])]