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

标签 php phpexcel

我通过使用 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/

相关文章:

php - 选择语句无法填充文本框

PHPexcel获取最高工作表索引范围

php - 如何使用 PHPSpreadsheet 在 Excel 上添加新行

php - 使用 phpExcel 库将新行附加到 excel 文件

PHPExcel插入数组公式

phpexcel - 使用PHPExcel读取Excel文件时忽略计算值

php - 如何制作一个php数组

php - 跨多个表的更高效的数据库结构

php - 将数据表的元素存储到数组中

php - 如何一次获取所有选定的 ID? PHP/MySQL 问题