Beranda · Contact Us · Downloads

Yii: Membaca Excel menggunakan Php Excel Reader

Php-excel-reader memiliki kemampuan untuk membaca format binary dari file XLS dan menampilkannya sesuai dengan isi dan formatnya. 


1. Pertama silahkan unduh library php-excel-reader terlebih dahulu, klik download

2. Kemuadian siapkan file .xls (Excel 97-2003 workbook).

3. Letakkan file xls dan excel_reader2.php di dalam folder webaccess
    Di sini saya meletakkannya di dalam folder C:\wamp\www\Helloword\upload

4. Silahkan pahami kode di bawah ini :
<?php
error_reporting(E_ALL ^ E_NOTICE);
require_once Yii::app()->basePath.'/../upload/excel_reader2.php';
$example = Yii::app()->basePath.'/../upload/transactions.xls' ;
$data = new Spreadsheet_Excel_Reader($example);
?>
<html>
<head>
<style>
table.excel {
    border-style:ridge;
    border-width:1;
    border-collapse:collapse;
    font-family:sans-serif;
    font-size:12px;
}
table.excel thead th, table.excel tbody th {
    background:#CCCCCC;
    border-style:ridge;
    border-width:1;
    text-align: center;
    vertical-align:bottom;
}
table.excel tbody th {
    text-align:center;
    width:20px;
}
table.excel tbody td {
    vertical-align:bottom;
}
table.excel tbody td {
    padding: 0 3px;
    border: 1px solid #EEEEEE;
}
</style>
</head>

<body>
<?php echo $data->dump(true,true); ?>
</body>
</html>

 Hasilnya :


Catatan :
  1. Jika menemukan error function split() is deprecated silahkan modifikasi excel_reader2.php, replace kata split dengan explode
  2. Jika menemukan error Assigning the return value of new by reference is deprecated silahkan modifikasi excel_reader2.php
    ganti kode berikut
    $this->_ole =& new OLERead();

    dengan
    $t = new OLERead();
    $this->_ole =& $t;


Good Luck!

Artikel keren lainnya:

1 Tanggapan untuk "Yii: Membaca Excel menggunakan Php Excel Reader"

  1. Saya dapat error The filename C:\xampp\htdocs\yiicrm\protected\uploads\20160608100750.xls is not readable.
    Bagaimana fix?

    BalasHapus