export excel second

This commit is contained in:
2024-09-30 17:25:58 +05:45
parent 4683fe67a7
commit ec6bfaf7ff
3 changed files with 46 additions and 11 deletions

View File

@ -17,7 +17,7 @@ $PL = $IncomesTotal - $ExpensesTotal;
<h5 class="m-0"><?php echo $pageTitle; ?> </h5>
</div>
<div class="card-body">
<table class="table table-bordered table-hover">
<table id='myTable'class="table table-bordered table-hover">
<thead>
<tr>
<th colspan="4">Profit & Loss Statement</th>
@ -95,7 +95,7 @@ $PL = $IncomesTotal - $ExpensesTotal;
{
$total = 0;
?>
<table class="table table-bordered table-hover">
<table id='myTable' class="table table-bordered table-hover">
<thead>
<tr>
<th>Account</th>
@ -121,6 +121,41 @@ $PL = $IncomesTotal - $ExpensesTotal;
</tr>
</tfoot> -->
</table>
<!-- pdf document -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
document.getElementById('downloadCsv').addEventListener('click', function() {
const table = document.getElementById('myTable');
const rows = Array.from(table.rows);
const data = [];
rows.forEach((row) => {
const cells = Array.from(row.cells);
const rowData = [];
cells.forEach((cell) => {
// Handle colspan
const colspan = cell.colSpan || 1;
for (let i = 0; i < (colspan - 1); i++) {
rowData.push(''); // Fill empty cells for merged columns
}
for (let i = 0; i < 1; i++) {
rowData.push(cell.innerText.trim());
}
// Fill empty cells for colspan
});
data.push(rowData);
});
// Create a worksheet
const worksheet = XLSX.utils.aoa_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
// Export to Excel
XLSX.writeFile(workbook, 'table.xlsx');
});
</script>
<!-- pdf document ends-->
<?php
}