Advertisement
sh1fralf4tih

Untitled

Nov 12th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.95 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. use PhpOffice\PhpSpreadsheet\Helper\Sample;
  5. use PhpOffice\PhpSpreadsheet\IOFactory;
  6. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  7. // End load library phpspreadsheet
  8.  
  9. class Lapexcel extends CI_Controller {
  10.  
  11.     // Load model
  12.     public function __construct()
  13.     {
  14.         parent::__construct();
  15.         $this->load->model('laporan/m_kios');
  16.         $this->load->model('lapexcel/sheetmkios');
  17.     }
  18.     function index() {
  19.         $customers = $this->m_kios->get_list_customers();
  20.         $salesmans = $this->m_kios->get_list_salesmans();
  21.         $clusters = $this->m_kios->get_list_clusters();
  22.         $kotas = $this->m_kios->get_list_kotas();
  23.        
  24.         $opt = array('' => 'Show All');
  25.         foreach ($customers as $customer) {
  26.             $opt[$customer] = $customer;
  27.         }
  28.         $opt2 = array('' => 'Show All');
  29.         foreach ($salesmans as $salesman) {
  30.             $opt2[$salesman] = $salesman;
  31.         }
  32.         $opt3 = array('' => 'Show All');
  33.         foreach ($clusters as $cluster) {
  34.             $opt3[$cluster] = $cluster;
  35.         }
  36.         $opt4 = array('' => 'Show All');
  37.         foreach ($kotas as $kota) {
  38.             $opt4[$kota] = $kota;
  39.         }
  40.         $data = array("title" => "Details M-KIOS","title_menu" => "LAPORAN M-KIOS","title_sub_menu" => "Details M-KIOS");
  41.         $data['form_customers'] = form_dropdown('',$opt,'','id="customer" class="form-control js-example-basic-single"');
  42.         $data['form_salesmans'] = form_dropdown('',$opt2,'','id="salesman" class="form-control js-example-basic-single"');
  43.         $data['form_clusters'] = form_dropdown('',$opt3,'','id="cluster" class="form-control js-example-basic-single"');
  44.         $data['form_kotas'] = form_dropdown('',$opt4,'','id="kota" class="form-control js-example-basic-single"');
  45.         $this->template->display("laporan/excel/details_mkios",$data);
  46.     }
  47.     // Export ke excel
  48.     public function export()
  49.     {
  50.         if(isset($_POST['submit']))
  51.         {
  52.             $dari = $this->input->post("DARI");
  53.             $sampai = $this->input->post("SAMPAI");
  54.             $isi = $this->sheetmkios->get_data_cell($dari,$sampai);
  55.         }
  56.         // Create new Spreadsheet object
  57.         $spreadsheet = new Spreadsheet();
  58.  
  59.         // Set document properties
  60.         $spreadsheet->getProperties()->setCreator('Andoyo - Java Web Media')
  61.         ->setLastModifiedBy('Andoyo - Java Web Medi')
  62.         ->setTitle('Office 2007 XLSX Test Document')
  63.         ->setSubject('Office 2007 XLSX Test Document')
  64.         ->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
  65.         ->setKeywords('office 2007 openxml php')
  66.         ->setCategory('Test result file');
  67.  
  68.         // Add some data
  69.         $spreadsheet->setActiveSheetIndex(0)
  70.         ->setCellValue('B3', 'NAMA SALES')
  71.         ->setCellValue('C3', 'TOTAL')
  72.         ;
  73.  
  74.         // Miscellaneous glyphs, UTF-8
  75.         $i=2; foreach($isi as $isi) {
  76.  
  77.         $spreadsheet->setActiveSheetIndex(0)
  78.         ->setCellValue('B'.$i, $isi->NMSAL)
  79.         ->setCellValue('C'.$i, $isi->TOTAL);
  80.         $i++;
  81.         }
  82.  
  83.         // Rename worksheet
  84.         $spreadsheet->getActiveSheet()->setTitle('Report Excel '.date('d-m-Y H'));
  85.  
  86.         // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  87.         $spreadsheet->setActiveSheetIndex(0);
  88.  
  89.         // Redirect output to a client’s web browser (Xlsx)
  90.         header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  91.         header('Content-Disposition: attachment;filename="Report Excel.xlsx"');
  92.         header('Cache-Control: max-age=0');
  93.         // If you're serving to IE 9, then the following may be needed
  94.         header('Cache-Control: max-age=1');
  95.  
  96.         // If you're serving to IE over SSL, then the following may be needed
  97.         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  98.         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
  99.         header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  100.         header('Pragma: public'); // HTTP/1.0
  101.  
  102.         $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
  103.         $writer->save('php://output');
  104.         exit;
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement