View | Details | Raw Unified | Return to bug 21560
Collapse All | Expand All

(-)a/reports/guided_reports.pl (-10 / +13 lines)
Lines 923-959 elsif ($phase eq 'Export'){ Link Here
923
                my $ods_fh = File::Temp->new( UNLINK => 0 );
923
                my $ods_fh = File::Temp->new( UNLINK => 0 );
924
                my $ods_filepath = $ods_fh->filename;
924
                my $ods_filepath = $ods_fh->filename;
925
925
926
                # Create document
926
                use OpenOffice::OODoc;
927
                use OpenOffice::OODoc;
927
                my $tmpdir = dirname $ods_filepath;
928
                my $tmpdir = dirname $ods_filepath;
928
                odfWorkingDirectory( $tmpdir );
929
                odfWorkingDirectory( $tmpdir );
929
                my $container = odfContainer( $ods_filepath, create => 'spreadsheet' );
930
                my $doc = odfDocument( file => $ods_filepath, create => 'spreadsheet' );
930
                my $doc = odfDocument (
931
931
                    container => $container,
932
                # Prepare sheet
932
                    part      => 'content'
933
                );
934
                my $table = $doc->getTable(0);
935
                my @headers = header_cell_values( $sth );
933
                my @headers = header_cell_values( $sth );
936
                my $rows = $sth->fetchall_arrayref();
934
                my $rows = $sth->fetchall_arrayref();
937
                my ( $nb_rows, $nb_cols ) = ( 0, 0 );
935
                my ( $nb_rows, $nb_cols ) = ( 0, 0 );
938
                $nb_rows = @$rows;
936
                $nb_rows = @$rows;
939
                $nb_cols = @headers;
937
                $nb_cols = @headers;
940
                $doc->expandTable( $table, $nb_rows + 1, $nb_cols );
938
                my $sheet = $doc->expandTable( 0, $nb_rows + 1, $nb_cols );
939
                my @rows = $doc->getTableRows($sheet);
941
940
942
                my $row = $doc->getRow( $table, 0 );
941
                # Write headers row
942
                my $row = $rows[0];
943
                my $j = 0;
943
                my $j = 0;
944
                for my $header ( @headers ) {
944
                for my $header ( @headers ) {
945
                    $doc->cellValue( $row, $j, $header );
945
                    $doc->cellValue( $row, $j, $header );
946
                    $j++;
946
                    $j++;
947
                }
947
                }
948
949
                # Write all rows
948
                my $i = 1;
950
                my $i = 1;
949
                for ( @$rows ) {
951
                for ( @$rows ) {
950
                    $row = $doc->getRow( $table, $i );
952
                    $row = $rows[$i];
951
                    for ( my $j = 0 ; $j < $nb_cols ; $j++ ) {
953
                    for ( my $j = 0 ; $j < $nb_cols ; $j++ ) {
952
                        my $value = Encode::encode( 'UTF8', $rows->[$i - 1][$j] );
954
                        my $value = Encode::encode( 'UTF8', $rows->[$i - 1][$j] );
953
                        $doc->cellValue( $row, $j, $value );
955
                        $doc->cellValue( $row, $j, $value );
954
                    }
956
                    }
955
                    $i++;
957
                    $i++;
956
                }
958
                }
959
960
                # Done
957
                $doc->save();
961
                $doc->save();
958
                binmode(STDOUT);
962
                binmode(STDOUT);
959
                open $ods_fh, '<', $ods_filepath;
963
                open $ods_fh, '<', $ods_filepath;
960
- 

Return to bug 21560