Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Spreadsheet::WriteExcel - using formats with multiple books (Fixed)

by MeowChow (Vicar)
on Dec 07, 2000 at 00:24 UTC ( [id://45306]=note: print w/replies, xml ) Need Help??


in reply to Spreadsheet::WriteExcel - using formats with multiple books

After toying around with the code for this module for a bit, I've fixed the problem, hopefully without introducing any new bugs (my understanding of the module is not very complete). This bug is caused by the "class data" at the beginning of Format.pm and Worksheet.pm. The data is actually per-workbook data, but the author of the module mistakenly stored it into class variables, thus applying it to the set of all worksheets and formats. I've made this mistake so many times myself, it was quite easy to recognize :) Anyway, I've whipped up a quick patch to get things working. One caveat with the patch though, is that you have to explicitly close() your workbooks, because the order in which objects get DESTROY'd is random.
diff -r c:\perl\site\lib\Spreadsheet/Format.pm C:\Perl\CPAN\Spreadshee +t-WriteExcel-0.22/Format.pm 32,33c32,33 < # my $xf_index = 15; < # my $font_index = 4; --- > my $xf_index = 15; > my $font_index = 4; 47,49c47 < _workbook => $_[1], < _xf_index => $_[1]->{_xf_index}, #MEOW < _font_index => $_[1]->{_font_index}, #MEOW --- > _xf_index => $xf_index, 50a49 > _font_index => $font_index, 89,90c88,89 < $self->{_workbook}{_xf_index}++; < $self->{_workbook}{_font_index}++; --- > $xf_index++; > $font_index++; diff -r c:\perl\site\lib\Spreadsheet/Workbook.pm C:\Perl\CPAN\Spreadsh +eet-WriteExcel-0.22/Workbook.pm 38,39d37 < bless $self, $class; < 49,52c47,48 < $self->{_xf_index} = 15; < $self->{_font_index} = 4; < $self->{_tmp_worksheet} = Spreadsheet::Worksheet->new('', 0, 0, + $self); < $self->{_tmp_format} = Spreadsheet::Format->new($self); --- > $self->{_tmp_worksheet} = Spreadsheet::Worksheet->new('', 0, 0) +; > $self->{_tmp_format} = Spreadsheet::Format->new(); 55a52 > bless $self, $class; 133d129 < $self, #MEOW 152c148 < my $format = Spreadsheet::Format->new($self); --- > my $format = Spreadsheet::Format->new(); diff -r c:\perl\site\lib\Spreadsheet/Worksheet.pm C:\Perl\CPAN\Spreads +heet-WriteExcel-0.22/Worksheet.pm 32,33c32,33 < #MEOW my $active_sheet = 0; < #MEOW my $first_sheet = 0; --- > my $active_sheet = 0; > my $first_sheet = 0; 53d52 < $self->{_workbook} = $_[3]; #MEOW 200c199 < $self->{_workbook}{_active_sheet} = $self->{_index}; #MEOW --- > $active_sheet = $self->{_index}; 212,214c211 < my $self = shift; #MEOW < < $self->{_workbook}{_active_sheet}; #MEOW --- > return $active_sheet; 229c226 < $self->{_workbook}{_first_sheet} = $self->{_index}; #MEOW --- > $first_sheet = $self->{_index}; 241,243c238 < my $self = shift; < < $self->{_workbook}{_first_sheet}; #MEOW --- > return $first_sheet; 341c336 < if ($self->{_workbook}{_active_sheet} == $self->{_index}) { --- > if ($active_sheet == $self->{_index}) {

Replies are listed 'Best First'.
Re: Re: Spreadsheet::WriteExcel - using formats with multiple books (Fixed)
by jmcnamara (Monsignor) on Dec 07, 2000 at 06:16 UTC

    I put a comment in the code that said "# Class Data". perl mustn't have read it. ;-)

    I patched this bug a few days ago but I haven't uploaded it because I was busy adding other bugs. s/bugs/features/.

    I hope to upload a new version of Spreadsheet::WriteExcel this weekend. The main addition will be customisable numerical formats. The problem with close() and DESTROY is explained in more detail in the updated documentation.

    John.
    --

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45306]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-24 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found