我安装了这个包:
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并在一个控制器中使用此Action:
$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中有很多东西仍然让我感到厌烦:/
答案 0 :(得分:1)
拉动最新的开发分支代码而不是标记版本是一个问题:开发分支代码永远不能保证处于可以简单运行的状态。
我修改了bindParent()方法的签名,以便不再发生此特定通知