How to generate word document in yii

Yii

Posted on 11 Feb 15 by Vickey
  1132



Create a action in your controller

public function actionUserDetails() {


   $title = "My Profile";
   $view= $this->renderPartial('profile', array('title'=>$title), true);
   header("Pragma: no-cache");
   header("Expires: 0");
   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
   header("Cache-Control: private", false);
   header("Content-type: application/vnd.ms-word");
   header("Content-Disposition: attachment; filename=\"test.doc");
  header("Content-Transfer-Encoding: binary");
  ob_clean();
  flush();
  echo $view;
  Yii::app()->end();


}

create profile.php in your view directory and add your data

Now create link for create word file on your view file

echo CHtml::link('Download Report', array('User/UserDetails'));

 

You can download source code here


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com