21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
setlocale(LC_ALL, 'zh_CN');
$row = 1;
$handle = fopen("xxx.csv","r");
while ($data = fgetcsv($handle, 1000, ",")) {
$num = count($data);
echo "<p> $num fields in line $row: <br>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br>\n";
}
}
fclose($handle);
?>
<?php
$workbook = "D:\\www\\xtwh\\B01\\mysingle.xls";
$sheet = "list";
#实例化一个组件的对象
$ex = new COM("Excel.sheet") or Die ("Did not connect");
#打开工作本使我们可使用它
$wkb = $ex->application->Workbooks->Open($workbook) or Die ("Did not open");
#读单元格数据
$sheets = $wkb->Worksheets($sheet); #Select the sheet
$sheets->activate; #Activate it
//$cell->activate; #Activate the cell .If this, you can modify the cell data.
for($i=2;$i<=2501;$i++)
{
$a=$sheets->Cells($i,A); if($a->value == "last") break;
$b=$sheets->Cells($i,B); $bp[]=$b->value;
$c=$sheets->Cells($i,C); $cp[]=$c->value;
$d=$sheets->Cells($i,D); $dp[]=$d->value;
$e=$sheets->Cells($i,E); $ep[]=$e->value;
$f=$sheets->Cells($i,F); $fp[]=$f->value;
$g=$sheets->Cells($i,G); $gp[]=$g->value;
$h=$sheets->Cells($i,H); $hp[]=$h->value;
}
$ex->application->ActiveWorkbook->Close("False");
unset ($ex);
require_once("../../conn.php");
$sql0="DELETE FROM `newyonghu`";
$result0=mysql_query($sql0,$mylink);
mysql_free_result($result0);
for($i=0;$i<count($bp);$i++)
{
$sql="INSERT INTO `newyonghu` (`name`, `dept`, `team`, `group01`, `position`, `mingzi`, `single`, `info`) VALUES ('".$bp[$i]."', '".$fp[$i]."', '".$dp[$i]."', '".$ep[$i]."', '".$gp[$i]."', '".$cp[$i]."', '".$hp[$i]."', 'single');";
$result=mysql_query($sql,$mylink);
}
echo "<script language=\"Javascript\">";
echo "window.close()";
echo "</script>";
mysql_free_result($result); //释放结果内存资源
mysql_close($mylink); // 断开连接
?>