Nenhuma descrição

Sample_07_TemplateCloneRow.php 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. include_once 'Sample_Header.php';
  3. // Template processor instance creation
  4. echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
  5. $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
  6. // Variables on different parts of document
  7. $templateProcessor->setValue('weekday', htmlspecialchars(date('l'))); // On section/content
  8. $templateProcessor->setValue('time', htmlspecialchars(date('H:i'))); // On footer
  9. $templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__))); // On header
  10. // Simple table
  11. $templateProcessor->cloneRow('rowValue', 10);
  12. $templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun'));
  13. $templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury'));
  14. $templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus'));
  15. $templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth'));
  16. $templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars'));
  17. $templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter'));
  18. $templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn'));
  19. $templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus'));
  20. $templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun'));
  21. $templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto'));
  22. $templateProcessor->setValue('rowNumber#1', htmlspecialchars('1'));
  23. $templateProcessor->setValue('rowNumber#2', htmlspecialchars('2'));
  24. $templateProcessor->setValue('rowNumber#3', htmlspecialchars('3'));
  25. $templateProcessor->setValue('rowNumber#4', htmlspecialchars('4'));
  26. $templateProcessor->setValue('rowNumber#5', htmlspecialchars('5'));
  27. $templateProcessor->setValue('rowNumber#6', htmlspecialchars('6'));
  28. $templateProcessor->setValue('rowNumber#7', htmlspecialchars('7'));
  29. $templateProcessor->setValue('rowNumber#8', htmlspecialchars('8'));
  30. $templateProcessor->setValue('rowNumber#9', htmlspecialchars('9'));
  31. $templateProcessor->setValue('rowNumber#10', htmlspecialchars('10'));
  32. // Table with a spanned cell
  33. $templateProcessor->cloneRow('userId', 3);
  34. $templateProcessor->setValue('userId#1', htmlspecialchars('1'));
  35. $templateProcessor->setValue('userFirstName#1', htmlspecialchars('James'));
  36. $templateProcessor->setValue('userName#1', htmlspecialchars('Taylor'));
  37. $templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773'));
  38. $templateProcessor->setValue('userId#2', htmlspecialchars('2'));
  39. $templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert'));
  40. $templateProcessor->setValue('userName#2', htmlspecialchars('Bell'));
  41. $templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774'));
  42. $templateProcessor->setValue('userId#3', htmlspecialchars('3'));
  43. $templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael'));
  44. $templateProcessor->setValue('userName#3', htmlspecialchars('Ray'));
  45. $templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775'));
  46. echo date('H:i:s'), ' Saving the result document...', EOL;
  47. $templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');
  48. echo getEndingNotes(array('Word2007' => 'docx'));
  49. if (!CLI) {
  50. include_once 'Sample_Footer.php';
  51. }