<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style>
<!--
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Tahoma}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
span.EmailStyle17
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
.MsoChpDefault
        {font-family:"Calibri","sans-serif"}
@page WordSection1
        {margin:72.0pt 72.0pt 72.0pt 72.0pt}
div.WordSection1
        {}
-->
</style>
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&gt;&gt;</span> All the above seems overkill. &nbsp; I suspect what you want is closer to this: (but see notes below).</p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">Tried that, didn&#8217;t work, ended up in a long Catalyst discussion where it was worked out that I needed to wrap any XLS output to an IO:FILE handle otherwise
 Catalyst dies with an &#8220;out of memory&#8221; error something to do with streaming data support issues in Catalyst so the work round is to wrap the output into an IO:File object.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal">&gt;&gt;Second, be aware that $c-&gt;response-&gt;content_length(length($xls));<span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D"></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">Yes, I was doing the encode then using Length (I did read on perldocs about requesting the length against the octet) , either way, the length was the least
 of my worries, keeping Catalyst from falling over with &#8216;Wide Character&#8217; errors, or not getting garbage was my main concern.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">And yes, the output is CSV not strictly XLS but I have been told and looked it up on the net that
</span>'application/vnd.ms-excel' <span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">
&nbsp;Is the correct MIME header to pass for CSV that you want MS Excel to open.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">Of course, if I have the wrong MIME header for CSV -&gt; MS Excel please can you provide the correct one, as it took me a long time to find that one, as the
 box standard &#8216;text/csv&#8217; does not work properly when opened in MS Excel.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">Though as it appears DBI is corrupting my Unicode data, it might be related to that rather than CSV-&gt;MS Excel per sae!</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt; font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span lang="EN-US" style="font-size:10.0pt; font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> Bill Moseley [mailto:moseley@hank.org]
<br>
<b>Sent:</b> 02 July 2013 16:59<br>
<b>To:</b> The elegant MVC web framework<br>
<b>Subject:</b> Re: [Catalyst] CSV / UTF-8 / Unicode</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style="margin-bottom:12.0pt">&nbsp;</p>
<div>
<p class="MsoNormal">On Tue, Jul 2, 2013 at 2:59 AM, Craig Chant &lt;<a href="mailto:craig@homeloanpartnership.com" target="_blank">craig@homeloanpartnership.com</a>&gt; wrote:</p>
<p class="MsoNormal"><br>
&nbsp; &nbsp; &nbsp; &nbsp; # output header<br>
&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;response-&gt;content_type('application/vnd.ms-excel');<br>
&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;response-&gt;content_length(length($xls));<br>
&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;response-&gt;header(Content_Disposition =&gt; 'attachment;filename=NBCS_Export.csv');</p>
<div>
<p class="MsoNormal"><br>
&nbsp; &nbsp; &nbsp; &nbsp; # create an IO::File for Catalyst<br>
&nbsp; &nbsp; &nbsp; &nbsp; use IO::File;<br>
&nbsp; &nbsp; &nbsp; &nbsp; my $iof = IO::File-&gt;new;<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; $iof-&gt;open(\$xls, &quot;r&quot;);<br>
&nbsp; &nbsp; &nbsp; &nbsp; $iof-&gt;binmode(&quot;:encoding(UTF-8)&quot;);<br>
<br>
&nbsp; &nbsp; &nbsp; &nbsp; # output XLS data<br>
&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;response-&gt;body($iof);</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">All the above seems overkill. &nbsp; I suspect what you want is closer to this: (but see notes below).</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;response-&gt;content_type('text/csv');</p>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;response-&gt;body($xls);<br>
&nbsp; &nbsp; &nbsp; &nbsp; $c-&gt;response-&gt;header(Content_Disposition =&gt; 'attachment;filename=NBCS_Export.csv');</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">Then with that content type the plugin would encode $xls as utf8 and add ;charset=utf8 (or whatever it is configured to encode as).</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">Notes:</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">First, you are not returning Excel, so the content type is not what you first listed above, right?</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">Second, be aware that $c-&gt;response-&gt;content_length(length($xls)); could be very wrong. &nbsp;If $xls is really CSV text AND it's decoded then length($xls) is the length in characters, not octets. &nbsp; Don't set the content length.</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">Third, Catalyst::Plugin::Unicode::Encoding, IMO, has some issues.</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">The plugin limits to just these content types.</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; return $c-&gt;next::method(@_)</p>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp; unless $c-&gt;response-&gt;content_type =~ /^text|xml$|javascript$/;</p>
</div>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">Then it does this:</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; $c-&gt;response-&gt;body( $c-&gt;encoding-&gt;encode( $body, $CHECK ) )</p>
</div>
<div>
<p class="MsoNormal">&nbsp; &nbsp; &nbsp; &nbsp; if ref(\$body) eq 'SCALAR';</p>
</div>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">Personally, I think the correct approach is to only encode <i>
character</i>&nbsp;data -- that is check to see if the utf8 flag is set before calling encode.</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">Maybe limit to the content types listed above, but throw an exception for other content types where the body is a scalar AND has the utf8 flag on. &nbsp;After all, we can only write out octets or else we get the Wide Character error.</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
</div>
<p class="MsoNormal">-- <br>
Bill Moseley<br>
<a href="mailto:moseley@hank.org" target="_blank">moseley@hank.org</a> </p>
</div>
This Email and any attachments contain confidential information and is intended solely for the individual to whom it is addressed. If this Email has been misdirected, please notify the author as soon as possible. If you are not the intended recipient you must
 not disclose, distribute, copy, print or rely on any of the information contained, and all copies must be deleted immediately. Whilst we take reasonable steps to try to identify any software viruses, any attachments to this e-mail may nevertheless contain
 viruses, which our anti-virus software has failed to identify. You should therefore carry out your own anti-virus checks before opening any documents. HomeLoan Partnership will not accept any liability for damage caused by computer viruses emanating from any
 attachment or other document supplied with this e-mail. HomeLoan Partnership reserves the right to monitor and archive all e-mail communications through its network. No representative or employee of HomeLoan Partnership has the authority to enter into any
 contract on behalf of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of H L Partnership Limited, registered in England and Wales with Registration Number 5011722. Registered office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership
 Limited is authorised and regulated by the Financial Conduct Authority.
</body>
</html>