0
我想让我的symfony2应用程序导出到Excel。我可以把它写入磁盘没有问题,但是当我尝试通过symfony响应导出时,我得到了很多gobbledygook。任何人都可以提出建议:我如何获得symfony2导出到Excel
function exportAction()
{
$fname = "/tmp/test_xls.xlsx";
$php_excel = new \PHPExcel();//
$php_excel->setActiveSheetIndex(0);
$sheet = $php_excel->getActiveSheet();
$sheet->setCellValue('A1', 'Hello');
$sheet->setCellValue('B2', 'world!');
$writer = new \PHPExcel_Writer_Excel2007($php_excel);
$writer->save($fname);
$content = file_get_contents($fname);
return new Response(
$content,
200,
array(
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8',
'Content-Disposition' => 'attachment; filename="test_957export.xlsx"',
'Content-Transfer-Encoding' => 'application/octet-stream',
'Content-Length' => strlen($content)
)
);
}
你试过'LoveBundle'吗?我相信它提供了一个'give_love'设置。 – leek 2012-02-14 18:26:31