Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
WARNING: Spreadsheet::WriteExcel and Office Service Pack 3
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
jmcnamara  
View profile  
 More options May 22 2008, 4:59 am
From: jmcnamara <jmcnam...@cpan.org>
Date: Thu, 22 May 2008 01:59:15 -0700 (PDT)
Local: Thurs, May 22 2008 4:59 am
Subject: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3

Q: Why do I get the following error when I open my
Spreadsheet::WriteExcel files in Excel with Office Service Pack 3:

    "File Error: data may have been lost".

A: Office Service Pack 3 changes the default behaviour of Excel when
dealing with multiple data in a cell.

Discussion
==========

After SP3 if Excel encounters multiple data in a cell it will issue a
warning when the file is opened and it will display the first data
that was written. Prior to SP3 it didn't issue a warning and displayed
the last data written.

Consider the following program where two strings are written to cell
A1:

    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    my $workbook  = Spreadsheet::WriteExcel->new('error.xls');
    my $worksheet = $workbook->add_worksheet();

    $worksheet->write('A1', 'Hello'  );
    $worksheet->write('A1', 'Goodbye');

    __END__

If you open the output file in Excel SP3 you will get the following
error warning and the string 'Hello' will be displayed in cell A1:

    "File Error: data may have been lost".

Workaround 1
===========

The main workaround for this issue is not to write duplicate data to
cells. This may seem a little restrictive but there isn't any valid
reason to write duplicate data to a cell and clearly Excel doesn't
want you to do it.

Workaround 2
===========

As an alternative workaround you can use Spreadsheet::WriteExcel's
compatibility_mode() which generates an Excel file with greater
fidelity at the cost of an additional speed and memory overhead. A
side effect of this is that duplicate cell data is removed
automatically.

    #!/usr/bin/perl -w

    use strict;
    use Spreadsheet::WriteExcel;

    my $workbook  = Spreadsheet::WriteExcel->new('no_error.xls');
       $workbook->compatibility_mode();

    my $worksheet = $workbook->add_worksheet();

    $worksheet->write('A1', 'Hello'  );
    $worksheet->write('A1', 'Goodbye');

    __END__

If you open the output file in Excel SP3 you will not get a warning
and the string 'Goodbye' will be displayed in cell A1.

Please, read the documentation on compatibility_mode() before you use
this feature:

http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel/lib/Spreadsh...()

John.
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jmcnamara  
View profile  
 More options May 22 2008, 10:16 am
From: jmcnamara <jmcnam...@cpan.org>
Date: Thu, 22 May 2008 07:16:39 -0700 (PDT)
Local: Thurs, May 22 2008 10:16 am
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3
Here is a simple utility program to help locate duplicate cell data in
a Spreadsheet::WriteExcel file.

#!/usr/bin/perl -w

########################################################################### ##
#
# find_duplicate_cells.pl.
#
# Simple Perl utility to find cells with duplicate data in an Excel
file.
#
# reverse('©'), May 2008, John McNamara, jmcnam...@cpan.org
#

use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::WriteExcel::Utility 'xl_rowcol_to_cell';

my %cell_data;
my $duplicate_found;

main();

########################################################################### ##
#
# Parse and Excel file and look for duplicates cell data.
#
sub main {

    # Check for an input file and print a simple usage.
    my $file_name = $ARGV[0];

    if ( !$file_name ) {
        die "Usage: perl $0 file.xls\n";
    }

    # Create the ParseExcel parser with a different cell handler.
    my $parse_excel = Spreadsheet::ParseExcel->new(
        CellHandler => \&cell_handler,
        NotSetCell  => 1
    );

    # Parse the Excel file.
    my $workbook = $parse_excel->Parse($file_name);

    # Print a message if the file didn't contain duplicates.
    print "No duplicates cells found.\n" if !$duplicate_found;

}

########################################################################### ##
#
# Callback function to replace ParseExcel's default cell handler.
#
sub cell_handler {

    my $workbook    = $_[0];
    my $sheet_index = $_[1];
    my $row         = $_[2];
    my $col         = $_[3];
    my $cell        = $_[4];

    # Convert the row and col to A1 notation.
    my $cell_index = xl_rowcol_to_cell( $row, $col );

    # Get the worksheet name.
    my $sheet_name = $workbook->{Worksheet}->[$sheet_index]->{Name};

    # Check if data already exists for this cell.
    if (   exists $cell_data{$sheet_name}->{$row}
        && exists $cell_data{$sheet_name}->{$row}->{$col} )
    {

        # Print a header. Once only.
        print "Duplicates cells found:\n" if !$duplicate_found++;

        # Check which data has been overwritten.
        my $existing_data = $cell_data{$sheet_name}->{$row}->{$col};

        # Let the user know which cell data is duplicated.
        printf "'%s'!%s = %s\n", $sheet_name, $cell_index,
$existing_data;
        printf "'%s'!%s = %s\n", $sheet_name, $cell_index, $cell-

>Value();

    }
    else {
        # Keep track of cells that have already been seen.
        $cell_data{$sheet_name}->{$row}->{$col} = $cell->Value();

    }

}

__END__

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Hamel  
View profile  
 More options Jun 2 2008, 12:47 pm
From: Chris Hamel <hame...@hotmail.com>
Date: Mon, 2 Jun 2008 09:47:01 -0700 (PDT)
Local: Mon, Jun 2 2008 12:47 pm
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3
Great explanation...  I had no idea why we encountered these errors on
some spreadsheets but not others.

For what it's worth, whenever I switch from WriteExcel to
WriteExcel::Big, the problem appears to go away.  It doesn't appear to
have any performance impact that I'm aware of.

Thanks,
Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jmcnamara  
View profile  
 More options Jun 2 2008, 7:45 pm
From: jmcnamara <jmcnam...@cpan.org>
Date: Mon, 2 Jun 2008 16:45:53 -0700 (PDT)
Local: Mon, Jun 2 2008 7:45 pm
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3

On Jun 2, 5:47 pm, Chris Hamel <hame...@hotmail.com> wrote:

> For what it's worth, whenever I switch from WriteExcel to
> WriteExcel::Big, the problem appears to go away.

Hi Chris,

That's very interesting. I hadn't noticed that. That gives me a clue
in the direction of fixing that warning.

Thanks.

John.
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jmcnamara  
View profile  
 More options Jun 2 2008, 8:33 pm
From: jmcnamara <jmcnam...@cpan.org>
Date: Mon, 2 Jun 2008 17:33:14 -0700 (PDT)
Local: Mon, Jun 2 2008 8:33 pm
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3
On Jun 2, 5:47 pm, Chris Hamel <hame...@hotmail.com> wrote:

> For what it's worth, whenever I switch from WriteExcel to
> WriteExcel::Big, the problem appears to go away.

Hi Chris,

Unfortunately, that is due to an error on my part. Compatibility mode
is (erroneously) on by default in ::Big. Therefore, you are actually
getting the second workaround that I referred to above.

Still, your observation helped me track down a bug of sorts. :-)

John.
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chrisy  
View profile  
 More options Jun 19 2008, 9:09 am
From: Chrisy <chr...@flirble.org>
Date: Thu, 19 Jun 2008 06:09:46 -0700 (PDT)
Local: Thurs, Jun 19 2008 9:09 am
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3

On May 22, 4:59 am, jmcnamara <jmcnam...@cpan.org> wrote:

> The main workaround for this issue is not to write duplicate data to
> cells

What if my intention is to overwrite/replace a value that has already
been written? I don't want a duplicate.

This is exactly what happened to me recently, though quite
inadvertently. I've since fixed it, but a mechanism to overwrite, or
delete, the contents of a cell seems to be lacking.

Chris.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jmcnamara  
View profile  
 More options Jun 21 2008, 2:24 pm
From: jmcnamara <jmcnam...@cpan.org>
Date: Sat, 21 Jun 2008 11:24:56 -0700 (PDT)
Local: Sat, Jun 21 2008 2:24 pm
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3

On Jun 19, 2:09 pm, Chrisy <chr...@flirble.org> wrote:

> On May 22, 4:59 am, jmcnamara <jmcnam...@cpan.org> wrote:

> > The main workaround for this issue is not to write duplicate data to
> > cells

> What if my intention is to overwrite/replace a value that has already
> been written? I don't want a duplicate.

> This is exactly what happened to me recently, though quite
> inadvertently. I've since fixed it, but a mechanism to overwrite, or
> delete, the contents of a cell seems to be lacking.

Hi Chris,

Spreadsheet::WriteExcel takes the approach of writing data to a file
as soon as possible. While this limits the user's ability to
manipulate the data afterwards it has significant advantages in that
it reduces the memory requirement and speeds up the overall creation
of an Excel file.

In addition Perl provides a variety of tools to overwrite, replace and
delete data such as hashes, tied hashes or database interfaces. So
these types of problems are best solved in the Perl domain and not in
Spreadsheet::WriteExcel.

Having said that, the compatibility_mode() option detailed above
actually gives you the overwrite/replace option and at some later
stage it might also be possible to delete data. However, that
flexibility comes with a performance cost which for very large files
can be significant.

John.
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ali_pedhi  
View profile  
 More options Jun 24 2008, 9:39 am
From: ali_pedhi <aliasgar.pedhiw...@gmail.com>
Date: Tue, 24 Jun 2008 06:39:32 -0700 (PDT)
Local: Tues, Jun 24 2008 9:39 am
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3
hey,
I am trying to overwrite some data in some cells in an existing
spreadsheet.
am able to make a copy of the sheet using SaveAs() n stuff...
at first I could not write into any cell which had some data & would
get a 'File Error- Data may be lost' on opening the sheet.
on trying to include 'compatibility_mode()' I get a message saying
'Cant Locate object compatibility_mode() via package
Spreadsheet::WriteExcel'
I am using perl 5.8.8.

any idea/help will be appreciated...

ali

On Jun 21, 2:24 pm, jmcnamara <jmcnam...@cpan.org> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jmcnamara  
View profile  
 More options Jun 24 2008, 11:33 am
From: jmcnamara <jmcnam...@cpan.org>
Date: Tue, 24 Jun 2008 08:33:25 -0700 (PDT)
Local: Tues, Jun 24 2008 11:33 am
Subject: Re: WARNING: Spreadsheet::WriteExcel and Office Service Pack 3

On Jun 24, 2:39 pm, ali_pedhi <aliasgar.pedhiw...@gmail.com> wrote:

> on trying to include 'compatibility_mode()' I get a message saying
> 'Cant Locate object compatibility_mode() via package
> Spreadsheet::WriteExcel'
> I am using perl 5.8.8.

Hi,

Compatibility mode is only supported in the latest version, 2.21, of
Spreadsheet::WriteExcel.

The error message above means that you don't have that version
installed.

John.
--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »