读取文件
private function import($filepath)
{
$this->ci->load->library('PHPExcel');
$PHPReader = new PHPExcel_Reader_Excel5();
$PHPExcel = $PHPReader->load($filepath);
/**读取excel文件中的第一个工作表*/
$currentSheet = $PHPExcel->getSheet(0);
/**取得最大的列号*/
$allColumn = $currentSheet->getHighestColumn();
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
/**从第二行开始输出,因为excel表中第一行为列名*/
for($currentRow = 2;$currentRow <= $allRow;$currentRow++) {
/**ord()将字符转为十进制数*/
$valA= $currentSheet->getCellByColumnAndRow(ord('A') - 65,$currentRow)->getValue();
$valB = $currentSheet->getCellByColumnAndRow(ord('B') - 65,$currentRow)->getValue();
$valC = $currentSheet->getCellByColumnAndRow(ord('C') - 65,$currentRow)->getValue();
// 新增
action code...
}
}
phpexcel - 简单使用 - excel导入
最新推荐文章于 2022-04-22 14:25:07 发布