Sample 34 SDT

04:52:21 Create new PhpWord object
04:52:21 Write to Word2007 format
04:52:21 Write to ODText format
04:52:21 Write to RTF format
04:52:21 Write to HTML format
04:52:21 Write to PDF format
04:52:21 Done writing file(s)
04:52:21 Peak memory usage: 8 MB

 

Results: docx odt rtf html pdf


<?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($phpWordbasename(__FILE__'.php'), $writers);
if (!
CLI) {
    include_once 
'Sample_Footer.php';
}