2012-11-05 39 views
0

在我當前的項目中,我使用PHPExcel 1.6.7,根據建議我使用我的projet配置了PHPExcel庫,但是當我嘗試將數據導出到excel文件時,出現以下錯誤。PHPExcel中的setLastModifiedBy()的致命錯誤

Fatal error: Call to a member function setLastModifiedBy() on a non-object in C:\wamp\www\xxx\site\dump.php on line 28 

我followinf代碼dump.php

/** Error reporting */ 
error_reporting(E_ALL); 

/** PHPExcel */ 
require_once ("Classes/PHPExcel.php"); 


/** PHPExcel_IOFactory */ 
require_once ("Classes/PHPExcel/IOFactory.php"); 

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

// Set properties 
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") 
->setLastModifiedBy("Maarten Balliauw") 
->setTitle("Office 2007 XLSX Test Document") 
    ->setSubject("Office 2007 XLSX Test Document") 
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") 
->setKeywords("office 2007 openxml php") 
->setCategory("Test result file"); 

// Add some data 
$objPHPExcel->setActiveSheetIndex(0) 
     ->setCellValue('A1', 'Hello') 
     ->setCellValue('B1', 'world!') 
     ->setCellValue('C1', 'Hello') 
     ->setCellValue('D1', 'world!'); 

// Miscellaneous glyphs, UTF-8 
$objPHPExcel->setActiveSheetIndex(0) 
     ->setCellValue('A2', 'Miscellaneous glyphs') 
     ->setCellValue('B2', 'test text'); 

// Rename sheet 
$objPHPExcel->getActiveSheet()->setTitle('Simple'); 


// 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="01simple.xls"'); 
header('Cache-Control: max-age=0'); 

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

我檢查了所有的配置設置&找到所有必需的文件,包括爲這個,但是仍然出現此錯誤。如果我在這個過程中做了任何錯誤,請給我建議任何建議。

謝謝。

+0

你可能會考慮更新你正在運行的PHPExcel的版本--1.6.7現在已經超過3年了:最新版本是1.7.8,並且在那個時候有很多錯誤修正,並且很多變化,包括流暢的界面元素如文檔屬性 –

回答