X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax-xls.cgi;h=bb843a73f31cc0a324367898fa1e22b19771e791;hb=a72a10f754f7465121d6137bb3dcee0a21ea6443;hp=1c278dfd1af6c7e675bb563b081b88cc64959b22;hpb=b5c4237a34aef94976bc343c8d9e138664fc3984;p=freeside.git diff --git a/httemplate/search/report_tax-xls.cgi b/httemplate/search/report_tax-xls.cgi index 1c278dfd1..bb843a73f 100755 --- a/httemplate/search/report_tax-xls.cgi +++ b/httemplate/search/report_tax-xls.cgi @@ -1,9 +1,24 @@ -<% $data %> <%init> +my $htmldoc = include('report_tax.cgi'); + +my ($title) = ($htmldoc =~ /\s*(.*)\s*<\/title>/i); + +# do this first so we can override the format if it's too many rows +# attribs option: how to locate the table? It's the only one with class="grid". +my $te = HTML::TableExtract->new(attribs => {class => 'grid'}); +$te->parse($htmldoc); +my $table = $te->first_table_found; + +my $override = ($table->row_count >= 65536 ? 'XLSX' : ''); +my $format = $FS::CurrentUser::CurrentUser->spreadsheet_format($override); +my $filename = 'report_tax'.$format->{extension}; + +http_header('Content-Type' => $format->{mime_type}); +http_header('Content-Disposition' => qq!attachment;filename="$filename"! ); my $data = ''; my $XLS = new IO::Scalar \$data; -my $workbook = Spreadsheet::WriteExcel->new($XLS) +my $workbook = $format->{class}->new($XLS) or die "Error opening .xls file: $!"; # hardcoded formats, this could be handled better @@ -66,15 +81,6 @@ foreach (keys(%format)) { } my $ws = $workbook->add_worksheet('taxreport'); -my $htmldoc = include('report_tax.cgi'); - -my ($title) = ($htmldoc =~ /<title>\s*(.*)\s*<\/title>/i); - -# attribs option: how to locate the table? It's the only one with class="grid". -my $te = HTML::TableExtract->new(attribs => {class => 'grid'}); -$te->parse($htmldoc); -my $table = $te->first_table_found; - my @sheet; $sheet[0][0] = { text => $title, @@ -148,6 +154,6 @@ for my $x (0..scalar(@widths)-1) { $workbook->close; -http_header('Content-Type' => 'application/vnd.ms-excel'); -http_header('Content-Disposition' => 'attachment;filename="report_tax.xls"'); +http_header('Content-Length' => length($data)); +$m->print($data); </%init>