Yii 1.1: yiireport

Extension for export Spreadsheet and PDF from scratch or templates using PHPExcel and PHPReport Libraries.
28 followers

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

  1. Download and install YiiExcel extension.
  2. Download a PDF library, like mPDF and copy to protected/vendors directory
  3. Download and Unzip YiiReport, then copy yiireport directory to protected/extensions.
  4. 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.
  5. 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' for xls, 'excel2007' for xlsx, 'html' and 'pdf'.
  • PHPReport class have lites modifications over the original PHPReport class by Vernes Å iljegović.

Example

  1. Copy students.xls file from examples/templates to views/reports
  2. Copy actionExcel() method from SiteController.php example file to your own SiteController

Resources

Total 13 comments

#18330 report it
William Vaquerano at 2014/10/16 12:33pm
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.

#18325 report it
Yeye at 2014/10/15 11:26am
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. :)

#18301 report it
William Vaquerano at 2014/10/13 07:14pm
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
                )
            )
        );
#17875 report it
vijay p s at 2014/08/05 12:23am
Doubt!

Were We use this "usage" part, in the admin page or in the controller page?

#15634 report it
C.S.Putera at 2013/12/02 06:01am
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);
...
#15633 report it
C.S.Putera at 2013/12/02 04:58am
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.

#15032 report it
Yeye at 2013/09/30 11:17am
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.

#15028 report it
fouss at 2013/09/30 06:10am
rendering pdf file

Why not give a clear instructions bout rendering pdf ?

#14955 report it
Johanovski at 2013/09/24 06:26am
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!

#14538 report it
Yeye at 2013/08/21 01:29pm
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');
#14527 report it
had at 2013/08/20 10:00pm
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 ?

#14252 report it
cioxideru at 2013/07/30 05:10am
sheets support

please add ability to generate reports with multi sheets

#13477 report it
bmac at 2013/05/30 05:05pm
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.

Leave a comment

Please to leave your comment.

Create extension