use uno (openoffice api) to open spreadsheet *without* recalculation

933 views Asked by At

I'm using pyuno to read an excel spreadsheet (running on linux.) Many cells have formulas referring to addins that are, obviously, not available. However the cell values are what I want.

But when I load and read the sheet, it seems those formulas are being evaluated and thus the values are being overwritten with errors.

I've tried several things, none of which have worked:

  • set flags AutomaticCalculation=False, MacroExecutionMode=NEVER_EXECUTE in the call to desktop.loadComponentFromURL
  • call document.enableAutomaticCalculation(False) on the loaded document

Any suggestions?

2

There are 2 answers

1
zebluk On

If formluas aren't a matter, you might circumvent the problem by processing a copy of your spreadsheet in which only the values (not the formulas) are present.

To achieve this quickly, select the whole sheet content, copy, special paste; then remove everything except "value". Save to a new file (make sure you don't overwrite the original file or every formula will be lost!). Your script should then be able to process this file.

This is an ugly solution, as there must be a way to do it programmaticaly.

3
moggi On

Calc does not yet support using the cached results after loading the document. Libreoffice Calc does now use cached results for xls documents. The results are also stored in ods but are ignored while loading the document and the formula result is evaluated by compiling and interpreting the saved formula.

There are some plans to add this for ods and xlsx too but there are many ods producers out there writting incorrect results in the file. So till now the only solution is to have a second version of the document only saving the results (or implementing it inside calc).