Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda