Sample 34 SDT

20:08:35 Create new PhpWord object
20:08:35 Write to Word2007 format
20:08:35 Write to ODText format
20:08:35 Write to RTF format
20:08:35 Write to HTML format
20:08:35 Write to PDF format ... NOT DONE!
20:08:35 Write to EPub3 format
20:08:35 Done writing file(s)
20:08:35 Peak memory usage: 2 MB

 

Results: docx odt rtf html epub


<?php


include_once 'Sample_Header.php';

// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new PhpOffice\PhpWord\PhpWord();

// New section
$section = $phpWord->addSection();

$textrun = $section->addTextRun();
$textrun->addText('Combobox: ');
$textrun->addSDT('comboBox')->setListItems(['1' => 'Choice 1', '2' => 'Choice 2']);

$textrun = $section->addTextRun();
$textrun->addText('Date: ');
$textrun->addSDT('date');
$textrun->addTextBreak(1);
$textrun->addText('Date with pre set value: ');
$textrun->addSDT('date')->setValue('03/30/2017');
$textrun->addTextBreak(1);
$textrun->addText('Date with pre set value: ');
$textrun->addSDT('date')->setValue('30.03.2017');

$textrun = $section->addTextRun();
$textrun->addText('Drop down list: ');
$textrun->addSDT('dropDownList')->setListItems(['1' => 'Choice 1', '2' => 'Choice 2'])->setValue('Choice 1');

// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!
CLI) {
    include_once 
'Sample_Footer.php';
}