hellope

Export.php

Mar 15th, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php
  2.     defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Export extends CI_Controller
  5. {
  6.  
  7.   function __construct() {
  8.       parent::__construct();
  9.     $this->routines->cekAuth();
  10.     $this->ci =& get_instance();
  11.     $this->load->library(array('PHPExcel','PHPExcel/IOFactory'));
  12.   }
  13.  
  14.   function excel(){
  15.     // misal di $idField ini adalah kolom-kolom yg akan saya ekspor ke excel
  16.     // $idField = array('kode_brg','nama_brg','warna','qty');
  17.     $fieldCaption = $this->input->post('fieldCaption');
  18.     $filter = $this->input->post('filter');
  19.     $title = 'Contoh Laporan';
  20.     /*
  21.     $sql = "SELECT ";
  22.     for ($i=0; $i < count($idField); $i++) {
  23.       $sql .= $idField[$i].",";
  24.     }
  25.     $sql = rtrim($sql,',');
  26.     $sql .= " FROM nama_tabel WHERE ";
  27.     for ($i=0; $i < count($idField); $i++) {
  28.       $sql .= " ".$idField[$i]." LIKE '%$filter%' OR";
  29.     }
  30.     $sql = rtrim($sql,'OR');
  31.     $sql .= " ORDER BY kode_brg DESC";
  32.     $proses = $this->mymodel->openQuery($sql);
  33.     $hasil = json_decode($proses,TRUE);
  34.     $data = $hasil['data'];
  35.     */
  36.     //Silahkan lakukan SELECT query seperti biasa untuk mendapatkan data dari database
  37.     //kode yang saya disable diatas adalah cara yg saya pakai untuk mendapatkan data dari DB
  38.     //selanjutnya passing hasil Query ke fungsi table2Excel yang ada pada file Routines.php yg telah dibuat sebelumnya
  39.     $export = $this->routines->table2Excel('PT. BLABLABLA',$title,$data,$fieldCaption);
  40.     echo json_encode($export);
  41.   }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment