clarketm / TableExport

The simple, easy-to-implement library to export HTML tables to xlsx, xls, csv, and txt files.
https://tableexport.travismclarke.com/
Apache License 2.0
888 stars 289 forks source link

Unable to click on button in excel. #137

Open nwoow opened 6 years ago

nwoow commented 6 years ago

I am trying to add a export to excel functionality to my table. I am generating my table using this code:

   var table = document.createElement("TABLE")  as HTMLTableElement;    
    var row,header,cell1, cell2;
    var data = chart.options.data;
    // table.style.border = "1px solid #000"; 
    header = table.createTHead();
    row = header.insertRow(0);
    table.setAttribute("id", "myId");    
    cell1 = row.insertCell(0);
    cell2 = row.insertCell(1);
    // cell1.style.border = "1px solid #000"; 
    // cell2.style.border = "1px solid #000"; 
    cell1.innerHTML = "<strong>Districts</strong>"; 
    cell2.innerHTML = "<b>"+rain_fall_type+"_Value</b>"; 
    for(var i = 0; i < data.length; i++){
      for(var j = 0; j< data[i].dataPoints.length; j++){
        // console.log(data[i].dataPoints[j]);
        // console.log(data[i].dataPoints[j].label);
        row = table.insertRow(1);
        cell1 = row.insertCell(0);
        cell2 = row.insertCell(1);
        // cell1.style.border = "1px solid #000"; 
        // cell2.style.border = "1px solid #000"; 
        cell1.innerHTML = "<strong>"+data[i].dataPoints[j].label+"</strong>";
        cell2.innerHTML = data[i].dataPoints[j].y; 
      }
    }    
    // document.getElementById("chartContainer").innerHTML = "<h1>"+rain_fall_type+" "+year+"</h2>";

    document.getElementById("chartContainer").appendChild(table);
    new TableExport(document.getElementsByTagName("table"));

I am generating my table using this code I am also adding tableexport function in this. But I am getting all the buttons but they are not clickable.

But when I add a simple table in html like this: <table id="myId"></table>

I can see the buttons and I can import excel sheet but it this case I am seeing two sets of button. How can I make this work in my case.