2017-10-06 5 views
0

J'ai cloné un projet du serveur et installé dans ma configuration locale. J'essaie d'exporter le fichier Excel vers le navigateur en utilisant PHPExcel. Cela fonctionne bien sur le serveur. Mais il y a un problème avec la configuration locale. Aussi j'ai vérifié le nombre de colonnes et de champs et ils vont bien. est sous le code:L'exportation de PHPExcel ne fonctionne pas: affiche "le site Web ne peut pas être atteint"

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

Je reçois cette erreur:

Ce site ne peut pas être atteint

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

Il fonctionne bien avec la version en direct en cours d'exécution sur le serveur. Quel pourrait être le problème?

+1

Supprimer les en-têtes et vérifiez si aucune erreur est levée/ – Justinas

+0

oui j'émis reçois l'erreur: Erreur fatale: « break » non dans le contexte 'loop' ou 'switch' dans C: \ xampp \ htdocs \ gbdportal-nouveau \ fournisseur \ phpoffice \ phpexcel \ Classes \ PHPExcel \ Calcul \ Functions.php on line 581 HTTP Erreur fatale: 'break' n'est pas dans le contexte 'loop' ou 'switch' (POST/Export) – Azima

+0

Voilà donc le problème. Votre serveur live supprime les erreurs, tandis que local ne l'est pas. Vous produisez une erreur au lieu du fichier Excel. – Justinas

Répondre