このバンドルをインストールします:
https://github.com/liuggio/ExcelBundle
私の Symfony2 では、基本的に以下を追加します。
[PHPExcel]
git=http://github.com/PHPOffice/PHPExcel.git
target=/phpexcel
version=origin/master
[n3bStreamresponse]
git=git://github.com/liuggio/Symfony2-StreamResponse.git
target=n3b/src/n3b/Bundle/Util/HttpFoundation/StreamResponse
[LiuggioExcelBundle]
git=https://github.com/liuggio/ExcelBundle.git
target=/bundles/Liuggio/ExcelBundle
deps に、Autoload.php と AppKernel.php を更新し、このアクションを 1 つのコントローラーで使用します。
$excelService = $this->get('xls.service_xls2007');
$excelService->excelObj->getProperties()
->setTitle("Reunión comercial")
->setDescription("Reunión Comercial - Generación automática desde la aplicación de RRHH.");
$excelService->excelObj->getActiveSheet()->setTitle('Reunión Comercial');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$excelService->excelObj->setActiveSheetIndex(0);
//create the response
$response = $excelService->getResponse();
$response->headers->set('Content-Type', 'text/vnd.ms-excel; charset=utf-8');
$response->headers->set('Content-Disposition', 'attachment;filename=reuComercial-'.date("Y_m_d_His").'.xls');
// If you are using a https connection, you have to set those two headers for compatibility with IE <9
/*$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
*/
$excelService->setActiveSheetIndex(0)
->setCellValue('A1', 'Lead')
->setCellValue('B1', 'Peticion')
->setCellValue('C1', 'Estado Candidato')
->setCellValue('D1', 'Nombre Candidato')
->setCellValue('E1', 'Apellido Candidato')
->setCellValue('F1', 'Cliente')
->setCellValue('G1', 'Descripcion');
$em = $this->getDoctrine()->getEntityManager();
$data = $em->getRepository('OportunidadBundle:Oportunidad')->reunionComercial();
$aux = 2;
foreach ($data as $row)
{
$excelService->setActiveSheetIndex(0)
->setCellValue('A'.$aux, $row->Lead)
->setCellValue('B'.$aux, $row->Peticion)
->setCellValue('C'.$aux, $row->Estado_Candidato)
->setCellValue('D'.$aux, $row->Nombre_Candidato)
->setCellValue('E'.$aux, $row->Apellido_Candidato)
->setCellValue('F'.$aux, $row->Cliente)
->setCellValue('G'.$aux, $row->Descripcion);
$aux++;
};
$excelService->getStreamWriter()->write( $filename );
return $response;
そして、私はこのエラーを受け取ります:(
Runtime Notice: Declaration of PHPExcel_Style_Color::bindParent() should be compatible with that of PHPExcel_Style_Supervisor::bindParent() in C:\Program Files\EasyPHP-5.3.8.1\www\www\www\intranet\vendor\phpexcel\Classes\PHPExcel\Style\Color.php line 36
PHPにはまだ私を逃れるものがたくさんあるので、これが何を意味するのかわかりません:/