Reputation: 1044
I have HTML table that i want to export as excel , that works!
I needed to show total value of one column on top of the page (and it works on browser) i did it with jQuery.
Here is were i add total value:
echo '<p style="display:inline-block;" class="total-title"></p>';
Here is how i add value:
<script>
$(document).ready(
function() {
$('p.total-title').html(' total: <?=$total;?>');
}
);
</script>
And here are my headers:
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=print_report(".date('Y-m-d').").xls");
header("Pragma: no-cache");
header("Expires: 0");
header('Content-Description: File Transfer');
header("Content-type: application/vnd.ms-excel");
All other data is exported but just this jQuery added content is not showing!
Why it works when i remove headers? And why could it not work in export?
What possible fixes are here?
Thanks
Upvotes: 0
Views: 341
Reputation: 1044
After talking with @MohitKumar and @FedericoklezCulloca i tied to do it like this:
$table = '<table>';
$table .= '<thead>';
$table .= '<tr>';
$table .= '<th>product</th>';
$table .= '<th>value</th>';
$table .= '</tr>';
$table .= '</thead>';
$table .= '<tbody>';
$result = mysqli_query($conn, "SELECT product, value FROM my_table");
while($row = mysqli_fetch_array($result)){
$table .= '<tr>';
$table .= '<td>'.$row['product'].'</td>';
$table .= '<td>'.$row['value'].'</td>';
$table .= '</tr>';
$abAmount += $row['value'];
}
$table .= '</tbody>';
$table .= '</table>';
echo '<br>THAT VALUE HERE: '.$abAmount.'<br>';
echo $table;
And it did work!
Upvotes: 2