Yii Framework Forum: Export To Excel Consultation With Parameters - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Export To Excel Consultation With Parameters Rate Topic: -----

#1 User is offline   JennyGamez0106 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 15-April 14

Posted 15 April 2014 - 03:19 PM

Hi I am trying to export a query to an excel file but I have not succeeded in this forum mime I found an example but I do not export anything just shows me what I leave the code acontinuacion

public function actionReporte() {
        $bus = true;

        if (!isset($_POST['fechaini']) || $_POST['fechaini'] == "") {
            if (!isset($_POST['fechafin']) || $_POST['fechafin'] == "") {
                $bus = false;
            }
        }

        if ($bus == true) {
            header('Content-type: text/csv');
            header('Content-Disposition: attachment; filename="report-customers-' . date('YmdHi') . '.csv"');

            $criteria = new CDbCriteria();
            $criteria->addBetweenCondition("Fecha_cita", $_POST['fechaini'], $_POST['fechafin']);
            $criteria->addCondition('personal="no"');
            $citas = Calendario::model()->findAll($criteria);
            Yii::app()->user->setState('exportModel',$citas);

            if (Yii::app()->user->getState('exportModel'))
                $citas = Yii::app()->user->getState('exportModel');

            $dataProvider = new CArrayDataProvider($citas);
            
            foreach ($dataProvider->getData() as $data) {
                echo "$data->Fecha_cita, $data->Hora_inicial, 
                $data->Servicio, $data->Nombre_completo \r\n";
            }

            exit;
        } else {
            throw new CHttpException(500, 'Faltan Parametros');
        }
    }


and view

<div id="resultado">
    <?php echo TbHtml::textField('fechaini', '', array("style" => "margin-bottom: 5px;")) . ' Hasta: ' . TbHtml::textField('fechafin', '', array("style" => "margin-bottom: 5px;")); ?>
    <?php
    echo TbHtml::submitButton(TbHtml::icon(TbHtml::ICON_DOWNLOAD_ALT) . 'Generar', array('color' => TbHtml::BUTTON_COLOR_WARNING,
        "ajax" => array(
            "type" => "post",
            "url" => Yii::app()->createUrl("admin/calendario/reporte"),
            "data" => array(
                "fechaini" => "js:$('#fechaini').val()",
                "fechafin" => "js:$('#fechafin').val()"
            ),
            "success" => "function(data){
                $('#reporte').html(data);
            }",
            "error" => "function(data){
                $('#reporte').html('');
            }",
        )
    ))
    ?>
    <?php echo CHtml::link('Excel', array('Excel'), array('class' => 'bt-excel')); ?>
    <div id="reporte">
        <?php $this->renderPartial('reporte'); ?>
    </div>
</div>


thanks for the help you can give me
0

#2 User is offline   JennyGamez0106 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 15-April 14

Posted 16 April 2014 - 11:25 AM

hi,


I could already export the excel file, but I need to pass url values ​​stuff to send to the query that generates the excel file I do not know how I can pass it values ​​URL (get)
0

#3 User is offline   jkofsky 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 527
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 16 April 2014 - 08:21 PM

Not sure why you need a url to generate an Excel file. Also where are you getting the url? But you could try
      "ajax" = > array(
            ...
            "data" => array(
                "fechaini" => "js:$('#fechaini').val()",
                "fechafin" => "js:$('#fechafin').val()",
                "url" => 'whatever/something.html"
            ),
            ...
      )

Do, or do not. There is no 'try.' Jedi Master Yoda
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users