thinkphp - PHPExcel导入数据出现问题

查看:588
本文介绍了thinkphp - PHPExcel导入数据出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

报错信息:
exception 'PHPExcel_Exception' with message 'Invalid cell coordinate ABCA2' in /home/wwwroot/localhost/Base/Extend/Library/ORG/PHPExcel/PHPExcel/Cell.php:539 Stack trace: #0 /home/wwwroot/localhost/Base/Extend/Library/ORG/PHPExcel/PHPExcel/Worksheet.php(1121): PHPExcel_Cell::coordinateFromString('ABCA2') #1 /home/wwwroot/localhost/Base/Extend/Library/ORG/PHPExcel/PHPExcel/Worksheet.php(1029): PHPExcel_Worksheet->getCell('ABCA2') #2 /home/wwwroot/localhost/App/Lib/Action/CustomerAction.class.php(1273): PHPExcel_Worksheet->setCellValue('ABCA2', 'xE5x85xB3xE9x94xAExE8xAFx8D') #3 /home/wwwroot/localhost/App/Lib/Action/CustomerAction.class.php(1032): CustomerAction->excelExport(Array) #4 [internal function]: CustomerAction->index() #5 /home/wwwroot/localhost/Base/Lib/Core/App.class.php(171): ReflectionMethod->invoke(Object(CustomerAction)) #6 /home/wwwroot/crm.gsi.com.cn/Base/Lib/Core/App.class.php(207): App::exec() #7 /home/wwwroot/localhost//Base/Lib/Core/Think.class.php(39): App::run() #8 /home/wwwroot/crm.gsi.com.cn/Base/Common/runtime.php(242): Think::start() #9 /home/wwwroot/localhost/Base/ThinkPHP.php(30): require('/home/wwwroot/c...') #10 /home/wwwroot/localhost/index.php(6): require('/home/wwwroot/c...') #11 {main}

代码:workersheet.php 1121 getCell方法
public function getCell($pCoordinate = 'A1')
    {
        // Check cell collection
        if ($this->_cellCollection->isDataSet($pCoordinate)) {
            return $this->_cellCollection->getCacheData($pCoordinate);
        }

        // Worksheet reference?
        if (strpos($pCoordinate, '!') !== false) {
            $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
            return $this->getParent()->getSheetByName($worksheetReference[0])->getCell($worksheetReference[1]);
        }

        // Named range?
        if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
            (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
            $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
            if ($namedRange !== NULL) {
                $pCoordinate = $namedRange->getRange();
                return $namedRange->getWorksheet()->getCell($pCoordinate);
            }
        }

        // Uppercase coordinate
        $pCoordinate = strtoupper($pCoordinate);

        if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) {
            throw new Exception('Cell coordinate can not be a range of cells.');
        } elseif (strpos($pCoordinate,'$') !== false) {
            throw new Exception('Cell coordinate must not be absolute.');
        } else {
            // Create new cell object

            // Coordinates
            $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);

            $cell = $this->_cellCollection->addCacheData($pCoordinate,new PHPExcel_Cell($aCoordinates[0], $aCoordinates[1], null, PHPExcel_Cell_DataType::TYPE_NULL, $this));
            $this->_cellCollectionIsSorted = false;

            if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($aCoordinates[0]))
                $this->_cachedHighestColumn = $aCoordinates[0];

            $this->_cachedHighestRow = max($this->_cachedHighestRow,$aCoordinates[1]);

            // Cell needs appropriate xfIndex
            $rowDimensions    = $this->getRowDimensions();
            $columnDimensions = $this->getColumnDimensions();

            if ( isset($rowDimensions[$aCoordinates[1]]) && $rowDimensions[$aCoordinates[1]]->getXfIndex() !== null ) {
                // then there is a row dimension with explicit style, assign it to the cell
                $cell->setXfIndex($rowDimensions[$aCoordinates[1]]->getXfIndex());
            } else if ( isset($columnDimensions[$aCoordinates[0]]) ) {
                // then there is a column dimension, assign it to the cell
                $cell->setXfIndex($columnDimensions[$aCoordinates[0]]->getXfIndex());
            } else {
                // set to default index
                $cell->setXfIndex(0);
            }

            return $cell;
        }
    }

请问一下是什么问题?求解

解决方案

excle的列表名超界错误,下面这个循环只能从A-AZ列。

$ascii = 65;
        $cv = '';
        $field_list = M('Fields')->where('model = \'customer\'')->order('order_id')->select();
        foreach($field_list as $field){
            $objActSheet->setCellValue($cv.chr($ascii).'2', $field['name']);
            $ascii++;
            if($ascii == 91){
                $ascii = 65;
                $cv .= chr(strlen($cv)+65);
            }
        }
        $mark_customer_ascii = $ascii;
        $mark_customer_cv = $cv;
        }

使用悟空crm的扩展字段太多,导致导出客户的excle列表名错误

这篇关于thinkphp - PHPExcel导入数据出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆