Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Spreadsheet::SaveParser - how to preserve formulas during parse, evaluate during write ?

by mikeh0078 (Initiate)
on Jan 08, 2010 at 21:23 UTC ( #816400=perlquestion: print w/replies, xml ) Need Help??

mikeh0078 has asked for the wisdom of the Perl Monks concerning the following question:

I have a question about the SaveParser related to parsing the xls and formulas.

I have an xls template with 3 worksheets. The first 2 worksheets have numerous formulas that depend on cell values in the 3rd sheet.

The 3rd sheet is empty except for some column headers - I'm populating the cells with results of oracle queries. That part is working fine.

However, at the point I initially create the new SaveParser object to parse the xls template, it appears to be evaluating the formulas and converting to values at that point. Since the 3rd sheet is empty on the template, all the values in the first two sheets evaluate to zero. Subsequently changing the 3rd worksheet has no effect.

Is there any way to get SaveParser to preserve formulas while parsing the xls, then run my queries to populate the 3rd worksheet, then the formulas evaluated to values on the write with SaveAs ?

Thanks!

  • Comment on Spreadsheet::SaveParser - how to preserve formulas during parse, evaluate during write ?

Replies are listed 'Best First'.
Re: Spreadsheet::SaveParser - how to preserve formulas during parse, evaluate during write ?
by jmcnamara (Monsignor) on Jan 08, 2010 at 23:51 UTC

    I am the current maintainer of Spreadsheet::ParseExcel.

    Excel stores formulas in two parts. The first in a pre-parsed stack of RPN tokens that the Excel formula parser uses and the second is the value of the formula when it was last evaluated (generally when the workbook was saved).

    Spreadsheet::ParseExcel ignores the first part (a general deparser is a little too tricky to implement) and just reads the result part. This is usually okay for applications that read an Excel file but isn't very useful if you are trying to re-write a file since the formula is effectively lost. This is currently the case with Spreadsheet::ParseExcel::SaveParser.

    So it isn't the case that your formulas aren't being evaluated at the right time. They aren't evaluated at all.

    Currently, there isn't a workaround for this. I have some plans for solutions that might be implemented in the future but they are either non-trivial or potentially error prone and neither will happen in the short term, unfortunately.

    --
    John.

      Hi, i am using SaveParser to parse an existing spreadsheet and i am trying to add formula, its giving the following error. Please let me know the reason, because the same write_formula works fine with WriteExcel. Can't locate object method "write_formula" via package "Spreadsheet::ParseExcel::SaveParser::Worksheet" With regards, Suresh.K

        Spreadsheet::ParseExcel::SaveParser::Worksheet is not a subclass of Spreadsheet:WriteExcel::Worksheet so it doesn't have a write_formula() method.

        Spreadsheet::ParseExcel::SaveParser does return a Spreadsheet:WriteExcel object that you can use to access the write_formula() method instead.

        P.S. Please don't post new questions in reply to a thread that your question isn't related to.

        --
        John.

Re: Spreadsheet::SaveParser - how to preserve formulas during parse, evaluate during write ?
by marto (Cardinal) on Jan 08, 2010 at 21:31 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://816400]
Approved by Limbic~Region
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2020-12-05 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?