Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Inserting a Shape object into a worksheet will corrupt a chart object on another sheet. #52

Closed
ilenard opened this Issue Feb 25, 2013 · 3 comments

Comments

Projects
None yet
2 participants

ilenard commented Feb 25, 2013

The followong code tries to show separated objects are working fine, but inserting both into a workbook will damage the chart.The 3rd if{} generates the corrupt xlsx.

Example code:

use Excel::Writer::XLSX;
use strict;
use warnings;

if (1){
  my $workbook  = Excel::Writer::XLSX->new('Shape_OK.xlsx');
  my $worksheet = $workbook->add_worksheet('Shape'); 
  my $format = $workbook->add_format(border => 6,
          valign => 'vcenter',
          align  => 'justify',
      text_wrap  => 1,
      font => 'Arial', 
      size => 14, 
      color => 'blue');
  my $shape = $workbook->add_shape(type => 'rect', valign => 't', align => 'l', width => 480, height => 660, format => $format, text => 'Test');
  $worksheet->insert_shape( 'B2', $shape );
  $worksheet = $workbook->add_worksheet('Chart');
  my $bold      = $workbook->add_format( bold => 1 );
  my @headings =('Test series');
  my @data = (
        [ 'Category', 2, 3, 4, 5, 6, 7 ],
        [ 'Value',    1, 4, 5, 2, 1, 5 ],
  );
  $worksheet->write( 'A1', \@headings, $bold );
  $worksheet->write( 'A2', \@data );
  $workbook->close;
}
if (1){
  my $workbook  = Excel::Writer::XLSX->new('Chart_OK.xlsx');
  my $worksheet = $workbook->add_worksheet('Chart');
  my $bold      = $workbook->add_format( bold => 1 );
  my @headings =('Test series');
  my @data = (
        [ 'Category', 2, 3, 4, 5, 6, 7 ],
        [ 'Value',    1, 4, 5, 2, 1, 5 ],
  );
  $worksheet->write( 'A1', \@headings, $bold );
  $worksheet->write( 'A2', \@data );
  my $chart = $workbook->add_chart( type => 'line', embedded => 1 );


  $chart->add_series(
      name       => '=Chart!$A$1',
      categories => '=Chart!$A$2:$A$8',
      values     => '=Chart!$B$2:$B$8',
      line       => { width => 2.25},
  );    
  $chart->set_style( 10 );
  $worksheet->insert_chart( 'A3', $chart, 25, 10 );
  $worksheet = $workbook->add_worksheet('Shape');
  $workbook->close;
}
if (1){
  my $workbook  = Excel::Writer::XLSX->new('Shape_Chart_NOK.xlsx');
  my $worksheet = $workbook->add_worksheet('Shape'); 
  my $format = $workbook->add_format(border => 6,
          valign => 'vcenter',
          align  => 'justify',
      text_wrap  => 1,
      font => 'Arial', 
      size => 14, 
      color => 'blue');
  my $shape = $workbook->add_shape(type => 'rect', valign => 't', align => 'l', width => 480, height => 660, format => $format, text => 'Test');
  $worksheet->insert_shape( 'B2', $shape );
  $worksheet = $workbook->add_worksheet('Chart');
  my $bold      = $workbook->add_format( bold => 1 );
  my @headings =('Test series');
  my @data = (
        [ 'Category', 2, 3, 4, 5, 6, 7 ],
        [ 'Value',    1, 4, 5, 2, 1, 5 ],
  );
  $worksheet->write( 'A1', \@headings, $bold );
  $worksheet->write( 'A2', \@data );
  my $chart = $workbook->add_chart( type => 'line', embedded => 1 );


  $chart->add_series(
      name       => '=Chart!$A$1',
      categories => '=Chart!$A$2:$A$8',
      values     => '=Chart!$B$2:$B$8',
      line       => { width => 2.25},
  );    
  $chart->set_style( 10 );
  $worksheet->insert_chart( 'A3', $chart, 25, 10 );
  $workbook->close;
}

__END__

Version info:
Perl version   : 5.016000
OS name        : linux
Module versions: (not all are required)
                 Excel::Writer::XLSX            0.65
                 Spreadsheet::WriteExcel        (not installed)
                 Archive::Zip                   1.30
                 XML::Writer                    (not installed)
                 IO::File                       1.16
                 File::Temp                     0.22
Owner

jmcnamara commented Feb 26, 2013

Thanks for the detailed bug report.

I'll look into it.

Owner

jmcnamara commented May 30, 2013

I've pushed an initial fix for this to the master branch. If you still remember the bug you can try it out.

Regards,

John

jmcnamara added a commit that referenced this issue Jun 4, 2013

@jmcnamara jmcnamara closed this Jun 4, 2013

ilenard commented Jun 12, 2013

Thanks for the fix! Works like a charm. BR,Istvan
John McNamara notifications@github.com írta:

I've pushed an initial fix for this to the master branch. If you still remember the bug you can try it out.
Regards,
John

Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment