我通过使用 php 脚本提交“提交按钮”上传了 excel 并且数据已成功插入到数据库中。我要做的最后一个阶段是在将数据插入数据库之前验证 excel。我对验证一无所知。
在我的 excel 中,我应该验证第一行应该包含“以下标题”(即数字、标记、等级、注意等),然后从第二行开始,PHP 脚本应该检查(验证)这些值(number应该只有8位,marks应该<=3digits,grade应该是1digit,attention应该<=2digits,最后是空行)最后应该成功插入到数据库中。我如何使用 PHP 脚本验证 excel 行和列?
我正在使用 PHP Excel 库读取电子表格数据
提前致谢
最佳答案
你可以使用下面的代码来完成
$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(); }
希望对你有帮助
关于php - 使用 PHP Excel 进行电子表格标题行数据验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24756069/