YiiReport ¶
Yii extension for export Spreadsheet and PDF from scratch or templates using PHPExcel and PHPReport Libraries.
This library needs YiiExcel extension for work.
Requirements ¶
- Yii 1.1 or above.
- PHPExcel 1.7.8
- YiiExcel extension.
- Optional: TcPDF, DomPDF or mPDF library.
Installation ¶
- Download and install YiiExcel extension.
- Download a PDF library, like mPDF and copy to
protected/vendors
directory - Download and Unzip
YiiReport
, then copyyiireport
directory toprotected/extensions
. - Edit
yiireport.php
config file if you need. Here you set the PDF library to use, the path for that library and the template path. - Add YiiReport to imports:
...
'import'=>array(
...
'application.vendors.phpexcel.PHPExcel',
'ext.yiireport.*',
...
),
Usage ¶
$r = new YiiReport(array('template'=> someTemplate.xls));
$r->load(array(...));
echo $r->render(format, name);
Notes ¶
- Inside
yiireport.php
config file, you must use alias path format. - The output format options are:
'excel5'
forxls
,'excel2007'
forxlsx
,'html'
and'pdf'
. - PHPReport class have lites modifications over the original PHPReport class by Vernes Šiljegović.
Example ¶
- Copy
students.xls
file fromexamples/templates
toviews/reports
- Copy
actionExcel()
method fromSiteController.php
example file to your ownSiteController
Grid Lines
Love the extension. Is there anyway to keep the grid lines from showing when printing to PDF?
EDIT: I figured it out. I unchecked gridlines from the view panel.
sheets support
please add ability to generate reports with multi sheets
PDF Report
Its nice extention but i had trouble creating pdf report, Excel report works like charm, but how to create pdf report
anyone can help please ?
RE PDF Report
You must use a pdf library, like mPDF, download and paste on «vendors» directory.
On yiireport.php you must set a config for the PDF library to use:
return array( 'pdfRenderer' => 'mpdf',//or 'dompdf', 'tcpdf' 'pdfRendererPath' => 'application.vendors.mpdf', 'templatePath' => 'application.views.reports' );
Then you can:
echo $r->render('pdf', 'name');
YiiReport suddenly stopped working
Hi there! First of all, congratulations for the work you've done: it's awesome! I'm having a problem generating Excels: I've been able to do it during months without any problem, but now it has stopped working. In my localhost installation it works fine, but in the online version, when I try to generate an Excel, it shows a kind of "page not found" error... However, if I comment the "render" function call, it doesn't show this error (of course it doesn't either generate the file). It's weird because I haven't changed anything, so I don't know what can be happening... Any idea? The code I'm using is quite simple:
$data[] = array('dni'=>$dninie, 'nom'=>$result[$i]['artnomcog'], 'telefon'=>$telefon, 'email'=>$result[$i]['artmail'], 'adreca'=>$adreca, 'datanaixement'=>$datanaix, 'numss'=>$result[$i]['artnumss'], 'numcc'=>$result[$i]['artnumcc'], 'grups'=>$grups, 'managers'=>$managers); $r = new YiiReport(array('template'=> $template)); $r->load(array( array( 'id' => 'ong', 'data' => array( 'name' => $nom ) ), array( 'id'=>$id, 'repeat'=>true, 'data'=>$data, 'minRows'=>2 ) ) ); echo $r->render('excel2007', $filename);
Thanks in advance!
rendering pdf file
Why not give a clear instructions bout rendering pdf ?
Test and PDF
@Johanovski Sorry, I try your code with test arrays and works for me. :/
@fouss the PDF render work it's made by external libs, TCPDF or mPDF. The processed template is exported to html and that html is taken by the PDF lib, then the lib do the job.
Failed To Load PDF
Hello. I have used this extension for a while and this is awesome. But I'm having some difficulties. I have created a template (.xlsx), consisting of 130 rows. I haven't tried to pass the data, just wanna see the outcome of the template. But when I try to load it, it said "Faild to Load PDF" ( using Chrome ). I can't load it using firefox neither. But, if I delete row no 1 - 35 or 36 - 50, then it runs well. Is there any limitations of how many rows can be rendered ? Please help, thank you.
Failed To Load PDF
Found the solution. I set the max memory limit and execution time before rendering the pdf.
... ini_set('memory_limit', '-1'); set_time_limit(180); ...
Doubt!
Were We use this "usage" part, in the admin page or in the controller page?
Insert image into template
Hi,
Great Extension, i've beenusing it a lot. Is there a way to insert an image into excel if I´m building the reports using templates? Here is an example of who i´m doing it.
public function actionExcelIndice02($tipo,$fecha_i,$fecha_f){ $this->setPageTitle("Ind-desempeno"); //Some data $dataProvider=Reporte::promedioIndiceDesempennioXUnidad($fecha_i,$fecha_f); $r = new YiiReport(array('template'=> 'indiceGerencial02.xlsx')); $r->load(array( array( 'id' => 'ong', 'data' => array( 'name' => 'REPORTE DE INDICE DEL DESEMPENO', 'usuario'=>Yii::t('app',Yii::app()->user->name), 'fecha_hoy'=>Yii::app()->dateFormatter->format('dd/MM/yyyy h:mm a', time()), 'titulo'=>$this->getPageTitle(), ) ), array( 'id'=>'ind', 'repeat'=>true, 'data'=>$dataProvider, 'minRows'=>2 ) ) );
La imagen
Me permitiré contestar en español. :P (Sorry, today I don't want think on english)
Verás William, la verdad que insertar una imagen desde la plantilla no es posible, o mejor dicho, todavía no he encontrado como. Pero es posible insertar imágenes antes de renderizar el reporte.
Hay que hacer un pequeño hack para devolver el objeto de PHPExcel.
En el archivo PHPReport.php agregas:
public function getPHPExcel(){ return $this->objPHPExcel; }
Luego, después de la llamada a load() del reporte:
$phpExcel = $r->getPHPExcel(); $sheet = $phpExcel->getActiveSheet(); $objDrawing = new PHPExcel_Worksheet_Drawing(); $objDrawing->setName('Logo'); $objDrawing->setDescription('Logo'); $objDrawing->setPath('ruta/a/logo.jpg'); $objDrawing->setHeight(70);//Cambias 70 por los pixeles de altura de tu logo $objDrawing->setCoordinates('A1'); $objDrawing->setResizeProportional(false); $phpExcel->setActiveSheetIndex(0); $objDrawing->setWorksheet($phpExcel->getActiveSheet());
Es un poco tosco, pero solucionas el problema. :)
RE: La imagen
Muchas gracias Yeye,
Funcionó perfecto al generar el archivo en excel, aunque al generar el pdf muestra solo un cuadro con una X roja, estoy usando la libreria mpdf. Tambien encontré una solución alterna que es insertar la imagen en la plantilla de excel y cambiar las propiedades de la imagen a "Mover y cambiar con tamaño de celda". Esto tampoco es muy eficiente ya que aumenta el tamaño de cada plantilla pero funciona al exportar a pdf tambien.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.