[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 40102e7cb896a4eeb8823552cbb1e0c36278e228

Mark Wells mark at 420.am
Fri Jul 13 16:56:09 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  40102e7cb896a4eeb8823552cbb1e0c36278e228 (commit)
      from  7d3df502cdb301418ea0659e39c48bd940591d4c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 40102e7cb896a4eeb8823552cbb1e0c36278e228
Author: Mark Wells <mark at freeside.biz>
Date:   Fri Jul 13 16:55:59 2012 -0700

    support XLSX in other places, #17971

diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm
index c5ce1af..08021ba 100644
--- a/FS/FS/access_user.pm
+++ b/FS/FS/access_user.pm
@@ -511,14 +511,16 @@ sub default_customer_view {
 
 }
 
-=item spreadsheet_format
+=item spreadsheet_format [ OVERRIDE ]
 
 Returns a hashref of this user's Excel spreadsheet download settings:
 'extension' (xls or xlsx), 'class' (Spreadsheet::WriteExcel or
-Excel::Writer::XLSX), and 'mime_type'.
+Excel::Writer::XLSX), and 'mime_type'.  If OVERRIDE is 'XLS' or 'XLSX',
+use that instead of the user's setting.
 
 =cut
 
+# is there a better place to put this?
 my %formats = (
   XLS => {
     extension => '.xls',
@@ -535,10 +537,12 @@ my %formats = (
 
 sub spreadsheet_format {
   my $self = shift;
+  my $override = shift;
 
-  my $f = $self->option('spreadsheet_format') 
-       || $conf->config('spreadsheet_format')
-       || 'XLS';
+  my $f =  $override
+        || $self->option('spreadsheet_format') 
+        || $conf->config('spreadsheet_format')
+        || 'XLS';
 
   $formats{$f};
 }
diff --git a/httemplate/graph/elements/report.html b/httemplate/graph/elements/report.html
index 3600f2c..f774616 100644
--- a/httemplate/graph/elements/report.html
+++ b/httemplate/graph/elements/report.html
@@ -77,15 +77,16 @@ any delimiter and linked from the elements in @data.
 %   } 
 %   
 % } elsif ( $cgi->param('_type') =~ /(xls)$/ ) {
-%
-%   #http_header('Content-Type' => 'application/excel' ); #eww
-%   http_header('Content-Type' => 'application/vnd.ms-excel' );
-%   #http_header('Content-Type' => 'application/msexcel' ); #alas
-%   http_header('Content-Disposition' => "attachment;filename=$filename.xls");
+%   #false laziness w/  search/elements/search-xls
+%   my $format = $FS::CurrentUser::CurrentUser->spreadsheet_format;
+%   $filename .= $format->{extension};
+%   
+%   http_header('Content-Type' => $format->{mime_type} );
+%   http_header('Content-Disposition' => qq!attachment;filename="$filename"! );
 %
 %   my $output = '';
 %   my $XLS = new IO::Scalar \$output;
-%   my $workbook = Spreadsheet::WriteExcel->new($XLS)
+%   my $workbook = $format->{class}->new($XLS)
 %     or die "Error opening .xls file: $!";
 %
 %   my $worksheet = $workbook->add_worksheet(substr($opt{'title'},0,31));
@@ -304,9 +305,6 @@ td.cell {
 
 <% include('/elements/footer.html') %>
 % } 
-<%once>
-
-</%once>
 <%init>
 
 my(%opt) = @_;
diff --git a/httemplate/search/elements/search-xls.html b/httemplate/search/elements/search-xls.html
index c862dfb..09dbe46 100644
--- a/httemplate/search/elements/search-xls.html
+++ b/httemplate/search/elements/search-xls.html
@@ -7,7 +7,10 @@ my $header = $args{'header'};
 my $rows   = $args{'rows'};
 my %opt    = %{ $args{'opt'} };    
 
-my $format = $FS::CurrentUser::CurrentUser->spreadsheet_format;
+my $override = scalar(@$rows) >= 65536 ? 'XLSX' : '';
+
+my $format = $FS::CurrentUser::CurrentUser->spreadsheet_format($override);
+
 my $filename = $opt{'name'} || PL($opt{'name_singular'});
 $filename .= $format->{extension};
 
diff --git a/httemplate/search/report_tax-xls.cgi b/httemplate/search/report_tax-xls.cgi
index 1c278df..f19f85a 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>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/access_user.pm                       |   14 ++++++++----
 httemplate/graph/elements/report.html      |   16 ++++++--------
 httemplate/search/elements/search-xls.html |    5 +++-
 httemplate/search/report_tax-xls.cgi       |   29 ++++++++++++++++-----------
 4 files changed, 37 insertions(+), 27 deletions(-)




More information about the freeside-commits mailing list