5 my $type = $args{'type'};
6 my $header = $args{'header'};
7 my $rows = $args{'rows'};
8 my %opt = %{ $args{'opt'} };
10 #http_header('Content-Type' => 'application/excel' ); #eww
11 #http_header('Content-Type' => 'application/msexcel' ); #alas
12 #http_header('Content-Type' => 'application/x-msexcel' ); #?
14 #http://support.microsoft.com/kb/199841
15 http_header('Content-Type' => 'application/vnd.ms-excel' );
17 #http://support.microsoft.com/kb/812935
18 #http://support.microsoft.com/kb/323308
19 $HTML::Mason::Commands::r->headers_out->{'Cache-control'} = 'max-age=0';
22 my $XLS = new IO::Scalar \$data;
23 my $workbook = Spreadsheet::WriteExcel->new($XLS)
24 or die "Error opening .xls file: $!";
26 my $worksheet = $workbook->add_worksheet(substr($opt{'title'},0,31));
30 $worksheet->write($r, $c++, $_) foreach @$header;
32 foreach my $row ( @$rows ) {
36 if ( $opt{'fields'} ) {
38 #my $links = $opt{'links'} ? [ @{$opt{'links'}} ] : '';
39 #my $aligns = $opt{'align'} ? [ @{$opt{'align'}} ] : '';
41 foreach my $field ( @{$opt{'fields'}} ) {
42 #my $align = $aligns ? shift @$aligns : '';
43 #$align = " ALIGN=$align" if $align;
46 # my $link = shift @$links;
47 # $link = &{$link}($row) if ref($link) eq 'CODE';
49 # my( $url, $method ) = @{$link};
50 # if ( ref($method) eq 'CODE' ) {
51 # $a = $url. &{$method}($row);
53 # $a = $url. $row->$method();
55 # $a = qq(<A HREF="$a">);
58 if ( ref($field) eq 'CODE' ) {
59 foreach my $value ( &{$field}($row) ) {
60 if ( ref($value) eq 'ARRAY' ) {
61 $worksheet->write($r, $c++, '(N/A)' ); #unimplemented
63 $worksheet->write($r, $c++, $value );
67 $worksheet->write($r, $c++, $row->$field() );
72 $worksheet->write($r, $c++, $_) foreach @$row;
77 $workbook->close();# or die "Error creating .xls file: $!";
79 http_header('Content-Length' => length($data) );