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