Skip to content

Commit

Permalink
download option available now
Browse files Browse the repository at this point in the history
  • Loading branch information
that-ar-guy committed Jun 3, 2024
1 parent f4859f9 commit 3e63b7c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
Binary file modified resultapp/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified resultapp/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file modified resultapp/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file modified resultapp/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified resultapp/__pycache__/views.cpython-311.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion resultapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from django.contrib import admin

# Register your models here.
45 changes: 44 additions & 1 deletion resultapp/templates/resultapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@
font-size: 25px;
text-align: center;
}
button.download-btn {
background-color: #4285f4;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
transition: background-color 0.3s ease;
}

button.download-btn:hover {
background-color: #357ae8;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>
Expand Down Expand Up @@ -190,7 +204,7 @@ <h1>OSMANIA UNIVERSITY RESULTS</h1>
<th>Backlogs</th>
</tr>
</thead>
<tbody>
<tbody id="resultsTable">
{% for result in results %}
{% if result.hall_ticket and result.marks and result.name and result.backlogs %}
<tr>
Expand All @@ -203,6 +217,7 @@ <h1>OSMANIA UNIVERSITY RESULTS</h1>
{% endfor %}
</tbody>
</table>
<button class="download-btn" onclick="downloadXLSX('results.xlsx')">Download as Excel Sheet</button>
{% endif %}


Expand All @@ -217,6 +232,34 @@ <h1>OSMANIA UNIVERSITY RESULTS</h1>
document.getElementById("mySidebar").style.width = "0";
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.0/xlsx.full.min.js"></script>
<script>
function downloadXLSX(filename) {
let table = document.getElementById("resultsTable");
if (!table) {
console.error("Table not found!");
return;
}
let sheetName = document.getElementById("heading").innerText.trim();
const wb = XLSX.utils.table_to_book(table, { sheet: sheetName });

// Get the first sheet and set cell styles
const ws = wb.Sheets[sheetName];
const range = XLSX.utils.decode_range(ws['!ref']);

for (let C = range.s.c; C <= range.e.c; ++C) {
for (let R = range.s.r; R <= range.e.r; ++R) {
const cell_address = {c: C, r: R};
const cell_ref = XLSX.utils.encode_cell(cell_address);
if (!ws[cell_ref]) continue;
if (!ws[cell_ref].s) ws[cell_ref].s = {};
ws[cell_ref].s.alignment = { wrapText: true };
}
}

XLSX.writeFile(wb, filename);
}
</script>
<footer>
made by <a href="https://github.com/that-ar-guy">AR</a>
</footer>
Expand Down

0 comments on commit 3e63b7c

Please sign in to comment.