从excel中读取数据
Posted bandbandme
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从excel中读取数据相关的知识,希望对你有一定的参考价值。
include KIF_PATH . ‘/phpExcel.class.php‘; //$inputFileType = ‘Excel5‘; $inputFileType = ‘Excel2007‘; $filePath = $this->excelFile; $objReader = PHPExcel_IOFactory::createReader($inputFileType); if (!$objReader->canRead($filePath)) { echo ‘error file type‘; exit(); } $objExcel = $objReader->load($filePath); $objSheet = $objExcel->getSheet(0); $allRow = $objSheet->getHighestRow(); $readColumns = array( ‘D‘, // 专柜名称 ‘F‘, // 详细地址 ‘J‘, // 省 ‘K‘, // 市 ‘L‘, // 店铺电话 ); $startRow = 2; for ($currentRow = $startRow; $currentRow <= $allRow; $currentRow++) { $row = $currentRow; $rowStr = ‘‘; foreach ($readColumns as $col) { $value = $objSheet->getCell($col . $row)->getValue(); $value = trim($value); if (strpos($value, ‘,‘) !== false) { $value = str_replace(‘,‘, ‘,‘, $value); echo $value . ‘ has , change to 中文逗号 ‘; echo PHP_EOL; } // 如果有 <202d>, 则表格内是空的 $string = $value; $tmpRes = array(); $length = strlen($string); for ($i = 0; $i < $length; $i++) { $tmpRes[] = ‘0x‘ . strtolower(base_convert(ord($string{$i}), 10, 16));//ord($string[$i]); } $tmpStr = implode(‘‘, $tmpRes); if (strpos($tmpStr, ‘0xe20x800xad‘) !== false) { echo $value . ‘ has special char, will set empty ‘; echo PHP_EOL; $value = ‘‘; } // end foreach ($wordSearch as $search => $replace) { $rowStr = str_replace($search, $replace, $rowStr); } $rowStr = substr($rowStr, 0, -1); echo $rowStr . PHP_EOL; file_put_contents($csvFile, $rowStr . PHP_EOL, FILE_APPEND); }
以上是关于从excel中读取数据的主要内容,如果未能解决你的问题,请参考以下文章