【问题标题】:how to fix import excel file in php如何修复在php中导入excel文件
【发布时间】:2016-10-07 16:58:39
【问题描述】:

我在 php 中使用 excel_reader 导入数据 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)

谢谢你..

【问题讨论】:

    标签: php excel codeigniter import reader


    【解决方案1】:

    你好阅读excel文件你可以阅读这篇文章read excel file

    验证您的 PHPExcel 文件夹PHPExcel 文件是否在您的第三方文件夹中,然后在您的应用程序/库文件夹中创建一个 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();
        }
    }
    

    【讨论】:

    • 无法修复先生,结果相同..“与其类同名的方法在 PHP 的未来版本中将不再是构造函数;Excel_reader 有一个已弃用的构造函数”
    • 嗨,首先,download PHPExcel 最新版本或 1.8.0v,然后解压缩,然后在 Classes/* 中将所有内容复制到 application/third_party 文件夹中,然后在 applicaton/libraries 中创建一个文件我在上面给你的代码,然后在你的控制器中只调用我在第一条评论中给你的链接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    • 2023-01-23
    • 1970-01-01
    • 2014-08-06
    相关资源
    最近更新 更多