PHPWord/samples/Sample_27_Field.php

32 lines
1.1 KiB
PHP
Raw Normal View History

2014-05-28 17:59:44 +02:00
<?php
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;
2014-05-28 17:59:44 +02:00
$phpWord = new \PhpOffice\PhpWord\PhpWord();
2016-06-04 20:06:37 +04:00
// New section
2014-05-28 17:59:44 +02:00
$section = $phpWord->addSection();
// Add Field elements
// See Element/Field.php for all options
2016-06-04 20:06:37 +04:00
$section->addText('Date field:');
2015-01-01 20:41:42 +04:00
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
2016-06-04 20:06:37 +04:00
$section->addText('Page field:');
2015-01-01 20:41:42 +04:00
$section->addField('PAGE', array('format' => 'ArabicDash'));
2016-06-04 20:06:37 +04:00
$section->addText('Number of pages field:');
2015-01-01 20:41:42 +04:00
$section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
2014-05-28 17:59:44 +02:00
2015-10-10 19:22:19 +04:00
$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
2016-06-04 20:06:37 +04:00
$textrun->addText('This is the date of lunar calendar ');
2015-01-01 20:41:42 +04:00
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
2016-06-04 20:06:37 +04:00
$textrun->addText(' written in a textrun.');
2014-05-28 17:59:44 +02:00
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}