Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
How to link html form to javascript function that appends row data into an excel file

I have written some code that appends row data into an excel worksheet using javascript and exceljs.

This file works perfectly fine independently without any HTML. However, my greater objective is to save form data into an excel file.

Here is the javascript code:

//Part1

const info = [];

function display(e){ 
    e.preventDefault();
    var nm = document.getElementById("nm").value;
    var ag = document.getElementById("ag").value;
    var data = [nm, ag];
    info.push(data);
    var text = document.createElement("h2"); 
    text.innerHTML = info;
    document.body.appendChild(text);
    console.log(info);

    // ----------------------------------------------

//Part2
    var Excel = require('exceljs');
    var workbook = new Excel.Workbook();
    workbook.xlsx.readFile("AppendRow.xlsx").then(function(){
        worksheet = workbook.getWorksheet("Main")
        worksheet.addRows(data);

    workbook.xlsx.writeFile("AppendRow.xlsx")
    });
}

In Part1, I am formatting the input details into a list so that I can easily append the data into excel....it puts all the user credentials into a list.

In Part2, it fetches the excel file and appends the data into a row (at least this is what I expect it to do, as I had mentioned it works fine independently but not when combined this way.)

Here is the HTML part:

<head>
    <h1 style="font-family: Broadway">HTML to Append Row Function :-)</h1>
</head>
<body>
    <script type="text/javascript" src="trial2.js"></script>
    <form method='POST' onsubmit = 'return(display())'>
        <input type="text" id='nm' placeholder="Name">
        <input type="number" id='ag' placeholder="Age">
        <input type="submit" value="Submit">
    </form>
</body>

On running the HTML file on the browser, I don't see any output. Nor do I see any new row appended into the excel file.

I assume the problem to be in linking the two files...so I copied the entire JavaScript code into the HTML script tag, but it still didn't work.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!