2013-12-16 17:24:46 +01:00
|
|
|
<?php
|
2014-03-15 22:39:57 +07:00
|
|
|
include_once 'Sample_Header.php';
|
2013-12-16 17:24:46 +01:00
|
|
|
|
2014-03-12 21:55:20 +07:00
|
|
|
// New Word document
|
2014-03-23 10:32:08 +04:00
|
|
|
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
|
|
|
|
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
2013-12-16 17:24:46 +01:00
|
|
|
|
2014-03-20 16:54:12 +04:00
|
|
|
$document = $phpWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
|
2013-12-16 17:24:46 +01:00
|
|
|
|
2014-04-02 18:57:34 +07:00
|
|
|
// Variables on different parts of document
|
|
|
|
|
$document->setValue('weekday', date('l')); // On section/content
|
|
|
|
|
$document->setValue('time', date('H:i')); // On footer
|
2014-04-03 21:03:10 +07:00
|
|
|
$document->setValue('serverName', realpath(__DIR__)); // On header
|
2014-04-02 18:57:34 +07:00
|
|
|
|
2014-01-10 14:26:02 +01:00
|
|
|
// Simple table
|
2013-12-16 17:24:46 +01:00
|
|
|
$document->cloneRow('rowValue', 10);
|
|
|
|
|
|
|
|
|
|
$document->setValue('rowValue#1', 'Sun');
|
|
|
|
|
$document->setValue('rowValue#2', 'Mercury');
|
|
|
|
|
$document->setValue('rowValue#3', 'Venus');
|
|
|
|
|
$document->setValue('rowValue#4', 'Earth');
|
|
|
|
|
$document->setValue('rowValue#5', 'Mars');
|
|
|
|
|
$document->setValue('rowValue#6', 'Jupiter');
|
|
|
|
|
$document->setValue('rowValue#7', 'Saturn');
|
|
|
|
|
$document->setValue('rowValue#8', 'Uranus');
|
|
|
|
|
$document->setValue('rowValue#9', 'Neptun');
|
|
|
|
|
$document->setValue('rowValue#10', 'Pluto');
|
|
|
|
|
|
|
|
|
|
$document->setValue('rowNumber#1', '1');
|
|
|
|
|
$document->setValue('rowNumber#2', '2');
|
|
|
|
|
$document->setValue('rowNumber#3', '3');
|
|
|
|
|
$document->setValue('rowNumber#4', '4');
|
|
|
|
|
$document->setValue('rowNumber#5', '5');
|
|
|
|
|
$document->setValue('rowNumber#6', '6');
|
|
|
|
|
$document->setValue('rowNumber#7', '7');
|
|
|
|
|
$document->setValue('rowNumber#8', '8');
|
|
|
|
|
$document->setValue('rowNumber#9', '9');
|
|
|
|
|
$document->setValue('rowNumber#10', '10');
|
|
|
|
|
|
2014-01-10 14:26:02 +01:00
|
|
|
// Table with a spanned cell
|
|
|
|
|
$document->cloneRow('userId', 3);
|
|
|
|
|
|
|
|
|
|
$document->setValue('userId#1', '1');
|
|
|
|
|
$document->setValue('userFirstName#1', 'James');
|
|
|
|
|
$document->setValue('userName#1', 'Taylor');
|
|
|
|
|
$document->setValue('userPhone#1', '+1 428 889 773');
|
|
|
|
|
|
|
|
|
|
$document->setValue('userId#2', '2');
|
|
|
|
|
$document->setValue('userFirstName#2', 'Robert');
|
|
|
|
|
$document->setValue('userName#2', 'Bell');
|
|
|
|
|
$document->setValue('userPhone#2', '+1 428 889 774');
|
|
|
|
|
|
|
|
|
|
$document->setValue('userId#3', '3');
|
|
|
|
|
$document->setValue('userFirstName#3', 'Michael');
|
|
|
|
|
$document->setValue('userName#3', 'Ray');
|
|
|
|
|
$document->setValue('userPhone#3', '+1 428 889 775');
|
|
|
|
|
|
2014-03-24 00:26:10 +07:00
|
|
|
$name = 'Sample_07_TemplateCloneRow.docx';
|
2014-03-23 10:32:08 +04:00
|
|
|
echo date('H:i:s'), " Write to Word2007 format", \EOL;
|
2014-03-12 21:55:20 +07:00
|
|
|
$document->saveAs($name);
|
|
|
|
|
rename($name, "results/{$name}");
|
|
|
|
|
|
2014-03-15 22:39:57 +07:00
|
|
|
include_once 'Sample_Footer.php';
|