X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Freport_tax-xls.cgi;h=bb843a73f31cc0a324367898fa1e22b19771e791;hb=196d15248930f3e54811a8b46b5ede47db678e19;hp=54a17d0b644680fc3d9247580e522012d018a323;hpb=11686f7c21bed96f563e70212f44044604f8a733;p=freeside.git diff --git a/httemplate/search/report_tax-xls.cgi b/httemplate/search/report_tax-xls.cgi index 54a17d0b6..bb843a73f 100755 --- a/httemplate/search/report_tax-xls.cgi +++ b/httemplate/search/report_tax-xls.cgi @@ -1,14 +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}; -use Spreadsheet::WriteExcel; -use Spreadsheet::WriteExcel::Utility 'xl_range_formula'; -use List::Util 'max'; -use HTML::TableExtract 'tree'; +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 @@ -71,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, @@ -153,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>