如何修复在 php 中导入 excel 文件
how to fix import excel file in php
我在 php 中导入数据 excel 时遇到问题,使用 excel_reader。
这是错误视图
这是我的代码:
$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 中不支持的问题,
我该如何解决?
谢谢...
[已解决]
这个问题已解决,我只需要将与名称 class 相同的名称函数更改为 (__construct)
谢谢你..
你好阅读excel文件你可以阅读这个post
确认您的 PHPExcel 文件夹PHPExcel 文件在您的 third_party 文件夹中,然后在您的 application/library 文件夹中您需要创建一个 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 时遇到问题,使用 excel_reader。
这是错误视图
这是我的代码:
$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 中不支持的问题, 我该如何解决?
谢谢...
[已解决]
这个问题已解决,我只需要将与名称 class 相同的名称函数更改为 (__construct)
谢谢你..
你好阅读excel文件你可以阅读这个post
确认您的 PHPExcel 文件夹PHPExcel 文件在您的 third_party 文件夹中,然后在您的 application/library 文件夹中您需要创建一个 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();
}
}