1
I need to export specific content to XLS within the administrative area, and am using the following code:
$arquivo = 'planilha.xls';
$html = '';
$html .= '<table>';
$html .= '<tr>';
$html .= '<td colspan="3">Planilha teste</tr>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td><b>Coluna 1</b></td>';
$html .= '<td><b>Coluna 2</b></td>';
$html .= '<td><b>Coluna 3</b></td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>L1C1</td>';
$html .= '<td>L1C2</td>';
$html .= '<td>L1C3</td>';
$html .= '</tr>';
$html .= '<tr>';
$html .= '<td>L2C1</td>';
$html .= '<td>L2C2</td>';
$html .= '<td>L2C3</td>';
$html .= '</tr>';
$html .= '</table>';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=\"{$arquivo}\"" );
header ("Content-Description: PHP Generated Data" );
echo $html;
exit;
But when I run this code on a admin page, it ends up exporting other content than the variable value $html
, as menus and admin links within the XLS file.
How to insert only the content returned by the variable $html
in the generated XLS file?
I was able to solve it by combining my code with this example here: http://wordpress.stackexchange.com/questions/144156/create-dynamic-wordrpess-blank-page?answertab=oldest#tab-top
– robssanches
Hi, Robson, can please post a reply, so help others who do not speak English. I also have a similar script: How to export comments in Wordpress?
– brasofilo
Hello brasofilo, you say publish a reply with the full code, showing how I managed to solve my problem?
– robssanches
In fact, your question is here without an answer/solution published below. It is nice for those who visit Sopt to see the solution right here. And as you mention that solved the problem, it is good practice to answer the question itself, so in addition to getting help for your questions, you also contribute with the site :)
– brasofilo
Got it... okay, I’ll post the full code.
– robssanches