Python: save excel formula value with wps cache value

data_only==True returns None value.
Due to the complicated calculation rules of the excel formula, the third party cannot independently calculate the value generated by the formula. It needs to have cached data. Before this, it needs to be opened with excel or wps and other software before saving and there will be a cached value.
It is better to install pywin32 and call wps to report an error. It is better to install and call excel. However, it seems unbelievable that the file opened at runtime will flash in wps (interestingly, when you use wps to open any document, the program will run faster, and the document has been loading. , but it will make an error after running like this for a while)
Knowledge link:
Calling WPS in Python code
Today, I used python win32com to call Jinshan wps to report an error, and finally found a solution
. Python reads the three commonly used modules of excel, who is the fastest

import os
import openpyxl
import re
from win32com.client import Dispatch

def just_open(filename):#解决值丢失的问题
    xlApp = Dispatch("Excel.Application")#该参数据说是注册表中项但是没找到
    xlApp.Visible = False
    xlBook = xlApp.Workbooks.Open(filename)
    xlBook.Save()
    xlBook.Close()
    return xlBook
input= r'C:\Users\huang\3D Objects'
os.chdir(input)
mywb = openpyxl.Workbook()
mysheet=mywb["Sheet"]
i=1
for file in os.listdir():
    if os.path.splitext(file)[1] == '.xlsx':
        i=i+1
        xlBook = just_open(input+'\\'+file)
        wb=openpyxl.load_workbook(file,data_only=True)
        wbsheet = wb['Sheet']
        for j in range(1,5,1):
            mysheet[chr(j+64)+str(i)]=wbsheet[chr(j+64)+str(2)].value
            print(wbsheet[chr(j+64)+str(2)].value)
        wb.save(file)
mywb.save(r'C:\Users\huang\Desktop'+'\\'+'权益导入.xlsx')

Guess you like

Origin blog.csdn.net/qq_37639139/article/details/122134374