Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Formats and Spreadsheet::WriteExcel

by nop (Hermit)
on Dec 01, 2000 at 20:22 UTC ( #44390=perlquestion: print w/replies, xml ) Need Help??
nop has asked for the wisdom of the Perl Monks concerning the following question:

I have an app that writes many reports to different Excel books using Spreadsheet::WriteExcel. I'd like to define formats in one place and have them apply across all sheets (sort of like a CSS)... eg I'd have formats named bigmoney (dollar sign, commas, no pennies), money (dollar signs, commas, pennies),  percent (percent sign, two digits after decimal) etc which would apply to all sheets... then, if I wanted to change how to percentages to one digit after the decimal, I'd make one change in only one spot.

I pass data to my subclassed sheet object as arrays, implementing a Pascalesque write (fill next cells rightward) and writeln (fill next cells rightward, then go to 1st col in next row) approach... as it is easier for me to think of writing a report row by row, column by column, like a textfile, rather than hopping all around the sheet when filling it.

If an array element is a regular number, the subclass spits it into the next cell in the sheet; if it is a array ref, the 1st elem is the number and the second elem should describe the number's format.
## illustrative code, untested $mysheet->writeln('firsttab', "Here are some data"); $mysheet->writeln('firsttab', qw(1 2 3 4 A B)); # or this foreach (qw(1 2 3 4 A B)) { $mysheet->writeln('firsttab', $_); } $mysheet->writeln('firsttab'); # and with formats $mysheet->writeln('tab2', 10, 15, [.00156, 'percent'], 20); # passing + type=percent as a string looks wrong, I wish I could pass a format o +bject here!!!!
It appears in Spreadsheet::WriteExcel that a format object is bound to a certain workbook, and Very Ugly Excel Errors (whacked sheets) arise if one uses a format from Book1 on Book2.

As the comment in the code notes, passing type=percent as a string looks wrong, I wish I could pass a format object itself here. But that would have formats crossing books, which yields the Very Ugly Errors.

Any ideas to work around this? I subclass WriteExcel anyway, so my wrapper class could hold matching formats for every instance, but that seems ugly...

Suggestions? Am I make any sense here? (Long post, whew! )

nop

Replies are listed 'Best First'.
Re: Formats and Spreadsheet::WriteExcel
by nop (Hermit) on Dec 02, 2000 at 00:11 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://44390]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2018-07-21 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (449 votes). Check out past polls.

    Notices?