#!/usr/bin/perl use strict; use warnings; sub add_xl_header { return< Sheet1 EOT } sub add_xl_table { defined(my $array_ref = shift) || return; my ($use_row_headers, $use_col_headers) = @_; my $table; my $max_width = 0; if ($use_row_headers) { my $row = shift @$array_ref; $table .= "\n"; $table .= "$_\n" for @$row; $table .= "\n"; } for my $row (@$array_ref) { $max_width = @$row if @$row > $max_width; $table .= "\n"; $$row[0] = '' . $$row[0] if $use_col_headers; $table .= "$_\n" for @$row; $table .= "\n"; } $table = "\n\n$table
\n"; $table; } sub add_xl_separator { my $sep_rows = shift || 1; return "
\n"; } sub add_xl_trailer { return "\n\n"; } ## Misc # Add a formula to a cell : # Define a cell as Text : 00123 # Indent a row 2 columns : my @test_array1 = ( [2, 3, 5] , [7, 11, 13] , [17, 19, 23] ); my @test_array2 = ( ['', 'Height', 'Siblings'], ['Joe', 77, 1], ['Frank', 70, 4] ); print add_xl_header; print add_xl_table \@test_array1; print add_xl_separator 3; print add_xl_table (\@test_array2, 1, 1); print add_xl_trailer;