1
我目前正在进行一项任务,我需要循环访问excel的大文件。我正在使用phpexcel进行此项工作。我在这个项目phpexcel选择表和列
的问题是,当我加载文件,我得到内存已满错误的两个问题。即便 同时使用
setActiveSheetIndex('')
功能,我想读 由表的代码表,但在我不能。我拿起仅选定列不整行所需要的,我 试图实现phpexcel用户手册所示的例子,但 都未能做到这一点,我要实现这个减少 处理时间 。
这里是我使用
set_time_limit (6000);
require_once('classes/phpexcel.php');
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("2.xlsx");
$objWorksheet = $objPHPExcel->setActiveSheetIndex('0') ;
$i=0;$dum=false;$sum=0;
foreach ($objWorksheet->getRowIterator() as $row)
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
if($dum) //to ignore first cell
{ .
foreach ($cellIterator as $cell)
{ if($i==2||$i==3||$i==4||$i==9)
{
if($i==2)
{
$value[$i]=$cell->getValue();
$num1=$value[$i]; // get the starting date and time
}
if($i==3)
{
$value[$i]=$cell->getValue();
$num2=$value[$i]; // get the ending date and time
}
if($i==4)
{
$value[$i]=$cell->getValue();
$asd=preg_split('#(?=\d)(?<=[a-z])#i',$value[$i]); //convert strings as asd12321 to asd , 12321
$value[$i]=$asd[1]; // to read only digit
}
if($i==9)
{
$value[$i]=$cell->getValue(); // read a string
$value[$i+1]=$num2-$num1; //to take diff in minutes between the two
}
}$i++;
}$i=0;
$con = mysql_connect("localhost","root","");
if (!$con)
{$value[0]=$value[2];
die('Could not connect: ' . mysql_error());
}mysql_select_db("mobilink", $con);
$sql="INSERT INTO my query ....";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$sum++;
mysql_close($con);
}
$dum=true;
}
我要读只有特定的列,因为我有在文件中共有26列,而我只需要4码。帮助将不胜感激