当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPExcel_Reader_Excel2007::canRead方法代码示例

本文整理汇总了PHP中PHPExcel_Reader_Excel2007::canRead方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Reader_Excel2007::canRead方法的具体用法?PHP PHPExcel_Reader_Excel2007::canRead怎么用?PHP PHPExcel_Reader_Excel2007::canRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPExcel_Reader_Excel2007的用法示例。


在下文中一共展示了PHPExcel_Reader_Excel2007::canRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _getReadFileObj

 /**
  * 获取可以读取类的phpexcel对象
  * @return PHPExcel_Reader_Excel2007
  */
 private function _getReadFileObj()
 {
     self::getInstance2007();
     if (!self::$_excelObj2007->canRead($this->_filePath)) {
         self::getInstance5();
         if (!self::$_execelObj5->canRead($this->_filePath)) {
             return false;
         } else {
             $this->_instance = self::$_execelObj5;
         }
     } else {
         $this->_instance = self::$_excelObj2007;
     }
 }
开发者ID:huangwei2wei,项目名称:kfxt,代码行数:18,代码来源:Excel.class.php

示例2: reader

 public function reader($filePath = null, $index = 2)
 {
     if ($filePath == null) {
         $filePath = $_FILES['file']['tmp_name'];
     }
     $PHPReader = new PHPExcel_Reader_Excel2007();
     if (!$PHPReader->canRead($filePath)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($filePath)) {
             return 'no Excel';
         }
     }
     $PHPExcel = $PHPReader->load($filePath);
     $rows = array();
     $sheet = $PHPExcel->getSheet(0);
     $allColumn = $sheet->getHighestColumn();
     $allRow = $sheet->getHighestRow();
     $allCell = $this->AT[$allColumn];
     for ($row = $index; $row <= $allRow; $row++) {
         $arr = array();
         for ($cell = 0; $cell <= $allCell; $cell++) {
             $val = $sheet->getCellByColumnAndRow($cell, $row)->getValue();
             $arr[$this->A[$cell]] = $val;
         }
         $rows[] = $arr;
     }
     return $rows;
 }
开发者ID:fatfox21,项目名称:rockoademo,代码行数:28,代码来源:PHPExcelReaderChajian.php

示例3: updateData

function updateData($filename, $encode = 'utf-8')
{
    $PHPReader = new PHPExcel_Reader_Excel2007();
    if (!$PHPReader->canRead($filename)) {
        $PHPReader = new PHPExcel_Reader_Excel5();
        if (!$PHPReader->canRead($filename)) {
            echo 'no Excel';
            return;
        }
    }
    $PHPExcel = $PHPReader->load($filename);
    $currentSheet = $PHPExcel->getSheet(0);
    $allColumn = $currentSheet->getHighestColumn();
    $allRow = $currentSheet->getHighestRow();
    $excelData = ['name' => $currentSheet->getCellByColumnAndRow(A, 1)->getValue(), 'version' => $currentSheet->getCellByColumnAndRow(A, 2)->getValue()];
    $keys = [];
    for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
        $keys[$currentColumn] = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, 5)->getValue();
    }
    for ($currentRow = 6; $currentRow <= $allRow; $currentRow++) {
        $tmp = [];
        for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
            $tmpv = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
            $tmp[$keys[$currentColumn]] = in_array($keys[$currentColumn], ['Id', 'Exp', 'Hp', 'Attack', 'Defense']) ? intval($tmpv) : floatval($tmpv);
        }
        if (!empty($tmp)) {
            $excelData['list'][] = $tmp;
        }
    }
    return $excelData;
}
开发者ID:niczhangqiang,项目名称:arserver,代码行数:31,代码来源:update.php

示例4: import

 /**
  * 导入代理商信息
  * @method import
  */
 public function import()
 {
     $file_info = R('Public/UploadExcel');
     //上传excel并返回上传路径
     if (!file_exists($file_info)) {
         //上传失败则输出
         $error_info['status'] = 0;
         $error_info['info'] = $file_info;
         die(json_encode($error_info));
     }
     import('Common.Tools.PHPExcel.PHPExcel');
     $PHPExcel = new \PHPExcel();
     $PHPReader = new \PHPExcel_Reader_Excel2007();
     if (!$PHPReader->canRead($file_info)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
     }
     if (!$PHPReader->canRead($file_info)) {
         $error_info['status'] = 0;
         $error_info['info'] = '无法读取文件';
         die(json_encode($error_info));
     }
     $PHPExcel = $PHPReader->load($file_info);
     $currentSheet = $PHPExcel->getSheet(0);
     $rowTotal = $currentSheet->getHighestRow();
     //总行数
     $columnTotal = $currentSheet->getHighestColumn();
     //总列数
     $columnTotal = \PHPExcel_Cell::columnIndexFromString($columnTotal);
     //字母列转换为数字列
     $_list = array();
     for ($i = 1; $i <= $rowTotal; $i++) {
         for ($j = 0; $j <= $columnTotal; $j++) {
             $val = $currentSheet->getCellByColumnAndRow($j, $i)->getValue();
             if (!empty($val)) {
                 $_list[$i - 1][] = $val;
             }
         }
     }
     foreach ($_list as $_k => $_v) {
         $list[$_k]['name'] = $_v[0];
         $list[$_k]['mobile'] = $_v[1];
         $list[$_k]['id_card'] = $_v[2];
         $list[$_k]['wechat_number'] = $_v[3];
         $list[$_k]['class'] = $_v[4];
         $list[$_k]['authorize_code'] = $_v[5];
         $list[$_k]['ctime'] = now();
         $list[$_k]['mtime'] = now();
     }
     $result = D('Agent')->addAll($list);
     if ($result) {
         $error_info['status'] = 1;
         $error_info['info'] = '导入成功';
     } else {
         $error_info['status'] = 0;
         $error_info['info'] = '导入数据失败';
     }
     die(json_encode($error_info));
 }
开发者ID:a3147972,项目名称:micro_business,代码行数:62,代码来源:AgentController.class.php

示例5: readExcel

 public static function readExcel($filePath)
 {
     self::init();
     $PHPReader = new PHPExcel_Reader_Excel2007();
     if (!$PHPReader->canRead($filePath)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($filePath)) {
             return null;
         }
     }
     return $PHPReader->load($filePath);
 }
开发者ID:aer123456,项目名称:yougou,代码行数:12,代码来源:XPHPExcel.php

示例6: exportToExcelWithHeader

 /**
  * 
  *函数名:		exportToExcelWithHeader
  *输入:		模板excel的路径 $filePath,例如 'C:\\123.xls'
  *输入:		二维数组  要导出的内容 $dataList
  * 			array(
  *				array(key1=>$value1,key2=>$value2,...),
  *				array(key1=>$value1,key2=>$value2,...),...
  *			)
  *输入:		一维数组  生成excel的头部信息 $headerList 
  *			array(数据库前台字段key1,数据库前台字段key2,...)
  *输入:		string $OutputFileName 输出文件名(建议输出文件名带时间戳)
  *输入:		$outputType 默认0输出到浏览器,输入其他保存到文件服务器并成功返回相对地址,失败返回NULL
  *创建人:          石昌民
  *创建时间:       2015-9-30
  */
 public function exportToExcelWithHeader($filePath, $dataList, $headerList, $OutputFileName, $outputType = 0)
 {
     require './ThinkPHP/Library/Org/PHPExcel/PHPExcel.php';
     //实例化Excel读取类
     $PHPReader = new \PHPExcel_Reader_Excel2007();
     $fileWebService = new FileWebController($this->userID);
     if (!$PHPReader->canRead($filePath)) {
         $PHPReader = new \PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($filePath)) {
             return false;
         }
     }
     //读取Excel
     $PHPExcel = $PHPReader->load($filePath);
     /**读取excel文件中的第一个工作表*/
     $currentSheet = $PHPExcel->getSheet(0);
     /**取得一共有多少行*/
     $allRow = $currentSheet->getHighestRow();
     $allRow++;
     //实例化Excel写入类
     $PHPWriter = new \PHPExcel_Writer_Excel5($PHPExcel);
     //遍历数据列表中的内容,从第allRow行开始
     $i = $allRow;
     foreach ($dataList as $key => $value) {
         $position = 'A';
         foreach ($headerList as $headerKey => $headerValue) {
             $currentSheet->setCellValueExplicit("{$position}" . $i, $dataList[$key][$headerValue], \PHPExcel_Cell_DataType::TYPE_STRING);
             //headerKey为数据库前台字段
             $position++;
         }
         $i++;
     }
     ob_end_clean();
     //清除缓冲区,避免乱码
     //决定是导出到浏览器还是文件服务器
     if ($outputType !== 0) {
         $path = Constant::WEBSERVER_EXCEL_SAVEPATH . "{$OutputFileName}.xls";
         $PHPWriter->save($path);
         // 					dump($path);
         // 					dump(file_exists($path));
         $fileURL = $fileWebService->uploadFile($path, "{$OutputFileName}.xls");
         if ($fileURL == false) {
             $fileURL = null;
         }
         return $fileURL;
         return false;
     } else {
         header('Content-Type: application/vnd.ms-excel');
         header("Content-Disposition: attachment;filename={$OutputFileName}.xls");
         header('Cache-Control: max-age=0');
         $PHPWriter->save('php://output');
     }
 }
开发者ID:AplayER,项目名称:TryGit,代码行数:69,代码来源:IndexController.class.php

示例7: readExcel

 /**
 * 
 * @param string $filePath
 * @return
 */
 private function readExcel($filePath)
 {
     $filePath = $this->dir() . $filePath;
     if (!is_file($filePath)) {
         return FALSE;
     }
     $PHPReader = new \PHPExcel_Reader_Excel2007();
     if ($PHPReader->canRead($filePath)) {
         return $PHPReader->load($filePath);
     }
     return FALSE;
 }
开发者ID:enozoom,项目名称:es,代码行数:17,代码来源:Excel.php

示例8: excel

 function excel($postdata)
 {
     require_once 'Excel_reader.php';
     require_once 'Classes/PHPExcel.php';
     $tmp = $postdata;
     $save_path = "./";
     //暂时上传的文件路径
     $file_name = $save_path . date('Ymdhis') . ".xls";
     //上传后的文件保存路径和名称
     if (copy($tmp, $file_name)) {
     }
     $PHPExcel = new PHPExcel();
     $PHPReader = new PHPExcel_Reader_Excel2007();
     //为了可以读取所有版本Excel文件
     if (!$PHPReader->canRead($file_name)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($file_name)) {
             echo '未发现Excel文件!';
             return;
         }
     }
     //不需要读取整个Excel文件而获取所有工作表数组的函数,感觉这个函数很有用,找了半天才找到
     $sheetNames = $PHPReader->listWorksheetNames($file_name);
     //读取Excel文件
     $PHPExcel = $PHPReader->load($file_name);
     //获取工作表的数目
     $sheetCount = $PHPExcel->getSheetCount();
     for ($i = 0; $i < $sheetCount; $i++) {
         //选择第一个工作表
         $currentSheet = $PHPExcel->getSheet($i);
         //取得一共有多少列
         $allColumn = $currentSheet->getHighestColumn();
         //取得一共有多少行
         $allRow = $currentSheet->getHighestRow();
         for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
             for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
                 $address = $currentColumn . $currentRow;
                 $data[$i][$currentRow][$currentColumn] = $currentSheet->getCell($address)->getValue();
                 //echo ."\t";
             }
         }
         //$data[$i]=$currentSheet;
     }
     unlink($file_name);
     //删除上传的文件
     return $data;
 }
开发者ID:ytftianwen,项目名称:web,代码行数:47,代码来源:Handle.php

示例9: get_rows_from_excel

 public function get_rows_from_excel($filepath, &$infos)
 {
     if (empty($filepath)) {
         return $infos;
     }
     $php_reader = new PHPExcel_Reader_Excel2007();
     if (!$php_reader->canRead($filepath)) {
         $php_reader = new PHPExcel_Reader_Excel5();
         if (!$php_reader->canRead($filepath)) {
             return $infos;
         }
     }
     $cur_excel = $php_reader->load($filepath);
     $cur_sheet = $cur_excel->getSheet(0);
     $all_column = $cur_sheet->getHighestColumn();
     //取得一共有多少列
     $all_row = $cur_sheet->getHighestRow();
     //取得一共有多少行
     $infos_have = array();
     $infos_error = array();
     $i = 0;
     $j = 0;
     for ($cur_row = 1; $cur_row <= $all_row; $cur_row++) {
         $flagadd = FALSE;
         $tmprow = array();
         $tmpchar = '';
         for ($cur_column = 'A'; $cur_column <= $all_column; $cur_column++) {
             $address = $cur_column . $cur_row;
             $curinfo = trim($cur_excel->getActiveSheet()->getCell($address)->getvalue());
             //if($cur_column == 'A')
             //{
             if (!empty($curinfo)) {
                 $flagadd = TRUE;
             }
             //}
             $tmprow[] = $curinfo;
             $tmpchar .= $curinfo;
         }
         if ($flagadd) {
             $infos['infos_have'][$i] = $tmprow;
             $i++;
         } elseif (!empty($tmpchar)) {
             $infos['infos_error'][$j] = $tmprow;
             $j++;
         }
     }
 }
开发者ID:RenzcPHP,项目名称:3dproduct,代码行数:47,代码来源:myexcel.php

示例10: index

 public function index()
 {
     // 		$xq_list = $this->manage_model->get_all_xiaoqu_list();
     // 		foreach ($xq_list as $xq) {
     // 			$name =  str_replace("•","",$xq['name']);
     // 			//echo $xq['id'] . ": " . $this->encode($name) . '<br>';
     // 			$xq['jianpin'] = $this->encode($name);
     // 			$this->manage_model->update_xiaoqu_jianpin($xq);
     // 		}
     // 		die('DONE');
     require_once APPPATH . 'libraries/PHPExcel/PHPExcel.php';
     $PHPExcel = new \PHPExcel();
     $PHPReader = new \PHPExcel_Reader_Excel2007();
     $file = 'E:/broker.xlsx';
     //为了可以读取所有版本Excel文件
     if (!$PHPReader->canRead($file)) {
         $PHPReader = new \PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($file)) {
             echo '未发现Excel文件!';
             return;
         }
     }
     //不需要读取整个Excel文件而获取所有工作表数组的函数,感觉这个函数很有用,找了半天才找到
     $sheetNames = $PHPReader->listWorksheetNames($file);
     //读取Excel文件
     $PHPExcel = $PHPReader->load($file);
     //获取工作表的数目
     $sheetCount = $PHPExcel->getSheetCount();
     //选择第一个工作表
     $currentSheet = $PHPExcel->getSheet(0);
     //取得一共有多少列
     $allColumn = $currentSheet->getHighestColumn();
     //取得一共有多少行
     $allRow = $currentSheet->getHighestRow();
     //循环读取数据,默认编码是utf8,这里转换成gbk输出
     $data = array();
     for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
         $name = trim($currentSheet->getCell("A" . $currentRow)->getValue());
         $tel = trim($currentSheet->getCell("B" . $currentRow)->getValue());
         $data[] = array('username' => $tel, 'passwd' => sha1('888888'), 'tel' => $tel, 'company_name' => "顺达地产", 'rel_name' => $name, 'region_id' => 6, 'admin_group' => 2);
     }
     $this->manage_model->add_broker_batch($data);
 }
开发者ID:binshen,项目名称:website,代码行数:43,代码来源:test.php

示例11: format_excel2array

function format_excel2array($filePath = '', $sheet = 0)
{
    if (empty($filePath) or !file_exists($filePath)) {
        die('file not exists');
    }
    $PHPReader = new PHPExcel_Reader_Excel2007();
    //建立reader对象
    if (!$PHPReader->canRead($filePath)) {
        $PHPReader = new PHPExcel_Reader_Excel5();
        if (!$PHPReader->canRead($filePath)) {
            echo 'no Excel';
            return;
        }
    }
    $PHPExcel = $PHPReader->load($filePath);
    //建立excel对象
    $currentSheet = $PHPExcel->getSheet($sheet);
    //**读取excel文件中的指定工作表*/
    $allColumn = $currentSheet->getHighestColumn();
    //**取得最大的列号*/
    $allRow = $currentSheet->getHighestRow();
    //**取得一共有多少行*/
    $data = array();
    for ($rowIndex = 1; $rowIndex <= $allRow; $rowIndex++) {
        //循环读取每个单元格的内容。注意行从1开始,列从A开始
        for ($colIndex = 'A'; $colIndex <= $allColumn; $colIndex++) {
            $addr = $colIndex . $rowIndex;
            $cell = $currentSheet->getCell($addr)->getValue();
            if ($cell instanceof PHPExcel_RichText) {
                //富文本转换字符串
                $cell = $cell->__toString();
            }
            $data[$rowIndex][$colIndex] = $cell;
        }
    }
    return $data;
}
开发者ID:zhangpanfei,项目名称:test,代码行数:37,代码来源:excel数据转成数组.php

示例12: import

 public function import($filePath)
 {
     $this->__construct();
     $PHPExcel = new PHPExcel();
     /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/
     $PHPReader = new PHPExcel_Reader_Excel2007();
     if (!$PHPReader->canRead($filePath)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($filePath)) {
             echo 'no Excel';
             return;
         }
     }
     $PHPExcel = $PHPReader->load($filePath);
     $currentSheet = $PHPExcel->getSheet(0);
     //读取excel文件中的第一个工作表
     $allColumn = $currentSheet->getHighestColumn();
     //取得最大的列号
     $allRow = $currentSheet->getHighestRow();
     //取得一共有多少行
     $erp_orders_id = array();
     //声明数组
     /**从第二行开始输出,因为excel表中第一行为列名*/
     for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
         /**从第A列开始输出*/
         for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
             $val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
             /**ord()将字符转为十进制数*/
             //if($val!=''){
             $erp_orders_id[] = $val;
             //}
             /**如果输出汉字有乱码,则需将输出内容用iconv函数进行编码转换,如下将gb2312编码转为utf-8编码输出*/
             //echo iconv('utf-8','gb2312', $val)."\t";
         }
     }
     return $erp_orders_id;
 }
开发者ID:superman1982,项目名称:ddd,代码行数:37,代码来源:ExcelModel.class.php

示例13: index

    public function index()
    {
        //提交的配置
        $config = $_POST['config'];
        $filePath = AMANGO_FILE_ROOT . $config['excel_path'];
        $currentid = $config['excel_readxls'] >= 1 ? $config['excel_readxls'] - 1 : 0;
        $startid = $config['excel_currentrow'] >= 2 ? $config['excel_currentrow'] : 2;
        if ($filePath == AMANGO_FILE_ROOT) {
            $this->error('请选择文件');
        }
        $xlsparam = parse_config($_POST['config']['excel_param']);
        //导入第三方插件
        Amango_Addons_Import('PHPExcel.php', 'Excelimport');
        Amango_Addons_Import('PHPExcel/Reader/Excel2007.php', 'Excelimport');
        //自动生成唯一数据表名
        $table_name = 'addonsexcel' . str_replace('_', '', strtolower($config['excel_tablename']));
        $tablename = C('DB_PREFIX') . $table_name;
        $sql = <<<sql
\t\t\t\tSHOW TABLES LIKE '{$tablename}';
sql;
        $res = M()->query($sql);
        //判断表唯一  以便生成新表
        if (count($res) > 0) {
            $this->error('该表名已存在,请换个数据表名');
        } else {
            if (strpos($_POST['config']['excel_param'], ':') === false) {
                $this->error('生成数据表时,请务必填写字段读取配置,格式:字段名:读取列标识');
            } else {
                $fields = '';
                $field = array();
                foreach ($xlsparam as $key => $value) {
                    if (!empty($key)) {
                        $fields .= "`{$key}` text,";
                        $field[] = $key;
                    }
                }
                //生成数据表
                $sql = <<<sql
\t\t\t\tCREATE TABLE IF NOT EXISTS `{$tablename}` (
\t\t\t\t`id`  int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键' ,
\t\t\t\t{$fields}
\t\t\t\tPRIMARY KEY (`id`)
\t\t\t\t)
\t\t\t\tENGINE=MyISAM
\t\t\t\tDEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
\t\t\t\tCHECKSUM=0
\t\t\t\tROW_FORMAT=DYNAMIC
\t\t\t\tDELAY_KEY_WRITE=0
\t\t\t\t;
sql;
                $res = M()->execute($sql);
                if ($res === false) {
                    $this->error('建立数据表出错,请重新建表');
                }
            }
        }
        //导入数据表名 存入总表
        D('addonsexcel')->add(array('fileds' => implode(',', $field), 'tablename' => $tablename));
        $PHPExcel = new \PHPExcel();
        /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/
        $PHPReader = new \PHPExcel_Reader_Excel2007();
        if (!$PHPReader->canRead($filePath)) {
            $PHPReader = new \PHPExcel_Reader_Excel5();
            if (!$PHPReader->canRead($filePath)) {
                $this->error('无法在' . $filePath . '路径下找到该文件');
            }
        }
        $PHPExcel = $PHPReader->load($filePath);
        /**读取excel文件中的第一个工作表*/
        $currentSheet = $PHPExcel->getSheet($currentid);
        /**取得最大的列号*/
        $allColumn = $currentSheet->getHighestColumn();
        /**取得一共有多少行*/
        $allRow = $currentSheet->getHighestRow();
        //初始化
        $rows = array();
        foreach ($xlsparam as $key => $value) {
            for ($currentRow = $startid; $currentRow <= $allRow; $currentRow++) {
                $rowinfo = $currentSheet->getCell(strtoupper($value) . $currentRow)->getValue();
                $rows[$currentRow][$key] = $config['excel_parxhtml'] == 1 ? strip_tags($rowinfo) : $rowinfo;
            }
        }
        //读取出总记录
        foreach ($rows as $key => $value) {
            M($table_name)->add($value);
        }
        M('addonsexcel')->where(array('tablename' => $tablename))->save(array('rows' => count($rows)));
        $this->success('新增成功', U('Addons/adminList', array('name' => 'Excelimport')));
    }
开发者ID:wmk223,项目名称:amango_V3,代码行数:89,代码来源:ExcelimportController.class.php

示例14: view_importBoxData

 /**
  * 批量导入箱子信息方法
  */
 public function view_importBoxData()
 {
     require_once WEB_PATH . 'lib/PHPExcel.php';
     $uploadfile = date("Y") . date("m") . date("d") . rand(1, 100) . ".xlsx";
     $path = WEB_PATH . 'html/template/v1/updload/boxinfo/';
     if (move_uploaded_file($_FILES['upfile']['tmp_name'], $path . $uploadfile)) {
         $importResult = "<font color=green>上传成功</font><br>";
         $ismark = 'yes';
     } else {
         $importResult = "<font color=red>上传失败</font><br>";
         $ismark = 'no';
     }
     $fileName = $path . $uploadfile;
     $filePath = $fileName;
     $PHPExcel = new PHPExcel();
     $PHPReader = new PHPExcel_Reader_Excel2007();
     if (!$PHPReader->canRead($filePath)) {
         $PHPReader = new PHPExcel_Reader_Excel5();
         if (!$PHPReader->canRead($filePath)) {
             echo 'no Excel';
             return;
         }
     }
     $PHPExcel = $PHPReader->load($filePath);
     $sheet = $PHPExcel->getActiveSheet();
     /**取得一共有多少列*/
     $c = 2;
     $importShow = '';
     $boxObj = new BoxManageModel();
     while (true) {
         $aa = 'A' . $c;
         $bb = 'B' . $c;
         $cc = 'C' . $c;
         $dd = 'D' . $c;
         $ee = 'E' . $c;
         $ff = 'F' . $c;
         $boxId = trim($sheet->getCell($aa)->getValue());
         $length = trim($sheet->getCell($bb)->getValue());
         $width = trim($sheet->getCell($cc)->getValue());
         $high = trim($sheet->getCell($dd)->getValue());
         $weight = trim($sheet->getCell($ee)->getValue());
         $netWeight = trim($sheet->getCell($ff)->getValue());
         if (empty($boxId)) {
             break;
         }
         $rtnCode = $boxObj->batchUpdBoxInfo($boxId, $length, $width, $high, $weight, $netWeight);
         if ($rtnCode == 'success') {
             $importShow .= "<font color=green>箱号[" . $boxId . "]更新成功</font><br/>";
         } else {
             if ($rtnCode == 'failure') {
                 $importShow .= "<font color=red>箱号[" . $boxId . "]更新失败</font><br/>";
             } else {
                 if ($rtnCode == 'statusError') {
                     $importShow .= "<font color=red>箱号[" . $boxId . "]未复核,不能更新</font><br/>";
                 } else {
                     if ($rtnCode == 'null') {
                         $importShow .= "<font color=red>箱号[" . $boxId . "]不存在</font><br/>";
                     } else {
                         if ($rtnCode == 'moreWeight') {
                             $importShow .= "<font color=red>箱号[" . $boxId . "]净重大于毛重,请复查</font><br/>";
                         }
                     }
                 }
             }
         }
         $c++;
     }
     $navlist = array(array('url' => '', 'title' => '海外仓补货'), array('url' => '', 'title' => '箱号管理'), array('url' => '', 'title' => '箱号信息导入结果'));
     $toplevel = 2;
     $this->smarty->assign('navlist', $navlist);
     //顶层菜单
     $this->smarty->assign('toplevel', $toplevel);
     $this->smarty->assign('importShow', $importShow);
     $this->smarty->assign('importResult', $importResult);
     $this->smarty->display('importBoxInfoResult.htm');
 }
开发者ID:ohjack,项目名称:newErp,代码行数:79,代码来源:owBoxManage.view.php

示例15: doWebBatchAddInfo

 public function doWebBatchAddInfo()
 {
     global $_W, $_GPC;
     load()->func('tpl');
     if (checksubmit()) {
         $excelfile = $_FILES['exceldata'];
         if (empty($excelfile)) {
             message('请先上传文件');
         }
         $str = explode(".", $excelfile['name']);
         $filetype = strtolower($str[1]);
         if (!($filetype == 'xlsx' || $filetype == 'xls')) {
             message('上传文件类型不正确!');
         }
         $path = '../attachment/excel/water/';
         if (!file_exists($path)) {
             mkdir($path);
         }
         $time = time();
         $filePath = $path . $time . '.' . $filetype;
         move_uploaded_file($excelfile['tmp_name'], $filePath);
         //首先导入PHPExcel
         require_once 'PHPExcel.php';
         //$filePath = "../addons/water_query2/test.xlsx";
         //建立reader对象
         $PHPReader = new PHPExcel_Reader_Excel2007();
         if (!$PHPReader->canRead($filePath)) {
             $PHPReader = new PHPExcel_Reader_Excel5();
             if (!$PHPReader->canRead($filePath)) {
                 echo 'no Excel';
                 return;
             }
         }
         //建立excel对象,此时你即可以通过excel对象读取文件,也可以通过它写入文件
         $PHPExcel = $PHPReader->load($filePath);
         /**读取excel文件中的第一个工作表*/
         $currentSheet = $PHPExcel->getSheet(0);
         /**取得最大的列号*/
         $allColumn = $currentSheet->getHighestColumn();
         echo $allColumn . '---';
         /**取得一共有多少行*/
         $allRow = $currentSheet->getHighestRow();
         echo $allRow . '----';
         //循环读取每个单元格的内容。注意行从1开始,列从A开始
         $data = array('uniacid' => $_W['uniacid']);
         for ($rowIndex = 1; $rowIndex <= $allRow; $rowIndex++) {
             for ($colIndex = 'A'; $colIndex <= $allColumn; $colIndex++) {
                 $addr = $colIndex . $rowIndex;
                 $cell = $currentSheet->getCell($addr)->getValue();
                 if ($cell instanceof PHPExcel_RichText) {
                     //富文本转换字符串
                     $cell = $cell->__toString();
                 }
                 //echo '第'.$rowIndex.'行,第'.$colIndex.'列:'.$cell.'</br>';
                 if ($colIndex == 'A') {
                     $data['keyword'] = $cell;
                 } else {
                     $data['ordercode'] = $cell;
                 }
             }
             pdo_insert('water_query2_info', $data);
         }
         message('导入成功!', $this->createWebUrl('Info'), 'success');
     } else {
         include $this->template('batchaddinfo');
     }
 }
开发者ID:eduNeusoft,项目名称:weixin,代码行数:67,代码来源:site.php


注:本文中的PHPExcel_Reader_Excel2007::canRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。