No Description

Sample_27_Field.php 1.1KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. include_once 'Sample_Header.php';
  3. // New Word document
  4. echo date('H:i:s'), ' Create new PhpWord object', EOL;
  5. $phpWord = new \PhpOffice\PhpWord\PhpWord();
  6. // Begin code
  7. $section = $phpWord->addSection();
  8. // Add Field elements
  9. // See Element/Field.php for all options
  10. $section->addText(htmlspecialchars('Date field:'));
  11. $section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
  12. $section->addText(htmlspecialchars('Page field:'));
  13. $section->addField('PAGE', array('format' => 'ArabicDash'));
  14. $section->addText(htmlspecialchars('Number of pages field:'));
  15. $section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
  16. $textrun = $section->addTextRun(array('align' => 'center'));
  17. $textrun->addText(htmlspecialchars('This is the date of lunar calendar '));
  18. $textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
  19. $textrun->addText(htmlspecialchars(' written in a textrun.'));
  20. // Save file
  21. echo write($phpWord, basename(__FILE__, '.php'), $writers);
  22. if (!CLI) {
  23. include_once 'Sample_Footer.php';
  24. }