Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do-not-Generate-with-empty-fildes #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bitter:wght@500&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
</head>
<body>
<div class="form">
41 changes: 28 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
let table = document.getElementsByClassName("sheet-body")[0],
rows = document.getElementsByClassName("rows")[0],
columns = document.getElementsByClassName("columns")[0]
tableExists = false
columns = document.getElementsByClassName("columns")[0],
tableExists = false;

const generateTable = () => {
let rowsNumber = parseInt(rows.value), columnsNumber = parseInt(columns.value)
let rowsNumber = parseInt(rows.value),
columnsNumber = parseInt(columns.value);
table.innerHTML = ""
for(let i=0; i<rowsNumber; i++){
var tableRow = ""
var tableRow = "";
for(let j=0; j<columnsNumber; j++){
tableRow += `<td contenteditable></td>`
tableRow += `<td contenteditable></td>`;
}
table.innerHTML += tableRow
table.innerHTML += tableRow;
}
if(rowsNumber>0 && columnsNumber>0){
tableExists = true
tableExists = true;
}
else{
Swal.fire({
icon: 'error',
title: 'Not Allowed',
text: 'Please enter the number of rows and columns.',
confirmButtonText: 'Try again'
});
}
}

const ExportToExcel = (type, fn, dl) => {
if(!tableExists){
return
if(tableExists){
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')));
}else {
Swal.fire({
icon: 'error',
title: 'Not Allowed',
text: 'Please Generate a table before Exporting.',
confirmButtonText: 'Generate first'
})
}
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')))
}