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

the changes which i do #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
43 changes: 43 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
56 changes: 32 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Excel Sheet Generator</title>
<link rel="stylesheet" href="./style.css">
<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">
</head>
<body>
<link rel="stylesheet" href="./style.css" />
<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" />
</head>
<body>
<div class="form">
<h1>Excel Sheet Generator</h1>
<input type="number" class="rows" placeholder="Enter number of rows">
<input type="number" class="columns" placeholder="Enter number of columns">
<div class="btns">
<button onclick="generateTable()">Generate</button>
<button onclick="ExportToExcel('xlsx')">Export</button>
</div>
<h1>Excel Sheet Generator</h1>
<input type="number" class="rows" placeholder="Enter number of rows" />
<input
type="number"
class="columns"
placeholder="Enter number of columns" />
<div class="btns">
<button onclick="generateTable()">Generate</button>
<button onclick="ExportToExcel('xlsx')">Export</button>
</div>
</div>
<div class="table">
<table cellspacing="6px">
<tbody class="sheet-body"></tbody>
</table>
<table cellspacing="6px">
<tbody class="sheet-body"></tbody>
</table>
</div>
</body>
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/xlsx.full.min.js"></script>
<script src="./script.js"></script>
</html>
</body>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script
type="text/javascript"
src="https://unpkg.com/[email protected]/dist/xlsx.full.min.js"></script>
<script src="./script.js"></script>
</html>
55 changes: 32 additions & 23 deletions script.js
Original file line number Diff line number Diff line change
@@ -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<rowsNumber; i++){
var tableRow = ""
for(let j=0; j<columnsNumber; j++){
tableRow += `<td contenteditable></td>`
}
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 += `<td contenteditable></td>`;
}
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')))
}
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"));
};