2
I am trying to print to excel a query presented in table with php and jquery in tag <tbody>
. However it did not work. It presented in excel a wrong result with all the result HTML in a single cell. COULD HELP ME?
I found the solution on the site http://nice-tutorials.blogspot.com.br/2011/06/export-to-excel-in-php-with-jquery.html
HTML and PHP
<form action="frameworks/teste.php" method="post"
onsubmit='$("#datatodisplay").val( $("<div>").append( $("#minhaTabela").eq(0).clone() ).html() )'>
<table id="minhaTabela" class="table table-striped">
<thead>
<th>DM Clarity</th>
<th>Mantis</th>
<th>Sistema</th>
<th>Descrição</th>
<th>Situação</th>
<th>Prioridade</th>
<th>Previsão Homol.</th>
<th>Ações</th>
</thead>
<tbody>
</tbody>
</table>
<div align="center">
<input type="hidden" id="datatodisplay" name="datatodisplay">
<button type="submit" class="btn btn-primary">Export to Excel</button>
</div>
</form>
<?php
header('Content-Type: application/force-download');
header('Content-disposition: attachment; filename=export.xls');
// Fix for crappy IE bug in download.
header("Pragma: ");
header("Cache-Control: ");
echo $_REQUEST['datatodisplay'];
?>