in reply to Perl Excel Formulas With Worksheet Links

I am using
use Spreadsheet::ParseExcel; use Spreadsheet::WriteExcel;
Yes, there is a sheet named Sales in one of the formulas. From what I have read, this should be possible.

Yes, their are two sheets. One named "How_Am_I_Doing" and the other "Sales".
There are numerous other cells, that have other formulas, for instance on sheet Sales there is one '=D3*E2, which calculates just fine. But all the cells with worksheet links cause errors, by removing those cells from the spreadsheet, everything writes fine. Here is some more of the code:
foreach my $sheet (keys %$storage_book){ my $dest_sheet = $dest_book->addworksheet($sheet); foreach my $row (keys %{$storage_book->{$sheet}}){ foreach my $col (keys %{$storage_book->{$sheet}->{$row}}){ if ($sheet eq "Sales") { if ($storage_book->{$sheet}->{$row}->{$col} eq 'Agent') { $getsales=1; #next row start getting sales } elsif ($storage_book->{$sheet}->{$row}->{$col} eq 'Total') { $getsales=0; #stop getting sales } #GET THE AGENTS NAME if (($getsales ==1) && ($col == 0)) { #performs a sql query here } } if (($getsales == 1) && ($col == 4) && ($sheet eq "Sales") && ($ +agentname eq "Agent")) { $dest_sheet->write($row, $col, $exchange_rate); } elsif (($getsales == 1) && ($col == 2) && ($sheet eq "Sales")) { if ($agentname eq "Agent") { $dest_sheet->write($row, $col, $storage_book->{$sheet}->{$ro +w}->{$col}); } else { $dest_sheet->write($row, $col, $cdnsales); } } elsif (($getsales == 1) && ($col == 3) && ($sheet eq "Sales")) { if ($agentname eq "Agent") { $dest_sheet->write($row, $col, $storage_book->{$sheet}->{$ro +w}->{$col}); } else { $dest_sheet->write($row, $col, $usdsales); } } else { if (($row == 0) && ($col == 1) && ($sheet eq "Sales")) { $dest_sheet->write($row, $col, $startdate); } elsif (($row == 0) && ($col == 3) && ($sheet eq "Sales")) { $dest_sheet->write($row, $col, $today); } else { ###HERE IS LINE 265 $dest_sheet->write($row, $col, $storage_book->{$sheet}->{$ro +w}->{$col}); } } } # foreach column } # foreach row } # foreach sheet $dest_book->close();

Replies are listed 'Best First'.
Re: Re: Perl Excel Formulas With Worksheet Links
by jmcnamara (Monsignor) on Feb 13, 2003 at 00:03 UTC

    It looks like my guess on the other node was wrong. :-)

    However, the solution is the same, iterate through the worksheets twice. The first time add the worksheets and the second time write the data:

    foreach my $sheet (keys %$storage_book){ $dest_book->addworksheet($sheet); } my $index = 0; foreach my $sheet (keys %$storage_book){ my $dest_sheet = ($dest_book->sheets())[$index++]; ...

    --
    John.

      Absolutely excellent. This did it, and now I understand these Excel modules a bit more. Thank you for your wonderful and timely response. Perlmonks will definitely be my new forum.