title: MIME type/Content-type for opening CSV files using Excel in IE & Firefox
body: <p>I have been having an issue with getting CSV output to be recognized &amp; opened in Excel. In my web application I have a java servlet that returns search results to the user. The search results are delivered by an Apache Solr server. There is an option on the GUI front-end that allows the user to request the search results in “CSV” format. If this option is selected then the query is re-run against Solr by adding a "wt=csv" param. Then a java filter adds headers to return the results as CSV formatted-text. But it’s not working correctly. </p>
  
  <ul>
  <li>In IE (ver 8.0) I am prompted to “Open” or “Save” the file. If I select “Open”; it just dumps CSV-formatted text on the screen instead of opening it in Excel. And if I select “Save”; I get an error message – “Unable to open this internet site. The requested site is either unavailable or cannot be found.”</li>
  <li>In Firefox (ver 10.0.9) also; I get prompted to open or save the file. But for opening the CSV file; the default option is Notepad &amp; Excel is not even listed. If I click “Save” then it does download the CSV file &amp; I can open it in Excel and it’s correctly recognized by Excel.</li>
  </ul>
  
  <p>I have tried a variety of headers &amp; combinations –</p>
  
  <pre><code>  //((HttpServletResponse)response).setHeader("Content-Type", "application/octet; charset=utf-8");
    ((HttpServletResponse)response).setHeader("Content-Type", "text/csv");
    //((HttpServletResponse)response).setHeader("Content-Type", "application/vnd.ms-excel");
    //((HttpServletResponse)response).setHeader("Cache-Control", "private, private,max-age=0,must-revalidate");
    //((HttpServletResponse)response).setHeader("Content-Encoding", "gzip");
    //((HttpServletResponse)response).setHeader("Content-Encoding", "binary");
    ((HttpServletResponse)response).setHeader("Content-Disposition", "attachment; filename=Download.CSV");
    //((HttpServletResponse)response).setHeader("Content-Disposition", "inline; filename=Download.CSV;");
  </code></pre>
  
  <p>But none of them seem to be working. I used Firefox to inspect the headers that are being sent back &amp; I see the following –</p>
  
  <p>Content-Disposition:attachment; filename=Download.CSV</p>
  
  <p>Content-Type:text/plain;charset=UTF-8</p>
  
  <p>Server:Jetty(7.x.y-SNAPSHOT)</p>
  
  <p>Transfer-Encoding:chunked</p>
  
  <p>Vary:Accept-Encoding</p>
  
  <p>Even though the content-type is specified as csv Or excel; when it reaches the browser it’s being interpreted as text/plain &amp; I think that’s the issue. Not sure what header Or encoding I should be setting? Any suggestions? Thanks.</p>