使用PHP Excel验证电子表格标题行数据

使用PHP Excel验证电子表格标题行数据,php,phpexcel,Php,Phpexcel,我上传了excel,通过使用php脚本提交“提交按钮”,数据成功插入数据库。我要做的最后一个阶段是在将数据插入数据库之前验证excel。我对验证没有任何想法 在我的excel中,我应该验证第一行应该包含“以下标题”(即数字、分数、等级、注意等),然后从第二行开始,PHP脚本应该检查(验证)值(数字应该只有8位,分数应该,您可以使用以下代码 $objReader = PHPExcel_IOFactory::load($filename); $objWorksheet = $objReade

我上传了excel,通过使用php脚本提交“提交按钮”,数据成功插入数据库。我要做的最后一个阶段是在将数据插入数据库之前验证excel。我对验证没有任何想法


在我的excel中,我应该验证第一行应该包含“以下标题”(即数字、分数、等级、注意等),然后从第二行开始,PHP脚本应该检查(验证)值(数字应该只有8位,分数应该,您可以使用以下代码

$objReader = PHPExcel_IOFactory::load($filename); $objWorksheet = $objReader->getActiveSheet(); //This will fetch the first row $row = $objWorksheet->getRowIterator(1)->current(); $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); //You can loop through the columns to see the data and match it with your some predefined array of headings. foreach ($cellIterator as $cell) { echo $cell->getValue(); } $objReader=PHPExcel\u IOFactory::load($filename); $objWorksheet=$objReader->getActiveSheet(); //这将获取第一行 $row=$OBJWORKS->getRowIterator(1)->current(); $cellIterator=$row->getCellIterator(); $cellIterator->setiterateonleyexistingcells(false); //您可以在列中循环查看数据,并将其与预定义的标题数组相匹配。 foreach($cellIterator作为$cell){ echo$cell->getValue(); } 希望这有帮助