Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- use PhpOffice\PhpSpreadsheet\Helper\Sample;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- // End load library phpspreadsheet
- class Lapexcel extends CI_Controller {
- // Load model
- public function __construct()
- {
- parent::__construct();
- $this->load->model('laporan/m_kios');
- $this->load->model('lapexcel/sheetmkios');
- }
- function index() {
- $customers = $this->m_kios->get_list_customers();
- $salesmans = $this->m_kios->get_list_salesmans();
- $clusters = $this->m_kios->get_list_clusters();
- $kotas = $this->m_kios->get_list_kotas();
- $opt = array('' => 'Show All');
- foreach ($customers as $customer) {
- $opt[$customer] = $customer;
- }
- $opt2 = array('' => 'Show All');
- foreach ($salesmans as $salesman) {
- $opt2[$salesman] = $salesman;
- }
- $opt3 = array('' => 'Show All');
- foreach ($clusters as $cluster) {
- $opt3[$cluster] = $cluster;
- }
- $opt4 = array('' => 'Show All');
- foreach ($kotas as $kota) {
- $opt4[$kota] = $kota;
- }
- $data = array("title" => "Details M-KIOS","title_menu" => "LAPORAN M-KIOS","title_sub_menu" => "Details M-KIOS");
- $data['form_customers'] = form_dropdown('',$opt,'','id="customer" class="form-control js-example-basic-single"');
- $data['form_salesmans'] = form_dropdown('',$opt2,'','id="salesman" class="form-control js-example-basic-single"');
- $data['form_clusters'] = form_dropdown('',$opt3,'','id="cluster" class="form-control js-example-basic-single"');
- $data['form_kotas'] = form_dropdown('',$opt4,'','id="kota" class="form-control js-example-basic-single"');
- $this->template->display("laporan/excel/details_mkios",$data);
- }
- // Export ke excel
- public function export()
- {
- if(isset($_POST['submit']))
- {
- $dari = $this->input->post("DARI");
- $sampai = $this->input->post("SAMPAI");
- $isi = $this->sheetmkios->get_data_cell($dari,$sampai);
- }
- // Create new Spreadsheet object
- $spreadsheet = new Spreadsheet();
- // Set document properties
- $spreadsheet->getProperties()->setCreator('Andoyo - Java Web Media')
- ->setLastModifiedBy('Andoyo - Java Web Medi')
- ->setTitle('Office 2007 XLSX Test Document')
- ->setSubject('Office 2007 XLSX Test Document')
- ->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
- ->setKeywords('office 2007 openxml php')
- ->setCategory('Test result file');
- // Add some data
- $spreadsheet->setActiveSheetIndex(0)
- ->setCellValue('B3', 'NAMA SALES')
- ->setCellValue('C3', 'TOTAL')
- ;
- // Miscellaneous glyphs, UTF-8
- $i=2; foreach($isi as $isi) {
- $spreadsheet->setActiveSheetIndex(0)
- ->setCellValue('B'.$i, $isi->NMSAL)
- ->setCellValue('C'.$i, $isi->TOTAL);
- $i++;
- }
- // Rename worksheet
- $spreadsheet->getActiveSheet()->setTitle('Report Excel '.date('d-m-Y H'));
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $spreadsheet->setActiveSheetIndex(0);
- // Redirect output to a client’s web browser (Xlsx)
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- header('Content-Disposition: attachment;filename="Report Excel.xlsx"');
- header('Cache-Control: max-age=0');
- // If you're serving to IE 9, then the following may be needed
- header('Cache-Control: max-age=1');
- // If you're serving to IE over SSL, then the following may be needed
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
- header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
- header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
- header('Pragma: public'); // HTTP/1.0
- $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
- $writer->save('php://output');
- exit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement