Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:45:31+00:00 2026-06-09T04:45:31+00:00

I am using this particular part of code which i found on the net,

  • 0

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.

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?

<html>
  <head>
    <script type="text/javascript">
      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 < row_count ; i++) 
        { 
          for(var j=0; j < col_Count; j++) 
          { 
            str= mytable.getElementsByTagName("tr")[i].getElementsByTagName("td")[j].innerHTML; 
            ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = str; 
          } 
        } 

      }
    </script>
    </script>
  </head> 
  <body> 

    <input type="submit" value="Export to EXCEL" onclick="write_to_excel();"/> 

    <!-- ************************************************--> 
    <!--**** INSERT THE TABLE YOU WANT EXPORT HERE ****--> 
    <table><tr><td>First</td><td>second</td></tr></table> 
    <!-- *******************example given above****************--> 

  </body> 
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:45:33+00:00Added an answer on June 9, 2026 at 4:45 am

    This does the trick:

    function writeToExcel() {
        var i, j, str,
            myTable = document.getElementById('mytable'),
            rowCount = myTable.rows.length,
            excel = new ActiveXObject('Excel.Application');// Activates Excel
        excel.Workbooks.Add(); // Opens a new Workbook
        excel.Application.Visible = true; // Shows Excel on the screen
        for (i = 0; i < rowCount; i++) {
            for (j = 0; j < myTable.rows[i].cells.length; j++) {
                str = myTable.rows[i].cells[j].innerText;
                excel.ActiveSheet.Cells(i + 1, j + 1).Value = str; // Writes to the sheet
            }
        }
        return;
    }
    

    Your original code actually works, there is just a typo in for(i)-loop (row_count == undefined). And no errors? However, with this code you can get rid of the horrible hack of referring cells in the rows, also it opens a “Workbook” instead of “Object”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading part of my webpage using AJAX, in particular jQuery.load() . With this
I am using this code phone calling from iPhone its calling directly to particular
I am trying to automap my domain model using fluent nhibernate. In this particular
Not sure if yall can help this time, as I'm just using this particular
I'm using a detailsview control to update a record, however in this particular case
Bjarne suggests using the condition in if's as scope restriction. In particular this example.
I'm trying to create a magnifier app in .NET using the Windows Magnification API
I am trying to implement some code to pick out the last line of
I'm working in a web application using VB.NET. There is also VisualBasic code mixed
For this particular project I will be using PHP 5.3 & MySQL with parameterized

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.