码迷,mamicode.com
首页 > 其他好文 > 详细

从excel中读取数据

时间:2019-12-23 13:37:57      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:this   adc   put   电话   ror   cto   length   名称   load   

 

 

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中读取数据

标签:this   adc   put   电话   ror   cto   length   名称   load   

原文地址:https://www.cnblogs.com/bandbandme/p/12083092.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!