PHPExcel导出不起作用: displays "the website cannot be reached"

标签 php phpexcel

我已经从服务器克隆了一个项目并安装在我的本地设置中。 我正在尝试使用 PHPExcel 将 Excel 文件导出到浏览器。它在服务器中运行良好。但是本地设置有问题。 我还检查了列和字段的数量,它们都很好。 下面是代码:

<?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;
?>

我收到此错误:

无法访问该网站

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

它与当前在服务器上运行的实时版本运行良好。可能是什么问题?

最佳答案

这是 phpExcel 与 php7 结合使用时出现的错误:

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

关于PHPExcel导出不起作用: displays "the website cannot be reached",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46599112/

相关文章:

javascript - 使用现有代码根据浏览器宽度更改图像网址

php - 从 Android 上传大文件(大于 10MB)到 PHP 服务器

PHP Excel 图像改变大小

PHPEXCEL : How to merge excel row based on array value

php - 使用 phpexcel 创建多个工作表时出现一个额外的工作表

php - 联系表单 php 邮件代码不起作用

php - 从下拉列表中获取值。 (有点棘手)

php - 如何在不先更新镜像的情况下更新mysql中的数据

php - 将 Excel 日期序列转换回可读的日期格式

PHP:如何从具有科学记数法/指数格式的 Excel 数据中获取字符串格式的数据?