title: Open HTML page in Excel via Javascript
body: <p>We have reports generated in HTML that our users frequently open in Excel, which we serve simple enough by using the content-type. However, we've recently had a wrinkle popup: some of these reports use a lot of Javascript to conduct dynamic grouping/sorting, and the user wants to download this "finished" version of the report into Excel. I have a functioning Javascript function for that:</p>
  
  <pre><code>var uri = 'data:application/vnd.ms-excel;base64,';
  var template = '&lt;html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"&gt;';
  template += '&lt;head&gt;&lt;/head&gt;';
  template += '&lt;body&gt;&lt;table&gt;{table}&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;';
  var base64 = function(s) { 
      return window.btoa(unescape(encodeURIComponent(s)));
  };
  var format = function(s, c) { 
      return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; });
  };
  var ctx = {worksheet: name || 'Worksheet', table: daBody};
  window.location.href = uri + base64(format(template, ctx));
  </code></pre>
  
  <p>I found that IE doesn't support window.btoa, so I addressed that, but now I get the following error when attempting to open the data in Excel:</p>
  
  <blockquote>
    <p>The data area passed to a system call is too small.</p>
  </blockquote>
  
  <p>I believe, despite the message, that this is caused by the base64 string in the URI being too long (I've seen in the past that IE doesn't accept extremely long URLs, and believe this is connected).</p>
  
  <p>So, does anybody have any alternative method I can use for this in IE?</p>