function saveBook() {
const name = document.getElementById('name').value;
const lastName = document.getElementById('lastName').value;
if (!name || !lastName) {
return;
}
// A multidimensional array represents the data.
// Each array is a new row and each item on the
// array is a different column (cell).
const data = [
// A B
["Name", "Last Name"], // Row 1
[name, lastName] // Row 2
// Row N
];
// Creates the sheet data
const ws = XLSX.utils.aoa_to_sheet(data);
// Create a new book where to append the data.
const wb = XLSX.utils.book_new();
// Append the sheet (second param) to the book (first param)
// with the specified name (third param)
XLSX.utils.book_append_sheet(wb, ws, "Test Sheet");
// This is the instruction that tells the browser to
// "download" the file
XLSX.writeFile(wb, 'book.xlsx');
}
document.querySelector('#saveBook').onclick = saveBook;
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.