最近我使用Spreadsheet_Excel_Reader读取codeigniter中的.xls文件。我做了以下步骤:

时间:2015-08-22 05:12:27

标签: codeigniter phpexcelreader

我想读取一个excel文件,我想将这个excel数据插入数据库,但是我收到一个错误(显示错误:excel文件不可读)。请帮助。我的代码在控制器中,< / p>

public function read_file($table = 'statement', $filename = 'ww.xls') {

        $pathToFile = './uploads/' . $filename;
        $this->load->library('Spreadsheet_Excel_Reader');
        $data = new Spreadsheet_Excel_Reader($pathToFile);
        $sql = "INSERT INTO $table(";
        for($index = 1;$index <= $data->sheets[0]['numCols']; $index++){
            $sql.= strtolower($data->sheets[0]['cells'][1][$index]) . ", ";
        }

        $sql = rtrim($sql, ", ")." ) VALUES ( ";
        for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
            $valuesSQL = '';
            for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
                $valuesSql .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\", ";
            }
            echo $sql . rtrim($valuesSql, ", ")." ) <br>";
        }
    }
    }

错误:表示

 A PHP Error was encountered

    Severity: 8192

    Message: Assigning the return value of new by reference is deprecated

    Filename: libraries/Spreadsheet_Excel_Reader.php

    Line Number: 916

    Backtrace:

    File: D:\wamp\www\moneymanager18_8_15\application\controllers\money_c.php
    Line: 641
    Function: library

    File: D:\wamp\www\moneymanager18_8_15\index.php
    Line: 292
    Function: require_once

    The filename ./uploads/ww.xls is not readable

0 个答案:

没有答案