Azima
Azima

Reputation: 4151

PHPExcel export not working : displays "the website cannot be reached"

I have cloned a project from server and installed in my local setup. I am trying to export excel file to the browser using PHPExcel. It is working fine in the server. But there is problem with the local setup. Also I checked number of columns and fields and they are fine. Below is the code:

<?php
//PHPExcel starts from here
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Asia/Kathmandu');

if (PHP_SAPI == 'cli')
    die('Error in loading PHPExcel');


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

// Set document properties
$objPHPExcel->getProperties()->setCreator("GBD Admin")
        ->setLastModifiedBy("GBD Admin")
        ->setTitle("Weekly checkin/checkout log")
        ->setDescription("Test document for PHPExcel, generated using PHP classes.")
        ->setKeywords("Checkin/Checkout Logs")
        ->setCategory("Checkin/Checkout Logs");


// Add some data
$objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A1', 'Date of Export')
        ->setCellValue('B1', $now)
        ->setCellValue('A3', 'Employee Name')
        ->setCellValue('B3', ' Checkin-date')
        ->setCellValue('C3', ' Checkin-time')
        ->setCellValue('D3', ' Checkout-date')
        ->setCellValue('E3', ' Checkout-time')
        //                        ->setCellValue('F3', ' Total-time Spent')
        //                        ->setCellValue('G3', ' Over-time')
        ->setCellValue('F3', ' Early checkout-remarks')
        ->setCellValue('G3', ' Late checkin-remarks');

//                        Newly added statement below
//                        ->setCellValue('H3', ' Absent/Leave Remarks');
$objPHPExcel->getActiveSheet()->getStyle('A1:B1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A3:H3')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->fromArray($results, null, 'A5');
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(45);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(45);

// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Login-data-' . $now);


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Login_data_' . $now . '.xls"');
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

$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>

I have been getting this error:

This site can’t be reached

The webpage at http://localhost/gbdportal-new/Export might be temporarily down or it may have moved permanently to a new web address. ERR_INVALID_RESPONSE

It is working fine with the live version currently running on the server. What could be the problem?

Upvotes: 2

Views: 14037

Answers (2)

Saad Mirza
Saad Mirza

Reputation: 1187

on Line 581 of file PHPExcel/Classes/PHPExcel/Calculation/Functions.php there is a " break" , simply comment.

Upvotes: 1

blaimi
blaimi

Reputation: 819

This is a bug in phpExcel in combination with php7:

https://github.com/PHPOffice/PHPExcel/issues/716

Upvotes: 3

Related Questions