PHPExcel中setLastModifiedBy()的致命错误

时间:2012-11-05 09:57:26

标签: php phpexcel

在我目前的项目中,我使用了PHPExcel 1.6.7,根据建议我使用我的projet配置PHPExcel库,但是当我尝试将数据导出到excel文件时,我得到了以下错误。

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

我在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;

我检查了所有配置设置&找到包含所有必需的文件,但仍然会收到此错误。如果我在这个过程中做错了,请建议我任何建议。

谢谢。

1 个答案:

答案 0 :(得分:3)

看看这里:

http://www.auditbureau.org.au/a/Documentation/API/PHPExcel/PHPExcel_DocumentProperties.html#methodsetLastModifiedBy

setLastModfiedBy()返回void。因此,您无法链接调用您正在制作的所有 - > setXX调用。你应该分别调用getProperties()的返回值。