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

(-)a/reports/guided_reports.pl (-10 / +13 lines)
Lines 906-942 elsif ($phase eq 'Export'){ Link Here
906
                my $ods_fh = File::Temp->new( UNLINK => 0 );
906
                my $ods_fh = File::Temp->new( UNLINK => 0 );
907
                my $ods_filepath = $ods_fh->filename;
907
                my $ods_filepath = $ods_fh->filename;
908
908
909
                # Create document
909
                use OpenOffice::OODoc;
910
                use OpenOffice::OODoc;
910
                my $tmpdir = dirname $ods_filepath;
911
                my $tmpdir = dirname $ods_filepath;
911
                odfWorkingDirectory( $tmpdir );
912
                odfWorkingDirectory( $tmpdir );
912
                my $container = odfContainer( $ods_filepath, create => 'spreadsheet' );
913
                my $doc = odfDocument( file => $ods_filepath, create => 'spreadsheet' );
913
                my $doc = odfDocument (
914
914
                    container => $container,
915
                # Prepare sheet
915
                    part      => 'content'
916
                );
917
                my $table = $doc->getTable(0);
918
                my @headers = header_cell_values( $sth );
916
                my @headers = header_cell_values( $sth );
919
                my $rows = $sth->fetchall_arrayref();
917
                my $rows = $sth->fetchall_arrayref();
920
                my ( $nb_rows, $nb_cols ) = ( 0, 0 );
918
                my ( $nb_rows, $nb_cols ) = ( 0, 0 );
921
                $nb_rows = @$rows;
919
                $nb_rows = @$rows;
922
                $nb_cols = @headers;
920
                $nb_cols = @headers;
923
                $doc->expandTable( $table, $nb_rows + 1, $nb_cols );
921
                my $sheet = $doc->expandTable( 0, $nb_rows + 1, $nb_cols );
922
                my @rows = $doc->getTableRows($sheet);
924
923
925
                my $row = $doc->getRow( $table, 0 );
924
                # Write headers row
925
                my $row = $rows[0];
926
                my $j = 0;
926
                my $j = 0;
927
                for my $header ( @headers ) {
927
                for my $header ( @headers ) {
928
                    $doc->cellValue( $row, $j, $header );
928
                    $doc->cellValue( $row, $j, $header );
929
                    $j++;
929
                    $j++;
930
                }
930
                }
931
932
                # Write all rows
931
                my $i = 1;
933
                my $i = 1;
932
                for ( @$rows ) {
934
                for ( @$rows ) {
933
                    $row = $doc->getRow( $table, $i );
935
                    $row = $rows[$i];
934
                    for ( my $j = 0 ; $j < $nb_cols ; $j++ ) {
936
                    for ( my $j = 0 ; $j < $nb_cols ; $j++ ) {
935
                        my $value = Encode::encode( 'UTF8', $rows->[$i - 1][$j] );
937
                        my $value = Encode::encode( 'UTF8', $rows->[$i - 1][$j] );
936
                        $doc->cellValue( $row, $j, $value );
938
                        $doc->cellValue( $row, $j, $value );
937
                    }
939
                    }
938
                    $i++;
940
                    $i++;
939
                }
941
                }
942
943
                # Done
940
                $doc->save();
944
                $doc->save();
941
                binmode(STDOUT);
945
                binmode(STDOUT);
942
                open $ods_fh, '<', $ods_filepath;
946
                open $ods_fh, '<', $ods_filepath;
943
- 

Return to bug 21560