Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Excel to MySQL (https://www.clubdelphi.com/foros/showthread.php?t=80846)

dec 26-11-2007 11:17:14

Excel to MySQL
 
Acá les dejo un código que hice para migrar datos de excel hacia una BD en MySQL con PHP...

error_reporting(0);
if (isset($_POST['xls']))
{
$xls = new COM("Excel.Application") or die("Excel");
$xls->Workbooks->Add;
try { $xls->Workbooks->Open($_POST['xls']); }
catch (exception $e) { $xls->Quit; unset($xls); }
}

if (!isset($xls)) die("<form method=post action=\"$_SERVER[PHP_SELF]\">Enter password:
<input type=password width=6 name=pwd><input type=file name=xls style=\"width:0px;height:20px;border:0px\"
onchange=\"this.form.submit()\">");
$db =& mysql_connect('localhost', 'root', $_POST['pwd']) or die('<script>history.go(-1)</script>'); ?>

<html><body><table border=1 style="border-collapse:collapse">

<?php define('y', 10); define('x', 10); //26
mysql_query('drop database xls', $db);
mysql_query('create database xls', $db);
$query = ''; for ($x = 0; $x < x; $x++) $query .= chr(65 + $x) . 'x char(32),';
mysql_query('create table xls.sheet (' . substr($query, 0, -1) . ')', $db);

for ($y = 1; $y <= y; $y++)
{
echo " <tr>\n"; $row = '';
for ($x = 1; $x <= x; $x++)
{
$cell = $xls->Cells($y, $x);
echo " <td align=center>$cell</td>\n";
$row .= "'$cell',";
}
mysql_query('insert into xls.sheet values(' . substr($row, 0, -1) . ')', $db);
echo " </tr>\n";
}

mysql_close($db);
$xls->Quit;

</table></body></html>

PD. Hay algún problema al tratar de incluir el código fuente entre etiquetas CODE, por ejemplo. Por favor, copiad el códifo fuente tal cual os lo presento, y, recordad, hablamos de PHP.


La franja horaria es GMT +2. Ahora son las 01:57:13.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi