ms-doc file in yii

Hi all,

Is there a way for me to create a doc file in yii? Basically i have an invoice which has to be converted to a doc file and then attached to a mail.

Thanks

You could use some third party library like: http://phpword.codeplex.com/

This isn’t really a Yii related question, however, there are a number of solutions to this in PHP. Most are complex or expensive, see this stackoverflow thread:

http://stackoverflow.com/questions/124959/create-word-document-using-php-in-linux

If you can get away with some other format, like PDF you’re going to find this easier.

You could use this, however, it’s only going to generate docx XML word files compatible with new versions of Word.

thanks for the reply Luke… I ll c what i can do

Hello, I am using phpword extension and if I try to do a “mail merge” using the sample Template.php in Windows is everithng ok, the problem is that I use Ubuntu and the same code has different result ( :angry: error :angry: ).

If i put the same code directly in a view run fine but I have to access the db to read the data and do the mail merge.

This is the code in my controller

public function actionPrint()


{


	Yii::import('ext.phpword.PHPWord');


	$PHPWord = new PHPWord();


	$document = $PHPWord->loadTemplate('Template.docx');


	$document->setValue('Value1', 'Sun');


	$document->setValue('Value2', 'Mercury');


	$document->setValue('Value3', 'Venus');


	$document->setValue('Value4', 'Earth');


	$document->setValue('Value5', 'Mars');


	$document->setValue('Value6', 'Jupiter');


	$document->setValue('Value7', 'Saturn');


	$document->setValue('Value8', 'Uranus');


	$document->setValue('Value9', 'Neptun');


	$document->setValue('Value10', 'Pluto');


	$document->setValue('weekday', date('l'));


	$document->setValue('time', date('H:i'));


	$document->save('Solarsystem.docx');


}

I’m invoking the controller with ajax (jquery)

$.post('index.php?r=mycontroller/print',


{ 'Dat_Data': '20-06-2012' },


	function(data) {


}

Someone understand the problem below? It seems a problem of the autoloader but in windows it function and I’ve not very clean the yii architecture so please help me :rolleyes:

<h1>PHP Error [2]</h1>

<p>include(PHPWord_DocumentProperties.php): failed to open stream: No such file or directory (/media/DATI/sviluppi/gestur/web/yii/framework/YiiBase.php:418)</p>

<pre>#0 /media/DATI/sviluppi/gestur/web/yii/framework/YiiBase.php(418): CWebApplication->handleError()

#1 /media/DATI/sviluppi/gestur/web/yii/framework/YiiBase.php(418): autoload()

#2 unknown(0): autoload()

#3 /media/DATI/sviluppi/gestur/web/gestur/protected/extensions/phpword/PHPWord.php(78): spl_autoload_call()

#4 /media/DATI/sviluppi/gestur/web/gestur/protected/controllers/StampaattestazioneregolamentataController.php(107): PHPWord->__construct()

#5 /media/DATI/sviluppi/gestur/web/yii/framework/web/actions/CInlineAction.php(50): StampaattestazioneregolamentataController->actionPrint()

#6 /media/DATI/sviluppi/gestur/web/yii/framework/web/CController.php(309): CInlineAction->runWithParams()

#7 /media/DATI/sviluppi/gestur/web/yii/framework/web/filters/CFilterChain.php(134): StampaattestazioneregolamentataController->runAction()

#8 /media/DATI/sviluppi/gestur/web/yii/framework/web/filters/CFilter.php(41): CFilterChain->run()

#9 /media/DATI/sviluppi/gestur/web/yii/framework/web/CController.php(1146): CAccessControlFilter->filter()

#10 /media/DATI/sviluppi/gestur/web/yii/framework/web/filters/CInlineFilter.php(59): StampaattestazioneregolamentataController->filterAccessControl()

#11 /media/DATI/sviluppi/gestur/web/yii/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter()

#12 /media/DATI/sviluppi/gestur/web/yii/framework/web/CController.php(292): CFilterChain->run()

#13 /media/DATI/sviluppi/gestur/web/yii/framework/web/CController.php(266): StampaattestazioneregolamentataController->runActionWithFilters()

#14 /media/DATI/sviluppi/gestur/web/yii/framework/web/CWebApplication.php(276): StampaattestazioneregolamentataController->run()

#15 /media/DATI/sviluppi/gestur/web/yii/framework/web/CWebApplication.php(135): CWebApplication->runController()

#16 /media/DATI/sviluppi/gestur/web/yii/framework/base/CApplication.php(162): CWebApplication->processRequest()

#17 /media/DATI/sviluppi/gestur/web/gestur/index.php(13): CWebApplication->run()

</pre>

ok ok i find the solution in the post below of the user slyder wich has same problem with eexcelview

THANKS VERY MUCH TO SLYDER!!!

[indent]Posted 09 April 2012 - 05:21 PM

I had some error during PHPExcel import:

Yii::import(‘application.extensions.phpexcel.Classes.PHPExcel’, true);

and as result had next message (because autoload was reset to PHPExcel autoload function):

Fatal error: Class ‘CExceptionEvent’ not found in C:\Projects\.libs\yii-framework-1_1_10\base\CApplication.php on line 707

And next fix will help to show Yii exception page if some error occurred during PHPExcel importing:

[b]spl_autoload_unregister(array(‘YiiBase’,‘autoload’));

try {

    Yii::import('application.extensions.phpexcel.Classes.PHPExcel', true);

}

catch (Exception $e) {

    spl_autoload_register(array('YiiBase','autoload'));


    throw  &#036;e;

}

$this->objPHPExcel = new PHPExcel();

spl_autoload_register(array(‘YiiBase’,‘autoload’));[/b]

Hope this help to someone else.[/indent]