Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Export extends CI_Controller
- {
- function __construct() {
- parent::__construct();
- $this->routines->cekAuth();
- $this->ci =& get_instance();
- $this->load->library(array('PHPExcel','PHPExcel/IOFactory'));
- }
- function excel(){
- // misal di $idField ini adalah kolom-kolom yg akan saya ekspor ke excel
- // $idField = array('kode_brg','nama_brg','warna','qty');
- $fieldCaption = $this->input->post('fieldCaption');
- $filter = $this->input->post('filter');
- $title = 'Contoh Laporan';
- /*
- $sql = "SELECT ";
- for ($i=0; $i < count($idField); $i++) {
- $sql .= $idField[$i].",";
- }
- $sql = rtrim($sql,',');
- $sql .= " FROM nama_tabel WHERE ";
- for ($i=0; $i < count($idField); $i++) {
- $sql .= " ".$idField[$i]." LIKE '%$filter%' OR";
- }
- $sql = rtrim($sql,'OR');
- $sql .= " ORDER BY kode_brg DESC";
- $proses = $this->mymodel->openQuery($sql);
- $hasil = json_decode($proses,TRUE);
- $data = $hasil['data'];
- */
- //Silahkan lakukan SELECT query seperti biasa untuk mendapatkan data dari database
- //kode yang saya disable diatas adalah cara yg saya pakai untuk mendapatkan data dari DB
- //selanjutnya passing hasil Query ke fungsi table2Excel yang ada pada file Routines.php yg telah dibuat sebelumnya
- $export = $this->routines->table2Excel('PT. BLABLABLA',$title,$data,$fieldCaption);
- echo json_encode($export);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment