X-Git-Url: http://git.home-dn.net/?p=manu%2FRT-Extension-SearchResults-XLS.git;a=blobdiff_plain;f=html%2FSearch%2FResults.xls;h=b1eb15d65e4c9764637b613d63573852b43bde6e;hp=123392a3718e72c0f4a35bc644955d7fe6a22217;hb=01d49d6eb897726684b1aa68866ed2a70f709a50;hpb=e8d47bc3e1b44e4e06ef3cb2ebb55828a98b1f86 diff --git a/html/Search/Results.xls b/html/Search/Results.xls index 123392a..b1eb15d 100644 --- a/html/Search/Results.xls +++ b/html/Search/Results.xls @@ -58,6 +58,14 @@ my $no_html = HTML::Scrubber->new( deny => '*' ); <%INIT> require HTML::Entities; +use Spreadsheet::WriteExcel; +my $xls; +my $fh; +open ($fh, ">", \$xls) or die "$!"; +my $workbook = Spreadsheet::WriteExcel->new($fh) or die $!; +my $worksheet = $workbook->add_worksheet(); + + $r->content_type('application/vnd.ms-excel'); my $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $Format); @@ -74,7 +82,7 @@ my $col_entry = sub { delete $col->{title} if $col->{title} and $col->{title} =~ /^\s*#\s*$/; return { - header => Encode::encode_utf8(loc($col->{title} || $col->{attribute})), + header => loc($col->{title} || $col->{attribute}), map => $m->comp( "/Elements/ColumnMap", Name => $col->{attribute}, @@ -103,8 +111,12 @@ else { : () } @Format]; } +my $ws_col = 0; for (@columns) { - $m->out(join("\t", map { $_->{header} } @$_)."\n"); + foreach my $ws_val (map { $_->{header} } @$_) { + $worksheet->write_string(0, $ws_col, $ws_val); + $ws_col++; + } } my $Tickets = RT::Tickets->new( $session{'CurrentUser'} ); @@ -122,21 +134,27 @@ else { $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order ); } +my $ws_row = 1; my $ii = 0; while (my $row = $Tickets->Next) { + $ws_col = 0; for my $col (@columns) { - $m->out(join("\t", map { + for (@$col) { my $val = ProcessColumnMapValue($_->{map}, Arguments => [$row, $ii++], Escape => 0); $val = loc($val) if $_->{should_loc}; - # remove tabs from all field values, they screw up the tsv $val = '' unless defined $val; - $val =~ s/(?:\n|\r)//g; $val =~ s{\t}{ }g; $val = $no_html->scrub($val); $val = HTML::Entities::decode_entities($val); - Encode::encode_utf8($val); - } @$col)."\n"); + $worksheet->write_string($ws_row, $ws_col, $val); + $ws_col++; + } } + $ws_row++; } + +$workbook->close; +close($fh); +$m->print($xls); $m->abort();