Foros del Web » Programando para Internet » PHP »

PHP OO Descargar Excel en php

Estas en el tema de Descargar Excel en php en el foro de PHP en Foros del Web. Excel en php Buenas estoy tratando de descargar a excel pero necesito que a la hora de descargar se registre la fecha y se cambie ...
  #1 (permalink)  
Antiguo 11/12/2015, 19:52
 
Fecha de Ingreso: noviembre-2015
Mensajes: 21
Antigüedad: 8 años, 5 meses
Puntos: 0
Descargar Excel en php

Excel en php
Buenas estoy tratando de descargar a excel
pero necesito que a la hora de descargar se registre la fecha y se cambie el estado 5 al 6
de todos los registros que descargo



Código PHP:
<?php

require_once('conexion.php');
    
header ("Cache-Control: no-cache, must-revalidate");  
    
header ("Pragma: no-cache");  
    
header ("Content-Type: application/vnd.ms-excel"); 
    
header ("Content-Disposition: attachment; filename=reporte.xls" );

$sql="select * from tbldocumentosicr INNER JOIN tblinfracciones ON tbldocumentosicr.icr_infraccion=tblinfracciones.icr_infraccion where icr_estado='5' order by icr_fecha_ri ASC";

$reg=mysql_query($sql,$cnx);
?>
<table width="100%"  align="center" cellspacing="0">
<tr><td colspan="12"  width="25" align=center><h5>TITULO</h5></td></tr>
 <tr><td colspan="12" width="90" align=center><h5>TITULO </h5></td></tr>
<tr><td colspan="12" width="150" align=center><h5>TITULO PERIODO:</h5></td></tr>

</table>
<table width="100%"  BORDER=3  align="center" cellspacing="0" BORDERCOLOR="#939393" BGCOLOR="FFFFFF">

<tr>
<td width="25" align=center valign="top" BGCOLOR="C1D4D6"><h5>Nª</h5></td>
<td width="90" align=center valign="top" BGCOLOR="C1D4D6"><h5>DEPENDENCIA</h5></td>
<td width="85" align=center valign="top" BGCOLOR="C1D4D6"><b><h5>CODIGO</h5></b></td>
<td width="150" align=center valign="top" BGCOLOR="C1D4D6"><h5>N CUENTA</h5></td>
<td width="230" align=center valign="top" BGCOLOR="C1D4D6"><h5>NOMBRE</h5></td>
<td width="100" align=center valign="top" BGCOLOR="C1D4D6"><h5>CODIGO RESLUCION</h5></td>
<td width="100" align=center valign="top" BGCOLOR="C1D4D6"><h5>FECHA NOTIFICACION</h5></td>
<td width="450" align=center valign="top" BGCOLOR="C1D4D6"><h5>CAUSAL DE INGRESO DE RECAUDACION</h5></td>
<td width="100" align=center valign="top" BGCOLOR="C1D4D6"><h5>TIPO MONTO A TRASLADAR</h5></td>
<td width="90" align=center valign="top" BGCOLOR="C1D4D6"><h5>OBSERVACIONES</h5></td>
<td width="90" align=center valign="top" BGCOLOR="C1D4D6"><h5>PERIODOS DE REVISION</h5></td> 
<td width="90" align=center valign="top" BGCOLOR="C1D4D6"><h5>MONTO A TRASLADAR</h5></td>
 </tr>
<?php
$i
=0;
while(
$res=mysql_fetch_array($reg)){
    
?>
<td width="25" align=center><h5><?php echo $i+1;?></h5></td>
<td width="90"><h5>00<?php echo $res['icr_dependencia'];?></h5></td>
<td width="85" align=center><h5><?php echo $res['icr_codigo'];?></h5></td>
<td width="150"><h5><?php echo $res['icr_cuenta_bn'];?></h5></td>
<td width="230" align=justify><h6><?php echo $res['icr_nombre'];?></h6></td>
<td width="100" align=center><h5>0<?php echo $res['icr_dependencia'];?>024000<?php echo $res['icr_num_resolucion'];?></h5></td>
<td width="100" align=center><h5><?php echo $res['icr_fecha_ri'];?></h5></td>
<td width="450" align=justify><h5><?php echo $res['icr_causal'];?></h5></td>

    <td width="90" align=center>
      <h5>
        <?php if($res["icr_traslado"]==1){?> Saldo Parcial
        <?php }elseif($res["icr_traslado"]==2){?> Saldo Total
        <?php }?>    
        </h5></td>
<td width="90" align=justify><h6><?php echo $res['icr_observaciones_a'];?></h6></td>

<td width="90" align=center>
<?php
date_default_timezone_set
('America/Lima');  
$calendario_meses = array( 
    
'January'=>'Enero'
    
'Febuary'=>'Febrero'
    
'March'=>'Marzo'
    
'April'=>'Abril'
    
'May'=>'Mayo'
    
'June'=>'Junio'
    
'July'=>'Julio'
    
'August'=>'Agosto'
    
'September'=>'Septiembre'
    
'October'=>'Octubre'
    
'November'=>'Noviembre'
    
'December'=>'Diciembre' 
);  

$data1 explode('-'$res['icr_fecha_revision1']);  
$fecha1 date('F \d\e\l Y'strtotime($data1[0] . '-' $data1[1])); 
$fecha1 strtr($fecha1$calendario_meses); 
  
echo 
$fecha1?>  - 

<?php
date_default_timezone_set
('America/Lima');   
$calendario_meses2 = array( 
    
'January'=>'Enero'
    
'Febuary'=>'Febrero'
    
'March'=>'Marzo'
    
'April'=>'Abril'
    
'May'=>'Mayo'
    
'June'=>'Junio'
    
'July'=>'Julio'
    
'August'=>'Agosto'
    
'September'=>'Septiembre'
    
'October'=>'Octubre'
    
'November'=>'Noviembre'
    
'December'=>'Diciembre' 
);  

$data2 explode('-'$res['icr_fecha_revision2']);  
$fecha2 date('F \d\e\l Y'strtotime($data2[0] . '-' $data2[1])); 
$fecha2 strtr($fecha2$calendario_meses2); 
echo 
$fecha2?>
</td>
<td width="90" align=center><h5><?php echo $res['icr_monto_icr'];?></h5></td>
</tr>
    <?php
    $i
=$i+1;
    }
    
?>
</table>
</body>
</html>
  #2 (permalink)  
Antiguo 12/12/2015, 06:12
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: Descargar Excel en php

Al final, ejecutas un UPDATE con los mismos parametros que el select.. y cambias el estado
__________________
>> Eleazan's Source
>> @Eleazan
  #3 (permalink)  
Antiguo 12/12/2015, 17:49
 
Fecha de Ingreso: noviembre-2015
Mensajes: 21
Antigüedad: 8 años, 5 meses
Puntos: 0
Respuesta: Descargar Excel en php

Y como seria eso
porque se tendria que actualizar todos los registros

por ejemplo esta es una forma en como actualizo en uno de mis formularios como haria para agregar el código en el archivo de la descarga

mis campos en mi base de datos son
icr_estado // para cambiar el estado
icr_num_accion // es el codigo unico de cada persona
icr_fecha_reporte // es donde deberia guardar la fecha

el estado deberia cambiar de
icr_estado='5' al
icr_estado='6'


Código PHP:
<?php
require_once('conexion.php');
$num_accion=$_POST['num_accion'];
$estado=$_POST['estado'];
$fecha_ri=$_POST['fecha_ri'];

$sql="update tbldocumentosicr set icr_estado='".$estado."',icr_fecha_ri='".$fecha_ri."' 
where icr_num_accion="
.$num_accion;
$res=mysql_query($sql,$cnx);
?>
<center> Guardado correctamente</center>
<script language="JavaScript" type="text/javascript">
var pagina="listar_icr.php"
function redireccionar() 
{
location.href=pagina

setTimeout ("redireccionar()", 2000);
</script>
  #4 (permalink)  
Antiguo 12/12/2015, 17:50
 
Fecha de Ingreso: noviembre-2015
Mensajes: 21
Antigüedad: 8 años, 5 meses
Puntos: 0
Respuesta: Descargar Excel en php

Y como seria eso
porque se tendria que actualizar todos los registros

por ejemplo esta es una forma en como actualizo en uno de mis formularios como haria para agregar el código en el archivo de la descarga

mis campos en mi base de datos son
icr_estado // para cambiar el estado
icr_num_accion // es el codigo unico de cada persona
icr_fecha_reporte // es donde deberia guardar la fecha

el estado deberia cambiar de
icr_estado='5' al
icr_estado='6'


Código PHP:
<?php
require_once('conexion.php');
$num_accion=$_POST['num_accion'];
$estado=$_POST['estado'];
$fecha_ri=$_POST['fecha_ri'];

$sql="update tbldocumentosicr set icr_estado='".$estado."',icr_fecha_ri='".$fecha_ri."' 
where icr_num_accion="
.$num_accion;
$res=mysql_query($sql,$cnx);
?>
<center> Guardado correctamente</center>
<script language="JavaScript" type="text/javascript">
var pagina="listar_icr.php"
function redireccionar() 
{
location.href=pagina

setTimeout ("redireccionar()", 2000);
</script>
  #5 (permalink)  
Antiguo 14/12/2015, 02:17
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 16 años
Puntos: 326
Respuesta: Descargar Excel en php

Si no me equivoco, en el select, pillas todos los que tienen estado 5, no?


Pues haces un

UPDATE table SET estado=6 WHERE estado=5

Por ejemplo! ;)

Otra opcion, es guardar el "num_accion" (que imagino que será unico), y despues hacerlo con un in

UPDATE table SET estado=6 WHERE num_accion IN (1,2,3,4,5.... blabla)
__________________
>> Eleazan's Source
>> @Eleazan

Etiquetas: excel, fecha, html, registro, select, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:02.