Excel-Writer-XLSX

 view release on metacpan or  search on metacpan

lib/Excel/Writer/XLSX/Worksheet.pm  view on Meta::CPAN

    my (
        $row,     $col,     $chart,  $x_offset,    $y_offset,
        $x_scale, $y_scale, $anchor, $description, $decorative
    ) = @{ $self->{_charts}->[$index] };

    $chart->{_id} = $chart_id - 1;

    # Use user specified dimensions, if any.
    my $width  = $chart->{_width}  if $chart->{_width};
    my $height = $chart->{_height} if $chart->{_height};

    $width  = int( 0.5 + ( $width  * $x_scale ) );
    $height = int( 0.5 + ( $height * $y_scale ) );

    my @dimensions =
      $self->_position_object_emus( $col, $row, $x_offset, $y_offset, $width,
        $height, $anchor);

    # Set the chart name for the embedded object if it has been specified.
    my $name = $chart->{_chart_name};

    # Create a Drawing object to use with worksheet unless one already exists.
    if ( !$self->{_drawing} ) {

        $drawing              = Excel::Writer::XLSX::Drawing->new();
        $drawing->{_embedded} = 1;
        $self->{_drawing}     = $drawing;

        push @{ $self->{_external_drawing_links} },
          [ '/drawing', '../drawings/drawing' . $drawing_id . '.xml' ];
    }
    else {
        $drawing = $self->{_drawing};
    }

    my $drawing_object = $drawing->_add_drawing_object();

    $drawing_object->{_type}          = $drawing_type;
    $drawing_object->{_dimensions}    = \@dimensions;
    $drawing_object->{_width}         = 0;
    $drawing_object->{_height}        = 0;
    $drawing_object->{_name}          = $name;
    $drawing_object->{_shape}         = undef;
    $drawing_object->{_anchor}        = $anchor;
    $drawing_object->{_rel_index}     = $self->_get_drawing_rel_index();
    $drawing_object->{_url_rel_index} = 0;
    $drawing_object->{_tip}           = undef;
    $drawing_object->{_description}   = $description;
    $drawing_object->{_decorative}    = $decorative;

    push @{ $self->{_drawing_links} },
      [ '/chart', '../charts/chart' . $chart_id . '.xml' ];
}


###############################################################################
#
# _get_range_data
#
# Returns a range of data from the worksheet _table to be used in chart
# cached data. Strings are returned as SST ids and decoded in the workbook.
# Return undefs for data that doesn't exist since Excel can chart series
# with data missing.
#
sub _get_range_data {

    my $self = shift;

    return () if $self->{_optimization};

    my @data;
    my ( $row_start, $col_start, $row_end, $col_end ) = @_;

    # TODO. Check for worksheet limits.

    # Iterate through the table data.
    for my $row_num ( $row_start .. $row_end ) {

        # Store undef if row doesn't exist.
        if ( !exists $self->{_table}->{$row_num} ) {
            push @data, undef;
            next;
        }

        for my $col_num ( $col_start .. $col_end ) {

            if ( my $cell = $self->{_table}->{$row_num}->{$col_num} ) {

                my $type  = $cell->[0];
                my $token = $cell->[1];


                if ( $type eq 'n'  || $type eq 't') {

                    # Store a number.
                    push @data, $token;
                }
                elsif ( $type eq 's' || $type eq 'r' ) {

                    # Store a string.
                    if ( $self->{_optimization} == 0 ) {
                        push @data, { 'sst_id' => $token };
                    }
                    else {
                        push @data, $token;
                    }
                }
                elsif ( $type eq 'f' ) {

                    # Store a formula.
                    push @data, $cell->[3] || 0;
                }
                elsif ( $type eq 'a' || $type eq 'd') {

                    # Store an array formula.
                    push @data, $cell->[4] || 0;
                }
                elsif ( $type eq 'b' ) {

                    # Store a empty cell.
                    push @data, '';



( run in 0.655 second using v1.01-cache-2.11-cpan-5837b0d9d2c )