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 6093715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:35:34+00:00 2026-05-23T12:35:34+00:00

I am using the following method to read header names in a table and

  • 0

I am using the following method to read header names in a table and put in excel. Could anyone let me know how to modify this to support multiple tables with header info and data.
i.e. how to modify to pass table id. “headers” is the id for “th” tag in code.

function write_headers_to_excel() 
{
  str="";
  var myTableHead = document.getElementById('headers');
  var rowCount = myTableHead.rows.length;
  var colCount = myTableHead.getElementsByTagName("tr")[0].getElementsByTagName("th").length; 

  var ExcelApp = new ActiveXObject("Excel.Application");
  var ExcelSheet = new ActiveXObject("Excel.Sheet");
   ExcelSheet.Application.Visible = true;

  for(var i=0; i<rowCount; i++) 
  {   
   for(var j=0; j<colCount; j++) 
   {           
      str= myTableHead.getElementsByTagName("tr")[i].getElementsByTagName("th")   [j].innerHTML;
    ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = str;
}
 }
  • 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-05-23T12:35:34+00:00Added an answer on May 23, 2026 at 12:35 pm

    Your question is a bit vague, so I’m guessing at what you want. Assuming your current function works as is, you can just take out the hard-coding of the table’s ID and pass it in as a parameter:

    function write_headers_to_excel(tableID)  {
       var myTableHead = document.getElementById(tableID);
       // rest of your function as is
    }
    

    Then call it once for each table, though that will create a new ExcelSheet for each table.

    If the idea is for all of the tables to be added to the same ExcelSheet you can pass an array of table IDs to the function something like the following. I’ve kept the basic structure of your function but moved the variable declarations out of the loops (since that what JavaScript does behind the scenes anyway), deleted your ExcellApp variable since it wasn’t used, and moved the getElementsByTagName call out of the inner loop.

    write_headers_to_excel(["headers1","headers3","headers7","etc"]);
    
    function write_headers_to_excel(tableIDs)  {
       var myTableHead,
           rowCount,
           cols,
           t,
           i,
           j,
           rowOffset = 1,
           ExcelSheet = new ActiveXObject("Excel.Sheet");
    
       ExcelSheet.Application.Visible = true;
    
       for (t=0; t < tableIDs.length; t++) {
          myTableHead = document.getElementById(tableIDs[t]);
          rowCount = myTableHead.rows.length;
    
          for(i=0; i<rowCount; i++) {
             cols = myTableHead.rows[i].getElementsByTagName("th");
             for(j=0; j < cols.length; j++) {
                ExcelSheet.ActiveSheet.Cells(i+rowOffset,j+1).Value = cols[j].innerHTML;
             }
          }
          rowOffset += rowCount;
       }
    }
    

    (No, I haven’t tested it.)

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

Sidebar

Related Questions

I'm using the following method to read the content of a file into a
I'm using the following method to read in a line of text from an
I'm using the following method to send mail from Python using SMTP. Is it
I am using the following method: set_browser_log_level 'off' but my log level continues to
I am using the following method to browse for a file: OpenFileDialog.ShowDialog() PictureNameTextEdit.Text =
I am using the following method for reading Csv file content: /// <summary> ///
I am using the following method to reverse geocode a google maps latlng: [GClientGeocoder.getLocations(address:String,
I am using the following method to basically create a JSON string. var saveData
I am using the following method to get the time of the video with
I'm using the following method in my code: - (NSMutableArray *) newOrderedArray:(NSMutableArray *)array ByKey:(NSString

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.