Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Basic Word integration using docx template files and PHPWord
#21

[eluser]heru[/eluser]
hello there ! it's been a while huh, but i came with the solution B)
let me explain this step by step :
1. download PHPWord library from this site.
2. put it in application/libraries
3. in application folder, create "docs" folder (for generated documents) and "temp" folders inside "docs" folder that you created before.
4. put "template.docx" in "temp" folder.
5. now creat the controller like this :
Code:
public function template(){
  $this->load->library('PHPWord');
  $document = $this->phpword->loadTemplate('application/docs/temp/Template.docx');
  $document->setValue('myReplacedValue','Test');
  $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('application/docs/Solarsystem.docx');
}
6. then, call it from browser, and check "docs" folder. voilaaa ! there is "Solarsystem.docx" B)
or simply, download my attachment.
#22

[eluser]Zeff[/eluser]
Hi all,

I tried this code/library and the docx files (with gegeneric names) are correctly created in my temp folder.
What if I do not want to save the file, but directly output it to the browser for download?
(save_document() does not work...)

I experimented with PHPWord in the past and I used this code to output my $this->word object:
Code:
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
$objWriter = PHPWord_IOFactory::createWriter($this->word, 'Word2007');
$objWriter->save('php://output');

Any suggestions to do this right from PhpOffice?

Many thanks!

Zeff




Theme © iAndrew 2016 - Forum software by © MyBB