Skip to content Skip to sidebar Skip to footer

Export Html Form To Excel Csv Not Working With Element.append() Method

Following my previous query: HTML form output as a table I would like to export my HTML form output to Excel. I found several examples on the web and tried some of them... https://

Solution 1:

You aren't creating row elements or inserting cells in those row elements or inserting text into the cells you are creating

You are trying to append everything directly into the table element and that won't work.

You can simplify this using Table.insertRow() and Row.insertCell()

initDemo()

const resultsList = document.getElementById('opresults');

newURLSearchParams(window.location.search).forEach((value, name) => {
  const row = resultsList.insertRow();
  [name, value].forEach(v => row.insertCell().textContent = v); 
})


// for demo only - creates initial url search paramsfunctioninitDemo() {
  const params = newURLSearchParams([
    ["issue_1", "answer_1"],
    ["thing_2", "answer_2"]
  ]);
  history.pushState(null, null, '?' + params.toString())


}
<pclass="outputtablehead">Survey Form - output</p><tableid="opresults"class="outputtable"border="1"><trclass="colname"><thclass="question">Form question</th><thcolspan="2"class="answer">Answer</th></tr></table>

Post a Comment for "Export Html Form To Excel Csv Not Working With Element.append() Method"