+ push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ;
+ }
+ while (my $row = $sth->fetchrow_arrayref()) {
+ if ($csv->combine(@$row)) {
+ $content .= $csv->string() . "\n";
+ } else {
+ push @$q_errors, { combine => $csv->error_diag() } ;
+ }
+ }
+ }
+ elsif ( $format eq 'ods' ) {
+ $type = 'application/vnd.oasis.opendocument.spreadsheet';
+ my $ods_fh = File::Temp->new( UNLINK => 0 );
+ my $ods_filepath = $ods_fh->filename;
+
+ use OpenOffice::OODoc;
+ my $tmpdir = dirname $ods_filepath;
+ odfWorkingDirectory( $tmpdir );
+ my $container = odfContainer( $ods_filepath, create => 'spreadsheet' );
+ my $doc = odfDocument (
+ container => $container,
+ part => 'content'
+ );
+ my $table = $doc->getTable(0);
+ my @headers = header_cell_values( $sth );
+ my $rows = $sth->fetchall_arrayref();
+ my ( $nb_rows, $nb_cols ) = ( 0, 0 );
+ $nb_rows = @$rows;
+ $nb_cols = @headers;
+ $doc->expandTable( $table, $nb_rows + 1, $nb_cols );
+
+ my $row = $doc->getRow( $table, 0 );
+ my $j = 0;
+ for my $header ( @headers ) {
+ $doc->cellValue( $row, $j, $header );
+ $j++;
+ }
+ my $i = 1;
+ for ( @$rows ) {
+ $row = $doc->getRow( $table, $i );
+ for ( my $j = 0 ; $j < $nb_cols ; $j++ ) {
+ my $value = Encode::encode( 'UTF8', $rows->[$i - 1][$j] );
+ $doc->cellValue( $row, $j, $value );
+ }
+ $i++;