
Exportar tabla html a excel
Publicado por jmuoz (21 intervenciones) el 14/04/2014 22:47:52
Buenas tardes tengo un problema con un codigo ya que necesito exportar una tabla de html a excel con un button pero al momento que mando a llamar al codigo en el input me da como resultado un doc excel sin nada y deberia de mandarlo con info, pero si junto el archivo en la cabecera del Inicio.php si me exporta el excel pero como tengo una lista desplegable cada vez que selecciono alguna opcion descarga sin mostrarme en pantalla la info de la tabla pero si me exporta el contenido de la tabla quizas algo me esta fallando espero me puedan asesorar, dejo el ejemplo
Inicio.php
export.php
Inicio.php
1
2
3
4
5
6
7
8
9
10
11
12
<form>
<select name="lista" onChange="this.form.submit()" >
<?php
asort($filelist);
echo "<option >-----Selecciona Archivo------</option>";
while (list ($key, $val) = each ($filelist)){
echo "<option value='$val'>$val</option>";
}
?>
</select>
<input type="button" onclick="window.location='genera.php'" value="Exportar">
</form>
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
$dia=date('d_m_Y');
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: attachment; filename=reporte_$fecha.xls");
header('Pragma: public');
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Pragma: no-cache');
header('Expires: 0');
header('Content-Transfer-Encoding: none');
//header('Content-type: application/vnd.ms-excel;charset=utf-8');// This should work for IE & Opera
header('Content-type: application/x-msexcel; charset=utf-8'); // This should work for the rest
header("Content-Disposition: attachment; filename=reporte_$dia.xls");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
?>
Valora esta pregunta


0