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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.