|more useful options|
Formats and Spreadsheet::WriteExcelby nop (Hermit)
|on Dec 01, 2000 at 20:22 UTC||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.
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! )