ClaCS, on 10 June 2011 - 09:08 AM, said:
Hi! Yes, I did
I used the phpexcel extension and a $_SESSION var to pass the filtered data
controller.php
model.php modify the search function
view.php
copy the file attached into your extensions folder
I hope to help you
if somebody find a best way to do this ... plz share it
regards!
phpexcel.zip
I used the phpexcel extension and a $_SESSION var to pass the filtered data
controller.php
public function actionExcel() {
$d = $_SESSION['Lectivo-excel'];
$data = array();
$data[]=array_keys($d->data[0]->attributes);//headers: cols name
foreach ($d->data as $item) {
$data[] = $item->attributes;
}
Yii::import('application.extensions.phpexcel.JPhpExcel');
$xls = new JPhpExcel('UTF-8', false, 'test');
$xls->addArray($data);
$xls->generateXML('filename'); //export into a .xls file
}
model.php modify the search function
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id_lectivo',$this->id_lectivo);
$criteria->compare('nombre',$this->nombre,true);
$criteria->compare('abreviatura',$this->abreviatura,true);
$criteria->compare('fec_inicio',$this->fec_inicio,true);
$criteria->compare('fec_fin',$this->fec_fin,true);
$criteria->compare('estado',$this->estado);
$data = new CActiveDataProvider(get_class($this), array(
'pagination'=>array('pageSize'=> Yii::app()->user->getState('pageSize',
Yii::app()->params['defaultPageSize']),),
'criteria'=>$criteria,
));
$_SESSION['Lectivo-excel']=$data; // get all data and filtered data :)
return $data;
}
view.php
<div id='menub'><?php $this->widget('zii.widgets.CMenu', array(
'encodeLabel'=>false,
'htmlOptions'=>array(
'class'=>'actions'),
'items'=>array(
...,
array(
'label'=>'<img align="absmiddle" alt = "'.Yii::t('internationalization','Exportar'). '" src = "'.bUrl().'/images/icons/page_excel.png" />'. ' ' . Yii::t('internationalization', 'Exportar'),
'url'=>array('Lectivo/Excel'),
),
... ,
),
)
));
?></div></div>
copy the file attached into your extensions folder
I hope to help you
if somebody find a best way to do this ... plz share it
regards!
Hi ClaCS,
Thank you for your solutions. This is very nice code and save my time. but I've an another issues.
1. how to report the relationship data. e.g. I keep users.id in my project tbl as user_id. Now, the report exported the project.user_id only. I want to export the username at report. How can I?
2. and some of the tbl's field keep the data by csv or jason code. For those fields are relationship with other tables. how could I export the really data from relative tbl at report.
Regards
Thu Ra

Help











