Skip Menu |

This queue is for tickets about the Spreadsheet-WriteExcel CPAN distribution.

Maintainer(s)' notes

If you are reporting a bug in Spreadsheet::WriteExcel here are some pointers

1) State the issues as clearly and as concisely as possible. A simple program or Excel test file (see below) will often explain the issue better than a lot of text.

2) Provide information on your system, version of perl and module versions. The following program will generate everything that is required. Put this information in your bug report.

    #!/usr/bin/perl -w

    print "\n    Perl version   : $]";
    print "\n    OS name        : $^O";
    print "\n    Module versions: (not all are required)\n";

    my @modules = qw(
                      Spreadsheet::WriteExcel
                      Parse::RecDescent
                      File::Temp
                      OLE::Storage_Lite
                      IO::Stringy
                      Spreadsheet::ParseExcel
                      Scalar::Util
                      Unicode::Map
                    );

    for my $module (@modules) {
        my $version;
        eval "require $module";

        if (not $@) {
            $version = $module->VERSION;
            $version = '(unknown)' if not defined $version;
        }
        else {
            $version = '(not installed)';
        }

        printf "%21s%-24s\t%s\n", "", $module, $version;
    }

    __END__

3) Upgrade to the latest version of Spreadsheet::WriteExcel (or at least test on a system with an upgraded version). The issue you are reporting may already have been fixed.

4) Create a small but complete example program that demonstrates your problem. The program should be as small as possible. At the same time it should be a complete program that generates an Excel file. If the Spreadsheet::WriteExcel section is part of a much larger program then simplify it down to the essentials. Simulate any DB reads with an array.

5) Say if you tested with Excel, OpenOffice, Gnumeric or something else. Say which version of that application you used.

6) If you are submitting a patch you should check with the author whether the issue has already been patched or if a fix is in the works. Patches should be accompanied by test cases.

Asking a question

If you would like to ask a more general question there is the Spreadsheet::WriteExcel Google Group.

Report information
The Basics
Id: 76997
Status: resolved
Priority: 0/
Queue: Spreadsheet-WriteExcel

People
Owner: Nobody in particular
Requestors: nanis [...] rcpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.37
Fixed in: (no value)



Subject: repeat_formula fails if stored formula refers to a 2D range and the replacement is a 3D range
This is related to the Stackoverflow question: <http://stackoverflow.com/questions/10452842/perl-excel-store-formula-and-repeat-formula/> When a formula with a 2D range is stored using store_formula as in my $formula = $sheet->store_formula('=MEDIAN(A1:A2)'); and later repeat_formula is called with a 3D range as replacement as in $sheet->repeat_formula($n, 0, $formula, undef, 'A1:A2' => 'Another!A1:10'); The sheet reference is stripped, and the formula in the Excel file becomes '=MEDIAN(A1:A10)'. After a cursory glance, my hypothesis is: The reason for this seems to have to do with the parser setup in Spreadsheet::WriteExcel::Formula. A plain range is parsed as a range2d token whereas a range with a sheet reference is parsed as a range3d token. Later, in repeat_formula, the replacement is done on tokens. From what I can gather, a range2d token looks like '_ref2dA1:A10'. So, '_ref2dA1:A2' gets transformed into '_ref2dFeb!A1:10' in repeat formula. However, when it is passed to Spreadsheet::WriteExcel::Formula::parse_tokens, the code still classifies it as a range2d token based on the prefix. I gather the final call $parse_str .= $self->_convert_ref2d($token, $class); then turns it back into '_ref2dA1:A10. I am not sure if this could be classified as a bug, but it is definitely unexpected from the user's POV. So, the solution is to put in the name of a sheet that is guaranteed to exist. A short script exhibiting the problem is attached. FWIW, I am using ActivePerl 5.14.2 on Windows XP SP3 with Excel 2003. I also would like to take this opportunity to thank you for Spreadsheet::WriteExcel. It has really helped me over the years. -- Sinan
Subject: xcl.pl
#!/usr/bin/env perl use strict; use warnings; use Spreadsheet::WriteExcel; use Const::Fast; const my @MONTHS => qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); const my $WORKBOOK => 'test.xls'; my $book = Spreadsheet::WriteExcel->new($WORKBOOK) or die "Cannot open '$WORKBOOK': $!"; my %sheets = map {$_ => $book->add_worksheet($_)} Summary => @MONTHS; for my $m (@MONTHS) { for my $n (1 .. 10) { $sheets{ $m }->write_number($n - 1, 0, $n); } } my $formula = $sheets{Summary}->store_formula('=MEDIAN(A1:A2)'); # Comment the line above and uncomment the one below to for # expected behavior. # my $formula = $sheets{Summary}->store_formula('=MEDIAN(Summary!A1:A2)'); for my $n (0 .. 1) { my $replacement = sprintf(q{'%s'!A1:A10}, $MONTHS[$n]); $sheets{Summary}->repeat_formula($n, 0, $formula, undef, 'Summary!A1:A2' => $replacement ); } $book->close or die "Error closing '$WORKBOOK': $!";
On Fri May 04 16:17:54 2012, NANIS wrote: Show quoted text
> This is related to the Stackoverflow question: > > <http://stackoverflow.com/questions/10452842/perl-excel-store-formula- > and-repeat-formula/> >
Hi Sinan, Thanks for the detailed report and the excellent answer (as always) on StackOverflow. The store/repeat formula functions were never intended for the the 2D to 3D range transformation that the OP was trying to achieve and couldn't really be made to work. These days I recommend that people use Excel::Writer::XLSX where possible. It has all the features of Spreadsheet::WriteExcel with less of the quirks and no formula oddities such as this one. Regards, John. --
Close for reasons give on rt.cpan.org. Cannot fix.