Programación Web y Scripting > PHP
como generar una tabla generada en Excel en PHP?
(1/1)
gokufast:
Hola amigos, aca acudiendo a ustedes para que me puedan iluminar para resolver este problema.
tengo la siguiente tabla, que esta generada en excel y la tengo que programar con PHP.
(http://desmond.110mb.com/tabla.jpg)
Tengo el siguiente codigo:
--- Código: PHP ---$cuota_mes = 661.66;$monto = 11188;$interes_mes_1 = $monto*(8/1200);$amortizacion_mes_1 = $cuota_mes - $interes_mes_1;$acumulada_mes_1 = $amortizacion_mes_1;$pendiente_mes_1 = $monto - $amortizacion_mes_1;$meses = 18; echo "<table border='1'>";echo "<tr>";echo "<td width='120' align='center' rowspan='2'>Numero</td>";echo "<td width='120' align='center' rowspan='2'>Amortización Mes</td>";echo "<td width='80' align='center' rowspan='2'>Interes Mes</td>";echo "<td width='80' align='center' rowspan='2'>Total Mes</td>";echo "<td colspan='2' align='center'>Amortización</td>";echo "<tr>";echo "<td width='80' align='center'>Acumulada</td>";echo "<td width='80' align='center'>Pendiente</td>";echo "</tr>";echo "</tr>";echo "<tr>";for($x=1;$x<=5;$x++){ $interes_mes_1 = $monto*(8/1200); $amortizacion_mes_1 = $cuota_mes - $interes_mes_1; $acumulada_mes_1 = $amortizacion_mes_1; $pendiente_mes_1 = $monto - $amortizacion_mes_1; echo "<td>".$x."</td>"; echo "<td>".number_format($amortizacion_mes_1,2)."</td>"; echo "<td>".number_format($interes_mes_1,2)."</td>"; echo "<td>".number_format($cuota_mes,2)."</td>"; echo "<td>".number_format($acumulada_mes_1,2)."</td>"; echo "<td>".number_format($pendiente_mes_1,2)."</td>"; echo "<tr>"; for ($y=1;$y<=2;$y++) { $interes_mes_2 = $pendiente_mes_1 * (8/1200); $amortizacion_mes_2 = $cuota_mes - $interes_mes_2; $acumulada_mes_2 = $amortizacion_mes_1 + $amortizacion_mes_2; $pendiente_mes_2 = $pendiente_mes_1 - $amortizacion_mes_2; echo "<td></td>"; echo "<td>".number_format($amortizacion_mes_2,2)."</td>"; echo "<td>".number_format($interes_mes_2,2)."</td>"; echo "<td>".number_format($cuota_mes,2)."</td>"; echo "<td>".number_format($acumulada_mes_2,2)."</td>"; echo "<td>".number_format($pendiente_mes_2,2)."</td>"; echo "</tr>"; } echo "</tr>";}echo "</tr>";echo "</table>"
pero solo saco las 2 primeras filas, y al querer sacar las demas "jalando" los valores del for con Y al for con X no me
jalan los datos, osea al poner [php:ipa0bzmy]echo $pendiente_mes_2;[/php:ipa0bzmy] en el primer for no me sale nada por ende no puedo sacar los demas calculos.
esta bien que use los for? o debo usar otro bucle? o como puedo hacer para generar esto?
les agradeceria mucho la ayuda que puedan darme, gracias.
ahh me olvidaba, tendria que ser para 18 filas o meses como para 5 o para 30 etc, dependiendo del usuario. osea el
x<=$meses.
RadicalEd:
De dónde tomas esos datos, de una tabla, de ese archivo de Excel???
Si es para lo primero con un mysql_fetch_array y un ciclo te mola.
Si es para lo segundo, revisa este enlace http://www.cristalab.com/tips/abrir-y-l ... p-c38945l/
gokufast:
bueno con algo de ayuda lo resolvi de la siguiente forma:
--- Código: PHP ---<?$cuota_mes = 661.66;$monto = 11188;$interes_mes_1 = $monto*(8/12/100);$amortizacion_mes_1 = $cuota_mes - $interes_mes_1;$acumulada_mes_1 = $amortizacion_mes_1;$pendiente_mes_1 = $monto - $amortizacion_mes_1;$meses = 18;?><table width="361" border="0" cellspacing="2" cellpadding="1"> <tr> <td width="295"><div align="right" class="style2">MONTO</div></td> <td width="56"><div align="right" class="style2"><? echo $monto; ?></div></td> </tr> <tr> <td width="295"><div align="right" class="style2">INTERES MENSUAL </div></td> <td width="56"><div align="right" class="style2"><? echo number_format($interes_mes_1,2); ?></div></td> </tr> <tr> <td width="295"><div align="right" class="style2">TIEMPO DE PAGO EN MESES </div></td> <td width="56"><div align="right" class="style2"><? echo $meses; ?></div></td> </tr> <tr> <td width="295"><div align="right" class="style2">CUOTA MES EN USD </div></td> <td width="56"><div align="right" class="style2"><? echo $cuota_mes; ?></div></td> </tr></table><br /><table width="600" border="1" cellspacing="1" cellpadding="1"> <tr> <td width="33"><div align="center"><span class="style1"></span></div></td> <td width="110"><div align="center" class="style1"><strong>AMORTIZACION</strong></div></td> <td width="110"><div align="center" class="style1"><strong>INTERES</strong></div></td> <td width="110"><div align="center" class="style1"><strong>TOTAL</strong></div></td> <td colspan="2"><div align="center" class="style1"><strong>AMORTIZACION</strong></div></td> </tr> <tr> <td width="33"><div align="center" class="style1"><strong>nro</strong></div></td> <td width="110"><div align="center" class="style1"><strong>MES</strong></div></td> <td width="110"><div align="center" class="style1"><strong>MES</strong></div></td> <td width="110"><div align="center" class="style1"><strong>MES</strong></div></td> <td width="110"><div align="center" class="style1"><strong>ACUMULADA</strong></div></td> <td width="110"><div align="center" class="style1"><strong>PENDIENTE</strong></div></td> </tr> <? $amort=0; $inter=0; $cuota=0; $acumu=0; $pendi=$monto;for($x=0;$x<=$meses;$x++){ ?> <tr> <td width="33"> <span class="style2"><? echo $x;?></span></td> <td width="110"><span class="style2"><? echo number_format($amort,2); ?></span></td> <td width="110"><span class="style2"><? echo number_format($inter,2); $inter=$pendi*8/12/100;?></span></td> <td width="110"><span class="style2"><? echo number_format($cuota,2); $cuota=$cuota_mes*1;?></span></td> <td width="110"><span class="style2"><? echo number_format($acumu,2); ?></span></td> <td width="110"><span class="style2"><? echo number_format($pendi,2); $amort=$cuota-$inter; $pendi=$pendi-$amort; $acumu=$acumu+$amort;?></span></td> </tr> <? } ?></table></body>
Navegación
Ir a la versión completa