2016-06-07 70 views
-1

我在php中使用excel_reader导入数据excel时遇到问题。如何修复php中的导入excel文件

这是错误观点

pict error

这是我的代码:

$config['upload_path'] = './assets/excel/'; 
    $config['allowed_types'] = 'xls'; 
    $config['max_size'] = 1024 * 8; 

    $this->load->library('upload', $config);     

    if (! $this->upload->do_upload()) 
    { 
     echo'<script>alert("Upload gagal. Perhatikan ekstensi file. Ekstensi harus xls. Apabila ekstensi sudah xls namun gagal, lengkapi data dalam file xls.");</script>'; 
     $this->load->view('include/header'); 
     $this->load->view('upload_excel_cust'); 
     $this->load->view('include/footer'); 

    } 
    else 
    { 
     $data = array('error' => false); 
     $upload_data = $this->upload->data(); 


     $this->load->library('Excel_reader'); 
     $this->excel_reader->setOutputEncoding('230787'); 

     $file = $upload_data['full_path']; 
     $this->excel_reader->read($file); 
     error_reporting(E_ALL^E_NOTICE); 

     // Sheet 1 
     $data = $this->excel_reader->sheets[0] ; 
        $dataexcel = Array(); 
     for ($i = 1; $i <= $data['numRows']; $i++) { 

         if($data['cells'][$i][1] == '') break; 
         $dataexcel[$i-1]['tgl'] = $data['cells'][$i][2]; 
         $dataexcel[$i-1]['nama_tempat'] = $data['cells'][$i][3]; 

我一直在阅读问题的原因excel_reader文件在PHP 7, 不支持我怎么能解决它?

三江源...

[解决]

这个问题解决了,我只需要更改名称相同的功能与类名中(__construct)

三江源..

回答

0

喜阅读excel文件,您可以阅读这篇文章read excel file

验证您的PHPExcel文件夹PHPExcel文件是否在您的third_party fo然后在你的应用程序/库文件夹中,你需要创建一个Excel.php文件

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

require_once APPPATH."/third_party/PHPExcel.php"; 

class Excel extends PHPExcel { 

    public function __construct() { 
     parent::__construct(); 
    } 
} 
+0

不能修正先生,结果相同..“的PHP; Excel_reader有一个不赞成的构造函数“ –

+0

嗨,首先,[下载PHPExcel](http://phpexcel.codeplex.com/releases/view/119187)最新版本或1.8.0v,然后解压缩,然后在Clasess/* copy全部放入应用程序/ third_party文件夹中,然后在applicaton/libraries中创建一个文件,其中包含我上面给出的代码,然后在您的控制器中仅调用我在第一条评论中给出的链接 – elddenmedio