|
Lines 254-271
sub generate_ods {
Link Here
|
| 254 |
my $messages = $params->{messages}; |
254 |
my $messages = $params->{messages}; |
| 255 |
my $filepath = $params->{filepath}; |
255 |
my $filepath = $params->{filepath}; |
| 256 |
|
256 |
|
|
|
257 |
# Create document |
| 257 |
use OpenOffice::OODoc; |
258 |
use OpenOffice::OODoc; |
| 258 |
my $tmpdir = dirname $filepath; |
259 |
my $tmpdir = dirname $filepath; |
| 259 |
odfWorkingDirectory( $tmpdir ); |
260 |
odfWorkingDirectory( $tmpdir ); |
| 260 |
my $container = odfContainer( $filepath, create => 'spreadsheet' ); |
261 |
my $doc = odfDocument( file => $filepath, create => 'spreadsheet' ); |
| 261 |
my $doc = odfDocument ( |
|
|
| 262 |
container => $container, |
| 263 |
part => 'content' |
| 264 |
); |
| 265 |
my $table = $doc->getTable(0); |
| 266 |
|
262 |
|
|
|
263 |
# Prepare sheet |
| 267 |
my @headers; |
264 |
my @headers; |
| 268 |
my ( $nb_rows, $nb_cols, $i ) = ( scalar(@$messages), 0, 0 ); |
265 |
my @rows; |
|
|
266 |
my $i = 0; |
| 269 |
foreach my $message ( @$messages ) { |
267 |
foreach my $message ( @$messages ) { |
| 270 |
my @lines = split /\n/, $message->{content}; |
268 |
my @lines = split /\n/, $message->{content}; |
| 271 |
chomp for @lines; |
269 |
chomp for @lines; |
|
Lines 273-282
sub generate_ods {
Link Here
|
| 273 |
# We don't have headers, get them |
271 |
# We don't have headers, get them |
| 274 |
unless ( @headers ) { |
272 |
unless ( @headers ) { |
| 275 |
@headers = split $delimiter, $lines[0]; |
273 |
@headers = split $delimiter, $lines[0]; |
|
|
274 |
my $nb_cols = scalar @headers; |
| 275 |
my $nb_rows = scalar @$messages; |
| 276 |
my $sheet = $doc->expandTable( 0, $nb_rows + 1, $nb_cols ); |
| 277 |
@rows = $doc->getTableRows($sheet); |
| 276 |
|
278 |
|
| 277 |
$nb_cols = @headers; |
279 |
# Write headers row |
| 278 |
$doc->expandTable( $table, $nb_rows + 1, $nb_cols ); |
280 |
my $row = $rows[0]; |
| 279 |
my $row = $doc->getRow( $table, 0 ); |
|
|
| 280 |
my $j = 0; |
281 |
my $j = 0; |
| 281 |
for my $header ( @headers ) { |
282 |
for my $header ( @headers ) { |
| 282 |
$doc->cellValue( $row, $j, Encode::encode( 'UTF8', $header ) ); |
283 |
$doc->cellValue( $row, $j, Encode::encode( 'UTF8', $header ) ); |
|
Lines 285-294
sub generate_ods {
Link Here
|
| 285 |
$i = 1; |
286 |
$i = 1; |
| 286 |
} |
287 |
} |
| 287 |
|
288 |
|
|
|
289 |
# Write all rows |
| 288 |
shift @lines; # remove headers |
290 |
shift @lines; # remove headers |
| 289 |
for my $line ( @lines ) { |
291 |
for my $line ( @lines ) { |
| 290 |
my @row_data = split $delimiter, $line; |
292 |
my @row_data = split $delimiter, $line; |
| 291 |
my $row = $doc->getRow( $table, $i ); |
293 |
my $row = $rows[$i]; |
| 292 |
# Note scalar(@$row_data) should be equal to $nb_cols |
294 |
# Note scalar(@$row_data) should be equal to $nb_cols |
| 293 |
for ( my $j = 0 ; $j < scalar(@row_data) ; $j++ ) { |
295 |
for ( my $j = 0 ; $j < scalar(@row_data) ; $j++ ) { |
| 294 |
my $value = Encode::encode( 'UTF8', $row_data[$j] ); |
296 |
my $value = Encode::encode( 'UTF8', $row_data[$j] ); |
| 295 |
- |
|
|