PHPWord/samples/Sample_34_SDT.php

35 lines
1019 B
PHP
Raw Normal View History

<?php
2022-09-16 11:45:45 +02:00
include_once 'Sample_Header.php';
// New Word document
2015-01-01 20:41:42 +04:00
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
2016-06-04 20:06:37 +04:00
// New section
$section = $phpWord->addSection();
2014-06-28 11:47:04 +07:00
$textrun = $section->addTextRun();
2016-06-04 20:06:37 +04:00
$textrun->addText('Combobox: ');
2022-09-16 11:45:45 +02:00
$textrun->addSDT('comboBox')->setListItems(['1' => 'Choice 1', '2' => 'Choice 2']);
2014-06-28 11:47:04 +07:00
$textrun = $section->addTextRun();
2016-06-04 20:06:37 +04:00
$textrun->addText('Date: ');
2014-06-28 11:47:04 +07:00
$textrun->addSDT('date');
2017-03-08 13:08:33 +01:00
$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');
2014-06-28 11:47:04 +07:00
$textrun = $section->addTextRun();
2016-06-04 20:06:37 +04:00
$textrun->addText('Drop down list: ');
2022-09-16 11:45:45 +02:00
$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';
}