Home > other >  Openpyxl with data_only=True, after reading the value of the formula after the save, found in the fi
Openpyxl with data_only=True, after reading the value of the formula after the save, found in the fi

Time:01-01

There is now a XLSM file, I want to read in a cell's formula into the value, then use the data_only=True, then I want to make any changes to your file, the save function, open the file again, only to find that inside the cell's formula is gone, are converted to digital, could you tell me how to keep the file to the formula? To help you, thank you!

CodePudding user response:

Now I have a solution, but more troublesome, before reading the file with workbook_=load_workbook (filename, keep_vba=True, data_only=True), don't save, after reading to modify the file, after again workbook_=load_workbook (filename, keep_vba=True, data_only=False), revised and save, but doing so more troublesome, not flexible, is there a more simple method bosses?

CodePudding user response:

To attach a knowledge: (from the website: https://www.cnblogs.com/vhills/p/8327918.html)
When 'ABC. XLSX' is generated and after open and save in the Excel program (this process will be the Excel formula results calculated), the file with two sets of values, is a set of formula without computing all (data_only=False (the default), is a set of formulas to calculate the results (data_only=True), (if it is not Excel to open and save only a set of values (the set of data_only=False, formula without calculation results),
At this point, to data_only default data_only==True or False open will obtain two different results, independently, namely data_only=True condition open, will find that the formula results to None (null) or a good constant calculation, and don't see how it's original formula, while data_only=False displays only the formula, therefore, data_only=True condition open, if in the end, the save () function to save, the original XLSX file, the formula will be replaced by constant results or null values, while data_only=False condition open, finally use the save () function to save, original XLSX file will only data_only=False (formula), the set value of another set (data_only=True) value will be lost, if you want to get two sets of values, is still need to use the Excel program to open the file and save,

With openpyxl to excel in writing after the save save in the formula, reoccupy openpyxl additional data_only=True read the value of the formula, there will be None, the solution is to manually open the file before reading, save again, or use of this function, use code to open the file and then save:
The from win32com. Client import Dispatch
Def just_open (filename) :
XlApp=Dispatch (" Excel. Application ")
XlApp. Visible=False
XlBook=xlApp. Workbooks. Open (filename)
XlBook. The Save ()
XlBook. Close ()

CodePudding user response:

I also met this problem
This is to use the Microsoft Windows inside dongdong go to processing, save the excel file later there will be two sets of formulas and things,
So under the Linux?

CodePudding user response:

The
reference 3 floor cajan2 response:
I also encountered this problem
This is to use the Microsoft Windows inside dongdong go to processing, save the excel file later there will be two sets of formulas and things,
So under the Linux?

Ao that I don't know, haven't tried in a Linux environment

CodePudding user response:

The
reference 3 floor cajan2 response:
I also encountered this problem
This is to use the Microsoft Windows inside dongdong go to processing, save the excel file later there will be two sets of formulas and things,
So under the Linux?

How are you solved? linux
  • Related