diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..2bd90b5 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,43 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + # Upload entire repository + path: '.' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/README.md b/README.md index cf820c2..df35580 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,10 @@ hello there, your task is to use sweetalert.js to display an alert when the user fork the repository and start working on it. best of luck. + + +the changes i did +1.add sweetalert library to html file +2. add function make alert if the input value isnot number or empty when click the generate button +3. add function make alert if the input values lower than 1 when click the export button +https://mostafashehata0.github.io/excel-sheet-generator/ diff --git a/index.html b/index.html index 7445a44..c7229e1 100644 --- a/index.html +++ b/index.html @@ -1,31 +1,39 @@ - - - - + + + + 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..778f4c6 100644 --- a/script.js +++ b/script.js @@ -1,29 +1,38 @@ 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 + let rowsNumber = parseInt(rows.value), + columnsNumber = parseInt(columns.value); + if (isNaN(rowsNumber) || isNaN(columnsNumber)) { + swal("Error", "Please enter valid numbers for rows and columns!", "error", { + button: "OK", + }); + return; + } + table.innerHTML = ""; + for (let i = 0; i < rowsNumber; i++) { + var tableRow = ""; + for (let j = 0; j < columnsNumber; j++) { + tableRow += ``; } - if(rowsNumber>0 && columnsNumber>0){ - tableExists = true - } -} + 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("Error", "Please generate a table before exporting!", "error"); + 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")); +};