title: How do I avoid encoding problems with Excel::Writer::XLSX in a CGI environment?
body: <p>I am trying to send an OOXML Excel file to the browser based on the <a href="http://p3rl.org/Excel%3a%3aWriter%3a%3aXLSX%3a%3aExamples#Example%3a-cgi.pl" rel="nofollow"><code>cgi.pl</code> example in Excel::Writer::XLSX::Examples</a>.</p>
  
  <pre><code>#!/usr/bin/perl
  
  ###############################################################################
  #
  # Example of how to use the Excel::Writer::XLSX module to send an Excel
  # file to a browser in a CGI program.
  #
  # On Windows the hash-bang line should be something like:
  #
  #     #!C:\Perl\bin\perl.exe
  #
  # The "Content-Disposition" line will cause a prompt to be generated to save
  # the file. If you want to stream the file to the browser instead, comment out
  # that line as shown below.
  #
  # reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
  #
  
  use strict;
  use warnings;
  use Excel::Writer::XLSX;
  
  # Set the filename and send the content type
  my $filename = "cgitest.xlsx";
  
  print "Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n";
  
  # The Content-Disposition will generate a prompt to save the file. If you want
  # to stream the file to the browser, comment out the following line.
  print "Content-Disposition: attachment; filename=$filename\n";
  print "\n";
  
  # Redirect the output to STDOUT. Binmode the filehandle in case it is needed.
  binmode STDOUT;
  
  my $workbook  = Excel::Writer::XLSX-&gt;new( \*STDOUT );
  my $worksheet = $workbook-&gt;add_worksheet();
  
  
  # Set the column width for column 1
  $worksheet-&gt;set_column( 0, 0, 20 );
  
  
  # Create a format
  my $format = $workbook-&gt;add_format();
  $format-&gt;set_bold();
  $format-&gt;set_size( 15 );
  $format-&gt;set_color( 'blue' );
  
  
  # Write to the workbook
  $worksheet-&gt;write( 0, 0, "Hi Excel!", $format );
  
  __END__
  </code></pre>
  
  <p>The file also contains characters like <code>č š ž ć đ</code> which are displayed like <code>Ä Å¡ Ä Å¾ Ä !</code>. I guess this is a problem with the encoding.</p>
  
  <p>Does anybody know what could be wrong and how to fix this?</p>