php://output issue without error

Topics: Developer Forum
Aug 15, 2014 at 5:13 AM
Hi, i having a problem that cannot output the excel to client but is work if save to server. My code stated below:
Javascript:
<a href="javascript:void(0)" class="icon-{!$button.params.icon!}" onclick="doExport()"></a>

function doExport(param, success, error){
    $.messager.progress({text:'Processing. Please wait...'});
        $.ajax({
        url: 'index.php',
        type: 'POST',
        dataType: 'json',
        jsonp: false,
        data: {
{!if isset($grid.searches)!}
            aqfld: {
{!foreach from=$grid.searches item=search name=search!}
                {!$search.name!}: $('#{!$search.name!}').searchbox('getName')
{!if !$smarty.foreach.search.last!},{!/if!}
{!/foreach!}
            },
            aqtxt: {
{!if isset($grid.options.params.aqtxt)!}
{!foreach from=$grid.options.params.aqtxt key=key item=param name=param!}
            {!$key!}: '{!$param!}',
{!/foreach!}
{!/if!}
{!foreach from=$grid.searches item=search name=search!}
                {!$search.name!}: $('#{!$search.name!}').searchbox('getValue')
{!if !$smarty.foreach.search.last!},{!/if!}
{!/foreach!}
            },
{!/if!}
{!if isset($grid.filters)!}
            aflt: {
{!if isset($grid.options.params.aflt)!}
{!foreach from=$grid.options.params.aflt key=key item=param name=param!}
            {!$key!}: '{!$param!}',
{!/foreach!}
{!/if!}
{!foreach from=$grid.filters item=filter name=filter!}
                {!$filter.name!}: $('#{!$filter.name!}').combobox('getValue{!if isset($filter.params.multiple) && $filter.params.multiple!}s{!/if!}')
{!if !$smarty.foreach.filter.last!},{!/if!}
{!/foreach!}
            },
{!/if!}
{!if isset($grid.ranges)!}
            aqrng: {
{!foreach from=$grid.ranges item=range name=range!}
                {!$range.name!}from: $('#{!$range.name!}From').datebox('getValue'),
                {!$range.name!}to: $('#{!$range.name!}To').datebox('getValue')
{!if !$smarty.foreach.range.last!},{!/if!}
{!/foreach!}
            },
{!/if!}
            ist: -1,
            ilt: 0,
            //sfld: sort,
            //sodr: order,
{!if isset($grid.options.params)!}
{!foreach from=$grid.options.params key=key item=param name=param!}
{!if !is_array($param) !}
            {!$key!}: '{!$param!}',
{!/if!}
{!/foreach!}
{!/if!}
{!if isset($sid)!}
            sid: {!$sid!},
{!/if!}
            iexport:'1',
            mdl:'{!$grid.module!}',
            action: 'excel'
        },
        success: function(data){
            $.messager.progress('close');
            console.log($('#{!$grid.id!}').datagrid('columns'));
            console.log(data);
        }
    });
}

PHP:
 protected function doGetExcel($params){
                //get parameters from doGetData
        $data= $this->doGetData($params, true, false);

        // Create new PHPExcel object
        $objPHPExcel = new PHPExcel();

        // Set properties
        $objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
        $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
        $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
        $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
        $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
        // Rename sheet
        $objPHPExcel->getActiveSheet()->setTitle('Member details');

        // Add some data
        $objPHPExcel->setActiveSheetIndex(0);
        $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Account');
        $objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Full Name');
        $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Channel');
        $objPHPExcel->getActiveSheet()->SetCellValue('D1', 'Currency');
        $objPHPExcel->getActiveSheet()->SetCellValue('E1', 'Main Wallet');
        $objPHPExcel->getActiveSheet()->SetCellValue('F1', 'Deposit');
        $objPHPExcel->getActiveSheet()->SetCellValue('G1', 'Withdrawal');
        $objPHPExcel->getActiveSheet()->SetCellValue('H1', 'Tel. No');
        $objPHPExcel->getActiveSheet()->SetCellValue('I1', 'Email');
        $objPHPExcel->getActiveSheet()->SetCellValue('J1', 'Registered On');
        $objPHPExcel->getActiveSheet()->SetCellValue('K1', 'Last Deposit');
        $objPHPExcel->getActiveSheet()->SetCellValue('L1', 'Status');
        $objPHPExcel->getActiveSheet()->SetCellValue('M1', 'IP Address');
        $objPHPExcel->getActiveSheet()->SetCellValue('N1', 'Location');


        foreach ($data['rows'] as $key => $value){
            $rowID = $key + 2;
            $columnID = 'A';
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['code']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['fullname']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['channel']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['crccode']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['balance']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['deposit']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['withdrawal']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['telephone']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['email']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['created']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['lastdeposit']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['status']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['createdip']);
            $objPHPExcel->getActiveSheet()->setCellValue($columnID++.$rowID, $value['location']);
        }

        // Auto resize the columns width
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setAutoSize(true);

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');

        ob_end_clean();

        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="myfile.xlsx"');
        header('Cache-Control: max-age=0');

        $objWriter->save('php://output');
        $objPHPExcel->disconnectWorksheets();
        unset($objPHPExcel);
        }
Is there any solution? Thanks alot!