Please enable JavaScript!
Bitte aktiviere JavaScript!
S'il vous plaît activer JavaScript!
Por favor,activa el JavaScript!
antiblock.org

 |  | 
Anda ingin membuat website?
Untuk Anda yang sedang mencari orang untuk jasa pembuatan website, Saya akan bantu buatkan aplikasi sesuai kebutuhan Anda. Segera hubungi : mail@rizaldimaulidia.com. Selengkapnya tentang profil saya klik www.rizaldimaulidia.com.

Codeigniter

Cara Membuat Export Data Ke Excel Dengan PHPExcel dan Codeigniter

img-responsive

Ketemu lagi dengan saya. Pada kesempatan kali ini, saya akan coba share catatan saya mengenai export data dari database ke excel. Hampir di setiap web aplikasi di perlukan yang namanya fitur Report / Laporan. Biasanya laporan tersebut menggunakan PDF atau Excel. Nah untuk catatan kali ini, kita akan buat laporan excel (export data ke excel). Dalam catatan ini, kita menggunakan sebuah plugin yang sudah lama dan banyak digunakan yakni PHPExcel. Menurut saya, plugin ini benar-benar plugin yang sangat lengkap dan dokumentasi nya pun lengkap dan mudah di pahami (untuk dokumentasi saya cantumkan link nya pada akhir catatan ini). Oke sekarang kita langsung masuk ke langkah demi langkah untuk membuat hal tersebut. Oh iyaa disini kita juga pakai Framework Codeigniter 3 (versi 3).


PENTING, MOHON DIBACA TERLEBIH DAHULU
Tutorial ini menggunakan librari PHPExcel untuk proses export excelnya. Librari ini setau saya dan sudah saya tes hanya mendukung sampai PHP Versi 7.2.8. Jadi bagi kamu yang pakai PHP Versi diatas 7.2.8, sebaiknya downgrade dulu atau download Xampp dimana PHP nya masih versi 7.2.8 ke bawah. Jika Anda ingin melihat tutorial untuk PHP 7.2.8 ke atas, silahkan buka tutorial berikut ini :

Tutorial Import Data dari Excel untuk PHP 7.2.8 ke Atas :
Cara Membuat Export Excel dengan Codeigniter dan PhpSpreadsheet

Berikut ini untuk link download Xampp Versi 7.2.8 :


DEMO
Sebelum membaca tutorialnya, mungkin ada yang ingin melihat demonya terlebih dahulu. Klik link berikut untuk melihat demonya : Lihat Demo.


STEP 1 – INSTALASI
Pada tahap ini kita akan menyiapkan hal-hal yang diperlukan.

  1. Download Framework Codeigniter, klik link berikut : download.
  2. Download plugin PHPExcel, klik link berikut : Download.
  3. Buat sebuah folder dengan nama export_phpexcel_ci, lalu simpan pada folder xampp/htdocs/.
  4. Copy and paste file codeigniter_v3.7z yang telah di download tadi ke folder xampp/htdocs/export_phpexcel_ci.
  5. Ekstrak file codeigniter_v3.7z nya.
  6. Ekstrak file PHPExcel.7z yang telah di download tadi, lalu copy and paste folder PHPExcel nya ke folder xampp/htdocs/export_phpexcel_ci/application/third_party/.

STEP 2 – BUAT DATABASE
Buat database dengan nama mynotescode, lalu buat sebuah tabel siswa dengan struktur tabel seperti berikut ini :

Struktur Tabel - Cara Mudah Membuat Export Excel Tanpa Plugin dengan Codeigniter

CREATE TABLE `siswa` (
  `nis` varchar(11) NOT NULL PRIMARY KEY,
  `nama` varchar(50) NOT NULL,
  `jenis_kelamin` varchar(10) NOT NULL,
  `alamat` text NOT NULL
)

STEP 3 – KONFIGURASI
Karena dibuat dengan Codeigniter, pertama kita harus melakukan konfigurasi terlebih dahulu pada framework codeigniternya.

  1. Buka folder xampp/htdocs/export_phpexcel_ci/application/config/
  2. Buka file config.php
    Cari kode berikut $config['base_url'] = '';Ubah kode tersebut jadi seperti ini :

    $config['base_url'] = 'http://localhost/export_phpexcel_ci';

    Kode diatas digunakan untuk menset baseurlnya.
    Lalu simpan file tersebut.

  3. Buka file autoload.php
    Cari kode berikut ini :

    $autoload['libraries'] = array();
    $autoload['helper'] = array();

    Ubah jadi seperti ini :

    $autoload['libraries'] = array('database');
    $autoload['helper'] = array('url');

    Kode diatas digunakan untuk memuat (menload) class database dan url.
    Lalu simpan file tersebut.

  4. Buka file routes.php
    Cari kode berikut ini :

    $route['default_controller'] = 'welcome';

    Ubah jadi seperti ini :

    $route['default_controller'] = 'siswa';

    Kode diatas digunakan untuk menset controller mana yang akan diload pertama kali. Secara default, Codeigniter telah menset default controller yaitu welcome. Disini kita set default controller menjadi siswa.
    Lalu simpan file tersebut.

  5. Buka file database.php
    Cari kode berikut ini :

    'hostname' => 'localhost',
    'username' => '',
    'password' => '',
    'database' => '',

    Ubah jadi seperti ini :

    'hostname' => 'localhost', // Nama host
    'username' => 'root', // Username
    'password' => '', // Jika menggunakan password isi, jika tidak kosongkan saja
    'database' => 'mynotescode', // Nama databasenya

    Kode diatas digunakan untuk koneksi ke database.
    Lalu simpan file tersebut.


STEP 4 – BUAT MODEL
Sekarang kita akan membuat modelnya. Berisi sebuah fungsi untuk menampilkan semua data siswa pada tabel siswa. Buat sebuah file dengan nama SiswaModel.php, Lalu simpan pada folder xampp/htdocs/export_phpexcel_ci/application/models/. Berikut kodenya :

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

class SiswaModel extends CI_Model {
  public function view(){
    return $this->db->get('siswa')->result(); // Tampilkan semua data yang ada di tabel siswa
  }
}

Pada kode diatas, kita membuat sebuah fungsi view(). dimana didalamnya terdapat kode return $this->db->get(‘siswa’)->result(). Kode tersebut berfungsi untuk menampilkan semua data pada tabel siswa. Struktur dasar penulisannya seperti ini : return $this->db->get(‘nama_tabel‘)->result(). Lalu pada kode diatas juga ada kode return, kode tersebut digunakan untuk mengeluarkan hasil dari sebuah fungsi. Pada kasus diatas, hasil yang dikeluarkan oleh return yaitu data-data siswa.


STEP 5 – BUAT CONTROLLER
Pada tahap ini, kita akan membuat controllernya. Buat sebuah file dengan nama Siswa.php, lalu simpan pada folder xampp/htdocs/export_phpexcel_ci/application/controllers/. Berikut ini kodenya :

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

class Siswa extends CI_Controller {
  
  public function __construct(){
    parent::__construct();
    
    $this->load->model('SiswaModel');
  }
  
  public function index(){
    $data['siswa'] = $this->SiswaModel->view();
    $this->load->view('view', $data);
  }
  
  public function export(){
    // Load plugin PHPExcel nya
    include APPPATH.'third_party/PHPExcel/PHPExcel.php';
    
    // Panggil class PHPExcel nya
    $excel = new PHPExcel();

    // Settingan awal fil excel
    $excel->getProperties()->setCreator('My Notes Code')
                 ->setLastModifiedBy('My Notes Code')
                 ->setTitle("Data Siswa")
                 ->setSubject("Siswa")
                 ->setDescription("Laporan Semua Data Siswa")
                 ->setKeywords("Data Siswa");

    // Buat sebuah variabel untuk menampung pengaturan style dari header tabel
    $style_col = array(
      'font' => array('bold' => true), // Set font nya jadi bold
      'alignment' => array(
        'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, // Set text jadi ditengah secara horizontal (center)
        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER // Set text jadi di tengah secara vertical (middle)
      ),
      'borders' => array(
        'top' => array('style'  => PHPExcel_Style_Border::BORDER_THIN), // Set border top dengan garis tipis
        'right' => array('style'  => PHPExcel_Style_Border::BORDER_THIN),  // Set border right dengan garis tipis
        'bottom' => array('style'  => PHPExcel_Style_Border::BORDER_THIN), // Set border bottom dengan garis tipis
        'left' => array('style'  => PHPExcel_Style_Border::BORDER_THIN) // Set border left dengan garis tipis
      )
    );

    // Buat sebuah variabel untuk menampung pengaturan style dari isi tabel
    $style_row = array(
      'alignment' => array(
        'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER // Set text jadi di tengah secara vertical (middle)
      ),
      'borders' => array(
        'top' => array('style'  => PHPExcel_Style_Border::BORDER_THIN), // Set border top dengan garis tipis
        'right' => array('style'  => PHPExcel_Style_Border::BORDER_THIN),  // Set border right dengan garis tipis
        'bottom' => array('style'  => PHPExcel_Style_Border::BORDER_THIN), // Set border bottom dengan garis tipis
        'left' => array('style'  => PHPExcel_Style_Border::BORDER_THIN) // Set border left dengan garis tipis
      )
    );

    $excel->setActiveSheetIndex(0)->setCellValue('A1', "DATA SISWA"); // Set kolom A1 dengan tulisan "DATA SISWA"
    $excel->getActiveSheet()->mergeCells('A1:E1'); // Set Merge Cell pada kolom A1 sampai E1
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(TRUE); // Set bold kolom A1
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(15); // Set font size 15 untuk kolom A1
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // Set text center untuk kolom A1

    // Buat header tabel nya pada baris ke 3
    $excel->setActiveSheetIndex(0)->setCellValue('A3', "NO"); // Set kolom A3 dengan tulisan "NO"
    $excel->setActiveSheetIndex(0)->setCellValue('B3', "NIS"); // Set kolom B3 dengan tulisan "NIS"
    $excel->setActiveSheetIndex(0)->setCellValue('C3', "NAMA"); // Set kolom C3 dengan tulisan "NAMA"
    $excel->setActiveSheetIndex(0)->setCellValue('D3', "JENIS KELAMIN"); // Set kolom D3 dengan tulisan "JENIS KELAMIN"
    $excel->setActiveSheetIndex(0)->setCellValue('E3', "ALAMAT"); // Set kolom E3 dengan tulisan "ALAMAT"

    // Apply style header yang telah kita buat tadi ke masing-masing kolom header
    $excel->getActiveSheet()->getStyle('A3')->applyFromArray($style_col);
    $excel->getActiveSheet()->getStyle('B3')->applyFromArray($style_col);
    $excel->getActiveSheet()->getStyle('C3')->applyFromArray($style_col);
    $excel->getActiveSheet()->getStyle('D3')->applyFromArray($style_col);
    $excel->getActiveSheet()->getStyle('E3')->applyFromArray($style_col);

    // Panggil function view yang ada di SiswaModel untuk menampilkan semua data siswanya
    $siswa = $this->SiswaModel->view();

    $no = 1; // Untuk penomoran tabel, di awal set dengan 1
    $numrow = 4; // Set baris pertama untuk isi tabel adalah baris ke 4
    foreach($siswa as $data){ // Lakukan looping pada variabel siswa
      $excel->setActiveSheetIndex(0)->setCellValue('A'.$numrow, $no);
      $excel->setActiveSheetIndex(0)->setCellValue('B'.$numrow, $data->nis);
      $excel->setActiveSheetIndex(0)->setCellValue('C'.$numrow, $data->nama);
      $excel->setActiveSheetIndex(0)->setCellValue('D'.$numrow, $data->jenis_kelamin);
      $excel->setActiveSheetIndex(0)->setCellValue('E'.$numrow, $data->alamat);
      
      // Apply style row yang telah kita buat tadi ke masing-masing baris (isi tabel)
      $excel->getActiveSheet()->getStyle('A'.$numrow)->applyFromArray($style_row);
      $excel->getActiveSheet()->getStyle('B'.$numrow)->applyFromArray($style_row);
      $excel->getActiveSheet()->getStyle('C'.$numrow)->applyFromArray($style_row);
      $excel->getActiveSheet()->getStyle('D'.$numrow)->applyFromArray($style_row);
      $excel->getActiveSheet()->getStyle('E'.$numrow)->applyFromArray($style_row);
      
      $no++; // Tambah 1 setiap kali looping
      $numrow++; // Tambah 1 setiap kali looping
    }

    // Set width kolom
    $excel->getActiveSheet()->getColumnDimension('A')->setWidth(5); // Set width kolom A
    $excel->getActiveSheet()->getColumnDimension('B')->setWidth(15); // Set width kolom B
    $excel->getActiveSheet()->getColumnDimension('C')->setWidth(25); // Set width kolom C
    $excel->getActiveSheet()->getColumnDimension('D')->setWidth(20); // Set width kolom D
    $excel->getActiveSheet()->getColumnDimension('E')->setWidth(30); // Set width kolom E
    
    // Set height semua kolom menjadi auto (mengikuti height isi dari kolommnya, jadi otomatis)
    $excel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1);

    // Set orientasi kertas jadi LANDSCAPE
    $excel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);

    // Set judul file excel nya
    $excel->getActiveSheet(0)->setTitle("Laporan Data Siswa");
    $excel->setActiveSheetIndex(0);

    // Proses file excel
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment; filename="Data Siswa.xlsx"'); // Set nama file excel nya
    header('Cache-Control: max-age=0');

    $write = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
    $write->save('php://output');
  }
}

Pada controller ini, kita membuat 3 fungsi. fungsi pertama yaitu public function __construct(){, fungsi ini berfungsi untuk menjalankan suatu aksi ketika controller main diload. Didalam fungsi ini, terdapat kode $this->load->model(‘SiswaModel’);, kode tersebut berfungsi untuk memuat (meload) model siswa (yang pada step sebelumnya kita buat) agar kita bisa mengakses fungsi-fungsi yang ada didalam model tersebut.

Fungsi yang kedua yaitu public function index(). Dalam fungsi ini ada kode $data[‘siswa’] = $this->SiswaModel->view();, kode tersebut digunakan untuk mengambil hasil query sql dari fungsi view() yang ada pada model siswa (SiswaModel.php) lalu memasukannya ke dalam array data dengan index siswa ($data[‘siswa’]). Pada fungsi index() ini juga, terdapat kode $this->load->view(‘view’, $data);. Kode tersebut berfungsi untuk memuat (meload) file view.php (file ini akan kita buat pada step selanjutnya) dan mengirimkan array data ($data) tadi ke file tersebut.

Lalu pada function export(), disitu terdapat kode :

$excel->setActiveSheetIndex(0)->setCellValue(‘A1’, “DATA SISWA”);
Seperti yang sudah saya jelaskan lewat komentar, skrip diatas berfungsi untuk menset kolom A1 dengan tulisan DATA SISWA. Mungkin ada yang bingung maksud dari A1 disini apa? lihat gambar berikut ini :

Set Value - Cara Membuat Export Data Ke Excel Dengan PHPExcel dan Codeigniter

Yang saya beri tanda panah itulah yang dimaksud dengan kolom A1. Saya harap Anda paham maksud saya.

$excel->getActiveSheet()->mergeCells(‘A1:F1’);
Fungsi dari skrip diatas adalah untuk membuat “Merge Cells”. Dan arti dari ‘A1:F1’ itu adalah buat merge kolom dari kolom A1 sampai dengan kolom F1. Untuk lebih jelasnya lihat gambar dibawah :

Merge Cells - Cara Membuat Export Data Ke Excel Dengan PHPExcel dan Codeigniter

Setelah di merge akan menghasilkan seperti gambar berikut :

After Merge - Cara Membuat Export Data Ke Excel Dengan PHPExcel dan Codeigniter

Mungkin itu tambahan penjelasan dari skrip proses excel nya. untuk lebih lengkapnya mengenai fungsi apa saja yang disediakan oleh PHPExcel, Anda bisa membaca dokumentasinya langsung. Klik link berikut untuk download dokumentasi PHPExcel nya : Download.



STEP 6 – BUAT VIEW
Selanjutnya kita akan buat sebuah file untuk menampilkan data siswa dan tombol export nya. Buat file baru dengan nama view.php, lalu simpan pada folder xampp/htdocs/export_phpexcel_ci/application/views/. Berikut ini kode dan tampilannya :

View - Cara Membuat Export Data Ke Excel Dengan PHPExcel dan Codeigniter

<h1>Data Siswa</h1><hr>
<a href="<?php echo base_url("index.php/siswa/export"); ?>">Export ke Excel</a><br><br>

<table border="1" cellpadding="8">
<tr>
  <th>NIS</th>
  <th>Nama</th>
  <th>Jenis Kelamin</th>
  <th>Alamat</th>
</tr>

<?php
if( ! empty($siswa)){ // Jika data pada database tidak sama dengan empty (alias ada datanya)
  foreach($siswa as $data){ // Lakukan looping pada variabel siswa dari controller
    echo "<tr>";
    echo "<td>".$data->nis."</td>";
    echo "<td>".$data->nama."</td>";
    echo "<td>".$data->jenis_kelamin."</td>";
    echo "<td>".$data->alamat."</td>";
    echo "</tr>";
  }
}else{ // Jika data tidak ada
  echo "<tr><td colspan='4'>Data tidak ada</td></tr>";
}
?>
</table>

Pada kode diatas terdapat kode foreach($siswa as $data){, kode tersebut akan manampilkan satu per satu data siswa sampai data siswa yang terakhir.
echo “<td>”.$data->nis.”</td>”;
echo “<td>”.$data->nama.”</td>”;
echo “<td>”.$data->jenis_kelamin.” </td>”;
echo “<td>”.$data->alamat.”</td>”;
Pada kode diatas, yang saya beri tanda merah. Itu harus sama dengan nama kolom / field yang ada di database tabel siswa.


Mungkin sekian untuk catatan kali ini. Semoga bisa bermanfaat. Jika ada yang kurang dipahami, langsung tanyakan pada form komentar dibawah ini. Jangan lupa LIKE dan SHARE nya, Terimakasih banyak.

Happy Coding ^_^


SOURCE CODE
Untuk mengunduh source code nya, klik link berikut ini : Download.


SUMBER & REFERENSI
Dokumentasi Codeigniter : https://www.codeigniter.com/user_guide
Dokumentasi PHPExcel : download

Tutorial membuat export data ke excel dengan plugin PHPExcel dan Codeigniter 3, Tutorial membuat laporan excel dengan PHPExcel dan CI 3, Cara membuat laporan excel dengan PHPExcel dan Codeigniter 3, Tutorial membuat export data dari database ke excel dengan PHPExcel dan Codeigniter 3, Cara membuat export data dari database ke excel dengan PHPExcel dan Codeigniter 3, Source code export data ke excel dengan plugin PHPExcel dan Codeigniter 3

PHPExcel

(Total : 47,554 viewers, 2 viewers today)
export-excel-dengan-phpexcel-codeigniter

ABOUT THE AUTHOR

Interested in android programming, long time focused on web development. Visit My Profile Site at www.rizaldimaulidia.com

POST YOUR COMMENTS

Your email address will not be published. Required fields are marked *

Name *

Email *

Website

44 Comments

  1. dika1234

    Gan, saya menggunakan PHP 5.6 tp excelnya tidak terdownload dan di inspect element hanya muncul karakter aneh.

    mohon pencerahannya terima kasih

  2. yoga dwi

    bagaimana kalau dalam 1 kotak row ada 5 data, misalnya :
    1. isi 1
    2. isi 2
    3. isi 3
    4. isi 4
    5. isi 5
    dari sebuah data array, saya nyoba blm berhasil .. mohon pencerahannya, terimakasih kang

    • Kalau saya biasanya diakali pakai enter aja, jadi tetap 1 kolom. untuk bisa menggunakan enter di phpexcel, bisa pakai “\n”. contoh penerapan :
      “1. isi 1\n2. isi 2\n3. dst….”

      Lalu jangan lupa, set kolom tersebut WrapText. cek dokumentasi phpexcel yang ada di bagian referensi tutorial ini (dibawah). disitu ada cara set kolom wraptext gimana.

  3. bagus1234

    Mas…saya sudah coba di localhost pake xampp jalan, tapi ketika deploy di server centos 7, excel downloadnya error, gak bisa dibuka corrupt. Ketika saya paksa buka dengan notepad muncu error seperti ini :
    It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone.

    • coba edit file index.php yang ada di root folder nya (yg sejajar dengan folder application). tambah script berikut setelah tag < ?php : date_default_timezone_set(‘Asia/Jakarta’);

  4. firmanudin

    mau tanya.
    saya sudah berhasil export.
    data merupakan hasil JOIN TABEL di model.
    yg saya tanyakan kok ga bisa looping ya.
    yang bisa ke set di excel cuma baris ke 1 tok.

    • periksa dulu, hasil querynya itu ada berapa data? coba print_r dulu hasil querynya untuk cek apakah querynya sudah benar atau belum

  5. hadiniyah

    om gmn caranya kalau saya ingin membuat menjadi laporan perhari/bulan/tahun ?

  6. Reza Pratama

    gan saya mau tanya, ini kan dia PHPExcelnya udah mau di pc saya kebetulan saya bikin programnya di pc, terus klo semisal saya pindahin ke laptop lain dia error gitu gan kayak file librarynya ga ke baca padahal sudah saya pindahkan folder PHPExcelnya

  7. Sayid Alwi

    Halo mas, saya mau tanya. kok waktu saya export datanya muncul error kayak gini yaa?? mohon penjelasannya mas.

    A PHP Error was encountered

    Severity: 8192

    Message: Array and string offset access syntax with curly braces is deprecated

    Filename: Shared/String.php

    Line Number: 526

    Backtrace:

    File: ..\export_phpexcel_ci\application\third_party\PHPExcel\PHPExcel\Autoloader.php
    Line: 79
    Function: _error_handler

    File: ..\export_phpexcel_ci\application\third_party\PHPExcel\PHPExcel\Autoloader.php
    Line: 79
    Function: require

    File: ..\export_phpexcel_ci\application\third_party\PHPExcel\PHPExcel\Autoloader.php
    Line: 11
    Function: spl_autoload_call

    File: ..\export_phpexcel_ci\application\third_party\PHPExcel\PHPExcel.php
    Line: 6
    Function: require

    File: ..\export_phpexcel_ci\application\controllers\Siswa.php
    Line: 18
    Function: include

    File: ..\export_phpexcel_ci\index.php
    Line: 315
    Function: require_once

    • sepertinya ini karena versi php yang om gunakan adalah yang terbaru ya. Saya sudah perbaiki librari PHPExcelnya. silahkan download ulang librari PHPExcelnya saja, caranya ada pada STEP 1 No. 2.

      • Sayid Alwi

        Iya mas benar saya pake xampp dengan php 7 dan yang paling baru. tapi saya waktu itu sempat coba di xampp php 5 juga sama mas. tapi saya coba download dulu yang terbaru mas.

          • Sayid Alwi

            Halo mas, maaf baru sempat konfirmasi lagi. saya sudah coba tapi gak mau jalan juga. Ini adalah errornya mas.

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Shared\String.php on line 538

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Shared\String.php on line 539

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Shared\String.php on line 541

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Shared\String.php on line 542

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2551

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2551

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2672

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2672

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2676

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2764

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2768

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 2780

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3034

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3166

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3168

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3169

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3457

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3457

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3460

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3461

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3891

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3891

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3936

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3942

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 3998

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php on line 4001

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Worksheet\AutoFilter.php on line 720

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Worksheet\AutoFilter.php on line 720

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 812

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 813

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 816

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 817

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 817

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 819

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 820

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 820

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 820

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell.php on line 824

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell\DefaultValueBinder.php on line 82

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell\DefaultValueBinder.php on line 90

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Cell\DefaultValueBinder.php on line 90

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\ReferenceHelper.php on line 884

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\ReferenceHelper.php on line 884

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\ReferenceHelper.php on line 885

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\ReferenceHelper.php on line 885

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 75

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 76

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 77

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 79

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 82

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 83

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 84

            Warning: Cannot modify header information – headers already sent by (output started at C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation.php:3891) in C:\xampp7\htdocs\phpexcel1\Examples\01simple-download-xlsx.php on line 85

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation\Functions.php on line 321

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation\Functions.php on line 324

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation\Functions.php on line 562

            Deprecated: Array and string offset access syntax with curly braces is deprecated in C:\xampp7\htdocs\phpexcel1\Classes\PHPExcel\Calculation\Functions.php on line 612

            Saya menggunakan php 7.4.5.

          • Tutorial ini menggunakan librari PHPExcel, dimana sudah saya cek hanya mendukung sampai PHP Versi 7.2.8. jadi mungkin om nya bisa download xampp dengan php yang versinya dibawah 7.2.8.
            Untuk tutorial buat yang pakai PHP versi diatas 7.2.8 akan saya buatkan, jadi tunggu saja update nya

  8. fadhilah

    excell cannot open the file, because the file format or file extension is not valid. verify that the file has not been corrupted and that the file extension matches the format of the file, punya saya ketika excelnya dibuka ada peringatan gini, kira” kenapa kak?

    • coba buka saja mba excelnya. sepertinya ada error di php nya, buka excelnya, biar keliatan errornya apa.

  9. Ariefhidayat

    misalnya saya punya data 1000, gmn caranya agar proses export excelnya bisa menjadi 500 dan 500 ganagar tidak berat saat melakukan proses export nya.

    makasih

    • tambahkan limit 500 om pada querynya.
      jadi pada export pertama kali, set limit : LIMIT 0, 500. export kedua kali set limit : LIMIT 501, 1000.
      Kuncinya ada disitu.

  10. sanbasori

    file hasil exportnya corrupt, knp ya bang?

    • ada error ketika exportnya om? atau coba paksa buka excelnya, biasanya suka muncul tulisan error di excelnya

  11. Alifah AP

    Bang, maaf mau nanya.. kok saya coba hasil output nya berantakan ya isinya? gak sesuai dengan posisi kolom dan barisnya. Terimakasih

    • yang harus diperhatikan saat menggunakan librari ini adalah penentuan Kolom + Row nya. Silahkan om simak dengan baik-baik penjelasan saya pada STEP 5 pada tutorial ini

  12. Alif_maulana

    Mohon maaf sebelumnya saya ingin bertanya, ketika saya mrubah data datanya menjadi data yang berbeda kenap file excelnya menjadi corrupt dan tidak bisa terbuka….terimakasih

      • alexander

        maaf gan saya mau tnya, saya ubah datanya menjadi data yang berbeda trus kenapa file excelnya menjadi corrupt dan tidak bisa terbuka?
        mohon sekalian solusinya gan
        terimakasih

          • alexander

            iya gan, bisa download tapi tidak bisa dibuka sama sekali
            mohon solusinya gan
            terimakasih

          • alexander

            sudah bisa gan saya ubah modelnya sm foreachnya
            terimakasih atas informasi di web ini gan, Terimakasih

  13. nazar dihartika

    om, ketika beres export di excel kolom NIS muncul “the number in this cell is formatted as text or preceded by an apostrophe”, cara biar ketika export kolom number gak ada tambahan apostrophe gimana ya om?

  14. azzam khalid

    Gan, waktu ane export malah muncul kyk gini..

    Object not found!
    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error

    • base_url di file config.php nya sudah di sesuaikan? coba ikuti STEP 3 Nomor 1
      lalu pastikan URL di link Export ke Excel sudah mengarah ke controller/function untuk export nya

  15. beelzebondz

    ane coba di localhost sendiri work gan..
    tapi sesudah saya hosting di webserver saya debian 9 dan apache2 ada error
    pada bagian APPATH nya gan
    sarannya gan

  16. cucusugiono

    makasi tutorialnya mas, sangat membantu saya menggunakan CI dan PHPExcel

    • Rizaldi Maulidia Achmad

      sama-sama om. senang bisa membantu 😀
      semoga lancar terus belajarnya om

  17. Seftianasd

    Gan Kenapa Error Ketika Export
    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in C:\xampp\htdocs\webtani\application\third_party\PHPExcel\PHPExcel\Cell.php on line 582

    • Rizaldi Maulidia Achmad

      isi data nya ada berapa om? dari errornya itu melebihi waktu maksimal eksekusi di php nya. saran dari saya, kalau data yang di export banyak. lebih baik di bagi jadi beberapa data saja. agar tidak berat saat melakukan proses export nya

NOTE ARCHIVES