我正在使用 phalcon php 框架,我正在尝试创建简单的 xsl 文件,但是当我调用我的控制器时,我得到了空的 excel 表。谁能告诉我我的代码有什么问题。这是我的方法:
public function createExcelAction () {
$loader = new \Phalcon\Loader();
$loader->registerClasses(array(
"PHPExcel" => "C:/wamp/www/phalcon1/Classes/PHPExcel.php",
"PHPExcel_Writer_Excel2007" => "C:/wamp/www/phalcon1/Classes/PHPExcel/Writer/PHPExcel_Writer_Excel2007.php"
));
$loader->register();
$excel = new PHPExcel();
//$excel = new PHPExcel();
//activate worksheet number 1
$excel->setActiveSheetIndex(0);
//name the worksheet
$excel->getActiveSheet()->setTitle('test worksheet');
//set cell A1 content with some text
$excel->getActiveSheet()->setCellValue('A1', 'Rezultati pretrage');
$excel->getActiveSheet()->setCellValue('A2', "Ime");
$excel->getActiveSheet()->setCellValue('C2', "Prezime");
$excel->getActiveSheet()->setCellValue('F2', "Adresa stanovanja");
$br = rand(0, 1000000);
$naziv = "Pobjeda-Rudet izvjestaj-" . $br . ".xls";
//$filename='pobjeda_rudet.xlsx'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime typež
header('Content-Disposition: attachment;filename="' . $naziv . '"');
// header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0'); //no cache
$objWriter = new PHPExcel_Writer_Excel2007($excel);
$objWriter->save(str_replace('.php', '.xls', __FILE__));
}