diff --git a/index.html b/index.html index 7445a44..7c8ad60 100644 --- a/index.html +++ b/index.html @@ -1,31 +1,38 @@ - - - - - Excel Sheet Generator - - - - - - -
-

Excel Sheet Generator

- - -
- - + + + + + Excel Sheet Generator + + + + + + +
+

Excel Sheet Generator

+ + +
+ + +
-
-
- - -
-
- - - +
+ + +
+
+ + + + + \ No newline at end of file diff --git a/script.js b/script.js index bb93c4d..cc2dee6 100644 --- a/script.js +++ b/script.js @@ -1,29 +1,42 @@ +// swal("Hello world!"); + let table = document.getElementsByClassName("sheet-body")[0], -rows = document.getElementsByClassName("rows")[0], -columns = document.getElementsByClassName("columns")[0] -tableExists = false + rows = document.getElementsByClassName("rows")[0], + columns = document.getElementsByClassName("columns")[0]; +tableExists = false; const generateTable = () => { - let rowsNumber = parseInt(rows.value), columnsNumber = parseInt(columns.value) - table.innerHTML = "" - for(let i=0; i` - } - table.innerHTML += tableRow - } - if(rowsNumber>0 && columnsNumber>0){ - tableExists = true + let rowsNumber = parseInt(rows.value), + columnsNumber = parseInt(columns.value); + console.log("start table"); + // check if fields empty + if (!rowsNumber || !columnsNumber || rowsNumber < 0 || columnsNumber < 0) { + swal("fields must not be empty and greater than 0"); + return; + } + + // render and generate table + table.innerHTML = ""; + for (let i = 0; i < rowsNumber; i++) { + var tableRow = ""; + for (let j = 0; j < columnsNumber; j++) { + tableRow += ``; } -} + table.innerHTML += tableRow; + } + if (rowsNumber > 0 && columnsNumber > 0) { + tableExists = true; + } +}; const ExportToExcel = (type, fn, dl) => { - if(!tableExists){ - return - } - var elt = table - var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" }) - return dl ? XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) - : XLSX.writeFile(wb, fn || ('MyNewSheet.' + (type || 'xlsx'))) -} \ No newline at end of file + if (!tableExists) { + swal("table not exists"); + return; + } + var elt = table; + var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" }); + return dl + ? XLSX.write(wb, { bookType: type, bookSST: true, type: "base64" }) + : XLSX.writeFile(wb, fn || "MyNewSheet." + (type || "xlsx")); +};