export excel second
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user