Exporting to ms word

Hi guys,

I am exporting my page to ms word using

$div = $this->renderPartial('print', array('model' => $model, 'user' => $user), true);

header("Pragma: no-cache"); // required

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: private", false); // required for certain browsers

header("Content-type: application/vnd.ms-word");

header("Content-Disposition: attachment; filename=\"profile_" . $model->faculty_id_no . ".doc");

header("Content-Transfer-Encoding: binary");



echo $div;

which will render something like:

<table class='detail-view'>


        <th colspan='3' class='header'>

            Basic Information</th>


    <tr class='odd'  >

        <th >

            Id No


        <td >



        <td rowspan=7" >

            <img style="width: 200px; height: 200px;" src="/albuja/assets/339833f3/2011-0001.jpg" alt="2011-0001.jpg" />        </td>


    <tr class='even'>

        <th >



.............. and so on

If I just render it to the screen, it displays the image. When allowing the user to export it file to MS Word, the image is not included in the exported file :(

Anyone who got an idea on how to solve this?

Use the full url including your domain


It works in the page rendered because the path is relative to your domain

I should have checked this topic earlier…it really is the solution :)

I used $_SERVER[‘HTTP_HOST’] to determine the address being used

$div .= CHtml::image('http://'.$_SERVER['HTTP_HOST'].'/'.Yii::app()->getAssetManager()->publish($img, true, 0, true), $alt . '.jpg', $options);

Thanks gustavo, the picture is now showing when exported to msword :)

The only problem left is when being exported to PDF. I use DOMPDF. Do you have any idea how to fix this? Or is there a better HTML->PDF exporter than Dompdf?


I wouldn’t know because I haven’t worked much with PDF’s

But you are right, the converter system should import the images correctly to the pdf file.

Test with another one and see what you get.

I solved it…whew!

Could you say how ?

So other can benefit from it


Oh yes, I just got overwhelmed I forgot to say how :D

Dompdf does not see the image if I give it a URL, and with some experiments, it worked using the absolute path of image. But that will make my export to WORD not work again, so I just added a parameter to check whether I am printing an HTML,word,or PDF.

Here’s the part of my code which I changed

//fullpath is needed in order for export to PDF to work

            !$fullPath ? $div .= CHtml::image('http://' . $_SERVER['HTTP_HOST'] . '/' . Yii::app()->getAssetManager()->publish($img, true, 0, true), $alt . '.jpg', $options) :

                            $div .= CHtml::image($_SERVER['DOCUMENT_ROOT'] . '/' . Yii::app()->getAssetManager()->publish($img, true, 0, true), $alt . '.jpg', $options);

where $fullPath is my parameter to check if I needed the absolute path, which means I am printing PDF.

I Also want to export the pdf of the grid view list.can some one pls help me

use this extension

its simpel to use http://www.yiiframew…ion/eexcelview/

in this page I posted a new version with a couple things corrected


HI. I used this code. But page margin of file .doc not setup. Can anyone tell me how to setup margins and page size of file .doc?