Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Creating Pivot tables from Perl

by narashima (Beadle)
on Nov 08, 2005 at 19:28 UTC ( #506853=perlquestion: print w/replies, xml ) Need Help??

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

Revered Monks,

I have a perl job(running on Solaris) that needs to output its results(finaincial figures) as a pivot table in a excel spreadsheet.
I tried looking up for modules that do this but could not find any. Can someone please advise me on how I can go about doing this??


Replies are listed 'Best First'.
Re: Creating Pivot tables from Perl
by marto (Cardinal) on Nov 08, 2005 at 20:11 UTC

    Not a complete Perl soultion but..
    Could you not have your pivot table in an Excel sheet**, then append the output from your Perl script to the file?

    **If you pre define a piviot table you should be able to update it when the excel file is next opened using a VBS (within the Excel file, NOT your Perl script) like:
    Sub Auto_Open() Application.OnSheetActivate = "UpdateIt" End Sub Sub UpdateIt() Dim iP As Integer Application.DisplayAlerts = False For iP = 1 To ActiveSheet.PivotTables.Count ActiveSheet.PivotTables(iP).RefreshTable Next Application.DisplayAlerts = True End Sub

    Please excuse the fact that this is not Perl code :(
    Are you currently able to write data to an Excel file? Cpan has many modules regards Excel writting.

    Hope this helps.

      Thanks Martin. This non-perl intensive solution sure works for me :)
Re: Creating Pivot tables from Perl
by Xaositect (Friar) on Nov 09, 2005 at 00:32 UTC

    Sounds like you've already got a workable answer, but for the record, I've had a lot of luck constructing feature-rich Excel files using Excel and some sample data, and then saving them as XML.

    Once you've got an Excel/XML file, it's not difficult to open in up and extrapolate the format and location of the data part of the file. Now you have a 'template' Excel document, and it's just a matter of substituting your data for the sample stuff, using whatever means you feel comfortable with. (Perl, PHP, XSLT, etc)

    It's worth pointing out that although Excel names XML files '.xml', you can name them the usual '.xls' and Excel will open them just the same.

    I make it sound straightforward, and it is, but do expect to spend some time ironing out bugs related to what formats and tags Excel expects.

    Xaositect -
      Thanks Buddy. Will sure try this out too.

      Xaositect: what you're saying is really interesting, since - I think - I have to do more or less the same thing:

      as an example: I have an Excel file with 2 tabs: 1st tab is just data 2nd tab has a few pivot tables using the data.

      => I'd like to create a Perl script that would update the data in the 1st tab, and then save the file with the pivot tables updated (then, the script would read the pivot tab and do stuff, but I can do that already).

      For now, I've tried with:
      use Spreadsheet::ParseExcel::SaveParser;
      I can update the data, but the pivot tables disappear to be replaced by "hard coded" data (I need to keep the pivot tables, so users can play with them on the dates and other stuff they need).

      Thanks for your help !

      ps: I'm under Solaris... to help things :/ So, as far as I know, I can't use Win32::OLE or VB scripts

Re: Creating Pivot tables from Perl
by duff (Parson) on Nov 08, 2005 at 22:51 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://506853]
Approved by larryp
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-12-04 21:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found