punchcard_bob has asked for the wisdom of the Perl Monks concerning the following question:

Brethren,

I'm using Spreadsheet::WriteExcel to convert plain text files of tabular data into Excel files and delivering them to the user's browser to either save to disk or open in Excel. It works perfectly for most users. (This really is an excellent module)

BUT, a small number of users report that the resulting file opens in Excel, but after just a few seconds Excel produces a "page fault" or an "access violation" and crashes. The one thing common to such users is Excel 97. Also, when a user with Excel 2000 opens such a file it works fine, and if they save it and then pass it to an Excel 97 user, the file opens alright but the column headings (which are in combined cells) are missing.

I read in John McNamara's article of Fall 2000 in The Perl Journal, that this was a problem in the original release of Spreadsheet::WriteExcel, but that it had been fixed. Having obtained and installed Spreadsheet::WriteExcel just a few months ago, I assume it was the latest version.

Might anyone have experience with such a thing? Mr. McNamara, are you out there?

  • Comment on Spreadsheet::WriteExcel crashing Excel97

Replies are listed 'Best First'.
Re: Spreadsheet::WriteExcel crashing Excel97
by jmcnamara (Monsignor) on Aug 26, 2002 at 07:58 UTC

    There is a only one Excel crashing problem that I'm aware of. This occurs when you use the merge_cells() method without specifying a format for the entire range of cells. This only affects Excel97 and not Excel2000.

    The solution is to ensure that you write a formatted blank to other cells in the merged range as follow:

    #!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new('test.xls'); my $worksheet = $workbook->addworksheet(); $worksheet->set_row($_, 30) for (1..11); $worksheet->set_column('B:D', 20); my $format = $workbook->addformat( border => 6, bold => 1, color => 'red', valign => 'vcenter', align => 'center', ); $worksheet->write('B2', 'Some text here', $format); $worksheet->write_blank('C2', $format); $worksheet->write_blank('D2', $format); $worksheet->write_blank('B3', $format); $worksheet->write_blank('C3', $format); $worksheet->write_blank('D3', $format); $worksheet->merge_cells('B2:D3');

    If this doesn't fix your problem then send me an email.

    --
    John.

      John,

      That certainly sounds like a strong possibility in our situation. I will have the code reviewed for systematic formatting for the entire range of merged cells.

      Thanks for your help. In case it's of any use to you, I'll let you know at your email what we find.

      Bob