1

我需要使用 codeigiter 将 excelsheet 数据加载到数据库中。因为我已经尝试过这种编码

function excel_data()
    {
//include 'PHPExcel/IOFactory.php';
  $this->load->library("PHPExcel");
 $inputFileName = '../first_data.xls';


//  Read your Excel workbook
try {
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}

//  Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestColumn();

//  Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++){ 
    //  Read a row of data into an array
    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
                                    NULL,
                                    TRUE,
                                    FALSE);
    //  Insert row data array into your database of choice here
    // $this->User_model->add_data($rowData);
}

 }

执行 iam 时出现此错误“加载文件时出错“first_data.xls”:无法打开 ../first_data.xls 进行读取!文件不存在。” 我的编码有什么问题。

我的错误是什么。有人知道吗?

4

0 回答 0