title: html table to excel sheet in javascript
body: <p>I am using this particular part of code which i found on the net, which i am trying to implement,  this javascript takes the values of the table displayed in the html table and convert's it into excel sheet.</p>
  
  <p>But for some unknown reason the below part of the code is not working. It can be used only in IE and i am not sure why the below code is not working. Can someone what is wrong with this code and can tell me how to correct this code?</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript"&gt;
        function write_to_excel() {
          str="";
          var mytable = document.getElementsByTagName("table")[0]; 
          var row_Count = mytable.rows.length; 
          var col_Count = mytable.getElementsByTagName("tr")[0].getElementsByTagName("td").length; 
  
          var ExcelApp = new ActiveXObject("Excel.Application"); 
          var ExcelSheet = new ActiveXObject("Excel.Sheet"); 
          ExcelSheet.Application.Visible = true; 
  
          for(var i=0; i &lt; row_count ; i++) 
          { 
            for(var j=0; j &lt; col_Count; j++) 
            { 
              str= mytable.getElementsByTagName("tr")[i].getElementsByTagName("td")[j].innerHTML; 
              ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = str; 
            } 
          } 
  
        }
      &lt;/script&gt;
      &lt;/script&gt;
    &lt;/head&gt; 
    &lt;body&gt; 
  
      &lt;input type="submit" value="Export to EXCEL" onclick="write_to_excel();"/&gt; 
  
      &lt;!-- ************************************************--&gt; 
      &lt;!--**** INSERT THE TABLE YOU WANT EXPORT HERE ****--&gt; 
      &lt;table&gt;&lt;tr&gt;&lt;td&gt;First&lt;/td&gt;&lt;td&gt;second&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; 
      &lt;!-- *******************example given above****************--&gt; 
  
    &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>