summaryrefslogtreecommitdiff
path: root/httemplate/search/report_tax-xls.cgi
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-07-26 14:05:08 -0700
committerIvan Kohler <ivan@freeside.biz>2012-07-26 14:05:08 -0700
commit8c450aab9bae89373c2c1b35c85597bb52299de3 (patch)
tree62e7400162703ad0990f80a2d71b90fc1167e759 /httemplate/search/report_tax-xls.cgi
parent2528cc7b182781a82844d8bbb1b555560487abc7 (diff)
parentbd647f16de5352722baed016b45baa4e7c695278 (diff)
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/search/report_tax-xls.cgi')
-rwxr-xr-xhttemplate/search/report_tax-xls.cgi29
1 files changed, 17 insertions, 12 deletions
diff --git a/httemplate/search/report_tax-xls.cgi b/httemplate/search/report_tax-xls.cgi
index 1c278dfd1..f19f85aaa 100755
--- a/httemplate/search/report_tax-xls.cgi
+++ b/httemplate/search/report_tax-xls.cgi
@@ -1,9 +1,25 @@
<% $data %>
<%init>
+my $htmldoc = include('report_tax.cgi');
+
+my ($title) = ($htmldoc =~ /<title>\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 +82,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 +155,4 @@ 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"');
</%init>