• Как интегрировать phpexcel в MVC?

    @Nick711 Автор вопроса
    Вот заголовки отправляемые с индексного файла:
    $do=$_GET['do'];
    $fiename=$do."_".date('d_m_y');
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="'.$fiename.'.xls"');
    header('Cache-Control: max-age=0');
    header('Cache-Control: max-age=1');
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    header ('Cache-Control: cache, must-revalidate');
    header ('Pragma: public');

    Вот примерно,что во view:
    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);
    define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
    ');
    date_default_timezone_set('Europe/Moscow');
    require_once 'Classes/PHPExcel/IOFactory.php';
    $objReader = PHPExcel_IOFactory::createReader('Excel2007');
    $objPHPExcel = $objReader->load("Classes/templates/26template.xlsx");
    $data = array(array('fio' => 'Welcome in the end',
    'dtr' => '18.01.1994',
    'pol' => 'm',
    'pasport' => '456454521',
    'pdata' => '18.01.1995',
    'fdata' => '18.01.1997',
    'loc' => 'rus',
    'max' => '-',
    'log' => 'йад'
    ),
    array('fio' => 'Welcome in the end',
    'dtr' => '10.05.1990',
    'pol' => 'm',
    'pasport' => '458415421',
    'pdata' => '18.01.2000',
    'fdata' => '18.01.2005',
    'loc' => 'rus',
    'max' => '-',
    'log' => 'йцоол'
    ),
    array('fio' => 'welcome in the end',
    'dtr' => '25.02.1994',
    'pol' => 'm',
    'pasport' => '452115421',
    'pdata' => '01.05.1998',
    'fdata' => '18.01.2005',
    'loc' => 'rus',
    'max' => '-',
    'log' => 'dsf'
    )
    );
    $company = 'hgj';
    $transport = 'fghjgh';
    $punct = 'fgfgjgf';
    $numreys = '45';
    $objPHPExcel->getActiveSheet()->setCellValue('J2', date('d.m.Y'));
    $objPHPExcel->getActiveSheet()->setCellValue('J3', $punct);
    $objPHPExcel->getActiveSheet()->setCellValue('E1', $company);
    $objPHPExcel->getActiveSheet()->setCellValue('C2', $transport);
    $objPHPExcel->getActiveSheet()->setCellValue('I4', $numreys);

    $baseRow = 7;
    foreach($data as $r => $dataRow) {
    $row = $baseRow + $r;
    $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);

    $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $r+1)
    ->setCellValue('B'.$row, $dataRow['fio'])
    ->setCellValue('C'.$row, $dataRow['pol'])
    ->setCellValue('D'.$row, $dataRow['dtr'])
    ->setCellValue('E'.$row, $dataRow['pasport'])
    ->setCellValue('F'.$row, $dataRow['pdata'])
    ->setCellValue('G'.$row, $dataRow['fdata'])
    ->setCellValue('H'.$row, $dataRow['loc'])
    ->setCellValue('I'.$row, $dataRow['max'])
    ->setCellValue('J'.$row, $dataRow['log']);
    }

    $objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');
    Ответ написан
    Комментировать