1
<form>
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>

I want onclick "submit" it should save first name and last name in Excel sheet. I don't want to use database and I don't have any server. I read somewhere that we can do the same in CSV. Help me out.

Thanks in advance.

4
  • Did you try anything yourself? Commented May 20, 2015 at 10:28
  • No... I am not sure whether we can do so or not... And if we can do, then how... I am new to it. Commented May 20, 2015 at 10:38
  • See this link. databison.com/… Commented May 20, 2015 at 10:40
  • Maybe this will get you started Commented May 20, 2015 at 10:40

2 Answers 2

1

A possible way is to create an html table. You can set the form values into an invisible table and simulate the download of html table with a link. Excel reads the html and display the data.


Example :

function exportF() {
  //Format your table with form data
  document.getElementById("input").innerHTML = document.getElementById("text").value;

  var table = document.getElementById("table");
  var html = table.outerHTML;

  var url = 'data:application/vnd.ms-excel,' + escape(html); // Set your html table into url 
  var link = document.getElementById("downloadLink");
  link.setAttribute("href", url);
  link.setAttribute("download", "export.xls"); // Choose the file name
  link.click(); // Download your excel file   
  return false;
}
<form onsubmit="return exportF()">
  <input id="text" type="text" />
  <input type="submit" />
</form>

<table id="table" style="display: none">
  <tr>
    <td id="input">
    </td>
  </tr>
</table>


<a style="display: none" id="downloadLink"></a>

Sign up to request clarification or add additional context in comments.

2 Comments

I worked for me. But how i can add one more row in excel sheet.
@user2842328 Add a line in your HTML table with tr tag
0

There are various libraries that allow the generation of .xlsx files, you will need to pick one of them (Google xlsx.js), read out the values in the form on submit and then create the spreadsheet you wish using the library you picked.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.