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

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

Return to bug 21560