Jual Beli Produk Digital - Cepat, Aman, Dan Terpercaya Sejak 2012 (Ada 70698 Members, 832 Products, 4745 Topic, 13114 Comments)

Cara Mengatasi Error di sebuah Aplikasi pada Library PHPExcell

Dibuat
Login Terakhir 10 Bulan lalu,
Telah Dilihat 2334 Kali
Rivani Noer Maulidi Mengatakan : Sultan Account
Assalamualaikum Warahmatullahi Wabarakatuh...
Mau tanya mengatasi error ini min
Ada 1 File Kiriman :
1. a1.jpg (79 KB)

Ada 4 Jawaban

Bukhori Muslim
commented on 08 Feb 2019 07:25:58
Assalam,.. artinya pada file excel tidak boleh ada yang kosong kolomnya,
ini mau import data ya gan?

controller import bikin begini saja :
public function import_excel(){
        $config['upload_path'] = 'asset/'.$this->uri->segment(3);
        $config['allowed_types'] = 'xlsx|xls';
        $this->load->library('upload', $config);
        if ( ! $this->upload->do_upload('fileexcel')){
            $error = array('error' => $this->upload->display_errors());
        }else{
            $data = array('upload_data' => $this->upload->data());
            $upload_data = $this->upload->data(); //Mengambil detail data yang di upload
            $filename = $upload_data['file_name'];//Nama File
            $this->model_app->import_excel($this->uri->segment(3),$filename);
            redirect('controller_nganu');
        }
}

Modelsnya begini :
public function import_excel_borongan($directory,$filename){
    ini_set('memory_limit', '-1');
    $inputFileName = './asset/'.$directory.'/'.$filename;
    try {
    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
    } catch(Exception $e) {
    die('Error loading file :' . $e->getMessage());
    }

    $worksheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
    $numRows = count($worksheet);
    for ($i=2; $i < ($numRows+1) ; $i++) { 
      $a        = $worksheet[$i]['A'];
      $b        = $worksheet[$i]['B'];
      $c        = $worksheet[$i]['C'];
      $d        = $worksheet[$i]['D'];

      $data = array('field1'=>$a,
                    'field1'=>$b,
                    'field1'=>$c,
                    'field1'=>$d);
    $this->model_app->insert('rb_table',$data);
    }
}
Rivani Noer Maulidi
commented on 09 Feb 2019 07:27:48
Assalam,.. 
itu mau export gan
Rivani Noer Maulidi
commented on 16 Feb 2019 18:05:42
Assalam,.. 
gimna ya gan caranya
Bukhori Muslim
commented on 18 Feb 2019 07:44:24
Assalam,.. coba sesuaikan dengan ini gan file exportnya :
<?php
//load our new PHPExcel library
$this->load->library('excel');
//activate worksheet number 1
$this->excel->setActiveSheetIndex(0);
//name the worksheet
$this->excel->getActiveSheet()->setTitle('Users list');

// load database
$this->load->database();

// load model
$this->load->model('userModel');

// get all users in array formate
$users = $this->userModel->get_users();

// read data to active sheet
$this->excel->getActiveSheet()->fromArray($users);

$filename='just_some_random_name.xls'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
            
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as.XLSX Excel 2007 format
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); 

//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!

Online