Please see Dancer and Excel::Writer::XLSX incompatibility! for the real solution and the root cause.


SOLVED!

binmode($fh);

It seems my Dancer application is injecting some CR/LF otherwise...


I'm at my wit's end...

I have a Dancer application where I want to download an Excel file created with Excel::Writer::XLSX as it is the successor of Spreadsheet::WriteExcel.

The below given test code works perfectly. I can download the example XLSX file. But as soon as I take the route and put it into my application, without changing it at all, I receive a non-functional xlsx file. I even tried to unpack it (as these files are zipped) and this unpacking already fails.

I have absolutely no idea what's going on there and I'm wondering whether or not anyone of you ever experienced something like this and might be able to point me into the right direction to solve this proble,m.

use Dancer; use utf8; use Excel::Writer::XLSX; # Step 0 get '/xxx' => sub { my $buffer; open my $fh, '>', \$buffer; my $workbook = Excel::Writer::XLSX->new( $fh ); # Step 1 my $worksheet = $workbook->add_worksheet(); # Step 2 $worksheet->write( 'A1', 'Hi Excel!' ); # Step 3 $workbook->close(); close $fh; return send_file( \$buffer, content_type => 'application/vnd.openxmlformats-officedocument +.spreadsheetml.sheet', filename => 'xxx.xlsx', ); }; dance;

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

In reply to Dancer and Excel::Writer::XLSX incompatibility? by Skeeve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.