#51 (updated samples).
This commit is contained in:
parent
d4d498d698
commit
c116afbd02
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
||||
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
|
||||
|
|
@ -12,16 +12,16 @@ $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
|||
$section = $phpWord->addSection();
|
||||
|
||||
// Simple text
|
||||
$section->addTitle('Welcome to PhpWord', 1);
|
||||
$section->addText('Hello World!');
|
||||
$section->addTitle(htmlspecialchars('Welcome to PhpWord'), 1);
|
||||
$section->addText(htmlspecialchars('Hello World!'));
|
||||
|
||||
// Two text break
|
||||
$section->addTextBreak(2);
|
||||
|
||||
// Defined style
|
||||
$section->addText('I am styled by a font style definition.', 'rStyle');
|
||||
$section->addText('I am styled by a paragraph style definition.', null, 'pStyle');
|
||||
$section->addText('I am styled by both font and paragraph style.', 'rStyle', 'pStyle');
|
||||
$section->addText(htmlspecialchars('I am styled by a font style definition.'), 'rStyle');
|
||||
$section->addText(htmlspecialchars('I am styled by a paragraph style definition.'), null, 'pStyle');
|
||||
$section->addText(htmlspecialchars('I am styled by both font and paragraph style.'), 'rStyle', 'pStyle');
|
||||
|
||||
$section->addTextBreak();
|
||||
|
||||
|
|
@ -30,39 +30,39 @@ $fontStyle['name'] = 'Times New Roman';
|
|||
$fontStyle['size'] = 20;
|
||||
|
||||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('I am inline styled ', $fontStyle);
|
||||
$textrun->addText('with ');
|
||||
$textrun->addText('color', array('color' => '996699'));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('bold', array('bold' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('italic', array('italic' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('underline', array('underline' => 'dash'));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('strikethrough', array('strikethrough' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('doubleStrikethrough', array('doubleStrikethrough' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('superScript', array('superScript' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('subScript', array('subScript' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('smallCaps', array('smallCaps' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('allCaps', array('allCaps' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('fgColor', array('fgColor' => 'yellow'));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('scale', array('scale' => 200));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('spacing', array('spacing' => 120));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addText('kerning', array('kerning' => 10));
|
||||
$textrun->addText('. ');
|
||||
$textrun->addText(htmlspecialchars('I am inline styled '), $fontStyle);
|
||||
$textrun->addText(htmlspecialchars('with '));
|
||||
$textrun->addText(htmlspecialchars('color'), array('color' => '996699'));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('bold'), array('bold' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('italic'), array('italic' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('underline'), array('underline' => 'dash'));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('strikethrough'), array('strikethrough' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('doubleStrikethrough'), array('doubleStrikethrough' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('superScript'), array('superScript' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('subScript'), array('subScript' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('smallCaps'), array('smallCaps' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('allCaps'), array('allCaps' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('fgColor'), array('fgColor' => 'yellow'));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('scale'), array('scale' => 200));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('spacing'), array('spacing' => 120));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addText(htmlspecialchars('kerning'), array('kerning' => 10));
|
||||
$textrun->addText(htmlspecialchars('. '));
|
||||
|
||||
// Link
|
||||
$section->addLink('http://www.google.com', 'Google');
|
||||
$section->addLink('http://www.google.com', htmlspecialchars('Google'));
|
||||
$section->addTextBreak();
|
||||
|
||||
// Image
|
||||
|
|
|
|||
|
|
@ -2,35 +2,36 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Ads styles
|
||||
$phpWord->addParagraphStyle('multipleTab', array(
|
||||
'tabs' => array(
|
||||
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
|
||||
new \PhpOffice\PhpWord\Style\Tab('center', 3200),
|
||||
new \PhpOffice\PhpWord\Style\Tab('right', 5300)
|
||||
)
|
||||
));
|
||||
$phpWord->addParagraphStyle('rightTab', array(
|
||||
'tabs' => array(
|
||||
new \PhpOffice\PhpWord\Style\Tab('right', 9090)
|
||||
)
|
||||
));
|
||||
$phpWord->addParagraphStyle('centerTab', array(
|
||||
'tabs' => array(
|
||||
new \PhpOffice\PhpWord\Style\Tab('center', 4680)
|
||||
)
|
||||
));
|
||||
$phpWord->addParagraphStyle(
|
||||
'multipleTab',
|
||||
array(
|
||||
'tabs' => array(
|
||||
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
|
||||
new \PhpOffice\PhpWord\Style\Tab('center', 3200),
|
||||
new \PhpOffice\PhpWord\Style\Tab('right', 5300),
|
||||
)
|
||||
)
|
||||
);
|
||||
$phpWord->addParagraphStyle(
|
||||
'rightTab',
|
||||
array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)))
|
||||
);
|
||||
$phpWord->addParagraphStyle(
|
||||
'centerTab',
|
||||
array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680)))
|
||||
);
|
||||
|
||||
// New portrait section
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
// Add listitem elements
|
||||
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", null, 'multipleTab');
|
||||
$section->addText("Left Aligned\tRight Aligned", null, 'rightTab');
|
||||
$section->addText("\tCenter Aligned", null, 'centerTab');
|
||||
$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree"), null, 'multipleTab');
|
||||
$section->addText(htmlspecialchars("Left Aligned\tRight Aligned"), null, 'rightTab');
|
||||
$section->addText(htmlspecialchars("\tCenter Aligned"), null, 'centerTab');
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,28 +2,43 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// New portrait section
|
||||
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
|
||||
$section->addText('I am placed on a default section.');
|
||||
$section->addText(htmlspecialchars('I am placed on a default section.'));
|
||||
|
||||
// New landscape section
|
||||
$section = $phpWord->addSection(array('orientation' => 'landscape'));
|
||||
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'I am placed on a landscape section. Every page starting from this section will be landscape style.'
|
||||
)
|
||||
);
|
||||
$section->addPageBreak();
|
||||
$section->addPageBreak();
|
||||
|
||||
// New portrait section
|
||||
$section = $phpWord->addSection(array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
|
||||
$section->addText('This section uses other margins with folio papersize.');
|
||||
$section = $phpWord->addSection(
|
||||
array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
||||
);
|
||||
$section->addText(htmlspecialchars('This section uses other margins with folio papersize.'));
|
||||
|
||||
// New portrait section with Header & Footer
|
||||
$section = $phpWord->addSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
|
||||
$section->addText('This section and we play with header/footer height.');
|
||||
$section->addHeader()->addText('Header');
|
||||
$section->addFooter()->addText('Footer');
|
||||
$section = $phpWord->addSection(
|
||||
array(
|
||||
'marginLeft' => 200,
|
||||
'marginRight' => 200,
|
||||
'marginTop' => 200,
|
||||
'marginBottom' => 200,
|
||||
'headerHeight' => 50,
|
||||
'footerHeight' => 50,
|
||||
)
|
||||
);
|
||||
$section->addText(htmlspecialchars('This section and we play with header/footer height.'));
|
||||
$section->addHeader()->addText(htmlspecialchars('Header'));
|
||||
$section->addFooter()->addText(htmlspecialchars('Footer'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,14 +2,17 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Ads styles
|
||||
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
|
||||
$phpWord->addFontStyle('BoldText', array('bold'=>true));
|
||||
$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080', 'bgColor' => 'FFFFCC'));
|
||||
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
||||
$phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
|
||||
$phpWord->addFontStyle('BoldText', array('bold' => true));
|
||||
$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080', 'bgColor' => 'FFFFCC'));
|
||||
$phpWord->addLinkStyle(
|
||||
'NLink',
|
||||
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
||||
);
|
||||
|
||||
// New portrait section
|
||||
$section = $phpWord->addSection();
|
||||
|
|
@ -17,21 +20,24 @@ $section = $phpWord->addSection();
|
|||
// Add text run
|
||||
$textrun = $section->addTextRun('pStyle');
|
||||
|
||||
$textrun->addText('Each textrun can contain native text, link elements or an image.');
|
||||
$textrun->addText(' No break is placed after adding an element.', 'BoldText');
|
||||
$textrun->addText(' Both ');
|
||||
$textrun->addText('superscript', array('superScript' => true));
|
||||
$textrun->addText(' and ');
|
||||
$textrun->addText('subscript', array('subScript' => true));
|
||||
$textrun->addText(' are also available.');
|
||||
$textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText');
|
||||
$textrun->addText(' Sample Link: ');
|
||||
$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.'));
|
||||
$textrun->addText(htmlspecialchars(' No break is placed after adding an element.'), 'BoldText');
|
||||
$textrun->addText(htmlspecialchars(' Both '));
|
||||
$textrun->addText(htmlspecialchars('superscript'), array('superScript' => true));
|
||||
$textrun->addText(htmlspecialchars(' and '));
|
||||
$textrun->addText(htmlspecialchars('subscript'), array('subScript' => true));
|
||||
$textrun->addText(htmlspecialchars(' are also available.'));
|
||||
$textrun->addText(
|
||||
htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.'),
|
||||
'ColoredText'
|
||||
);
|
||||
$textrun->addText(htmlspecialchars(' Sample Link: '));
|
||||
$textrun->addLink('http://www.google.com', null, 'NLink');
|
||||
$textrun->addText(' Sample Image: ');
|
||||
$textrun->addText(htmlspecialchars(' Sample Image: '));
|
||||
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||
$textrun->addText(' Sample Object: ');
|
||||
$textrun->addText(htmlspecialchars(' Sample Object: '));
|
||||
$textrun->addObject('resources/_sheet.xls');
|
||||
$textrun->addText(' Here is some more text. ');
|
||||
$textrun->addText(htmlspecialchars(' Here is some more text. '));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,38 +2,44 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
|
||||
'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' .
|
||||
'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' .
|
||||
'Suspendisse congue congue leo sed pellentesque.';
|
||||
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
|
||||
. 'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. '
|
||||
. 'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. '
|
||||
. 'Suspendisse congue congue leo sed pellentesque.';
|
||||
|
||||
// Normal
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('Normal paragraph. ' . $filler);
|
||||
$section->addText(htmlspecialchars("Normal paragraph. {$filler}"));
|
||||
|
||||
// Two columns
|
||||
$section = $phpWord->addSection(array(
|
||||
'colsNum' => 2,
|
||||
'colsSpace' => 1440,
|
||||
'breakType' => 'continuous'));
|
||||
$section->addText('Two columns, one inch (1440 twips) spacing. ' . $filler);
|
||||
$section = $phpWord->addSection(
|
||||
array(
|
||||
'colsNum' => 2,
|
||||
'colsSpace' => 1440,
|
||||
'breakType' => 'continuous',
|
||||
)
|
||||
);
|
||||
$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}"));
|
||||
|
||||
// Normal
|
||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||
$section->addText('Normal paragraph again. ' . $filler);
|
||||
$section->addText(htmlspecialchars("Normal paragraph again. {$filler}"));
|
||||
|
||||
// Three columns
|
||||
$section = $phpWord->addSection(array(
|
||||
'colsNum' => 3,
|
||||
'colsSpace' => 720,
|
||||
'breakType' => 'continuous'));
|
||||
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
|
||||
$section = $phpWord->addSection(
|
||||
array(
|
||||
'colsNum' => 3,
|
||||
'colsSpace' => 720,
|
||||
'breakType' => 'continuous',
|
||||
)
|
||||
);
|
||||
$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}"));
|
||||
|
||||
// Normal
|
||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||
$section->addText('Normal paragraph again.');
|
||||
$section->addText(htmlspecialchars('Normal paragraph again.'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
\PhpOffice\PhpWord\Settings::setCompatibility(false);
|
||||
|
||||
|
|
@ -10,32 +10,40 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|||
$section = $phpWord->addSection();
|
||||
|
||||
// Add style definitions
|
||||
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
|
||||
$phpWord->addFontStyle('BoldText', array('bold'=>true));
|
||||
$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
|
||||
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
||||
$phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
|
||||
$phpWord->addFontStyle('BoldText', array('bold' => true));
|
||||
$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080'));
|
||||
$phpWord->addLinkStyle(
|
||||
'NLink',
|
||||
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
||||
);
|
||||
|
||||
// Add text elements
|
||||
$textrun = $section->addTextRun('pStyle');
|
||||
$textrun->addText('This is some lead text in a paragraph with a following footnote. ','pStyle');
|
||||
$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. '), 'pStyle');
|
||||
|
||||
$footnote = $textrun->addFootnote();
|
||||
$footnote->addText('Just like a textrun, a footnote can contain native texts. ');
|
||||
$footnote->addText('No break is placed after adding an element. ', 'BoldText');
|
||||
$footnote->addText('All elements are placed inside a paragraph. ', 'ColoredText');
|
||||
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. '));
|
||||
$footnote->addText(htmlspecialchars('No break is placed after adding an element. '), 'BoldText');
|
||||
$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. '), 'ColoredText');
|
||||
$footnote->addTextBreak();
|
||||
$footnote->addText('But you can insert a manual text break like above, ');
|
||||
$footnote->addText('links like ');
|
||||
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, '));
|
||||
$footnote->addText(htmlspecialchars('links like '));
|
||||
$footnote->addLink('http://www.google.com', null, 'NLink');
|
||||
$footnote->addText(', image like ');
|
||||
$footnote->addText(htmlspecialchars(', image like '));
|
||||
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||
$footnote->addText(', or object like ');
|
||||
$footnote->addText(htmlspecialchars(', or object like '));
|
||||
$footnote->addObject('resources/_sheet.xls');
|
||||
$footnote->addText('But you can only put footnote in section, not in header or footer.');
|
||||
$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.'));
|
||||
|
||||
$section->addText('You can also create the footnote directly from the section making it wrap in a paragraph like the footnote below this paragraph. But is is best used from within a textrun.');
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'You can also create the footnote directly from the section making it wrap in a paragraph '
|
||||
. 'like the footnote below this paragraph. But is is best used from within a textrun.'
|
||||
)
|
||||
);
|
||||
$footnote = $section->addFootnote();
|
||||
$footnote->addText('The reference for this is wrapped in its own line');
|
||||
$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,56 +2,56 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// Template processor instance creation
|
||||
echo date('H:i:s') , ' Creating new TemplateProcessor instance...' , EOL;
|
||||
echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
|
||||
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
|
||||
|
||||
// Variables on different parts of document
|
||||
$templateProcessor->setValue('weekday', date('l')); // On section/content
|
||||
$templateProcessor->setValue('time', date('H:i')); // On footer
|
||||
$templateProcessor->setValue('serverName', realpath(__DIR__)); // On header
|
||||
$templateProcessor->setValue('weekday', htmlspecialchars(date('l'))); // On section/content
|
||||
$templateProcessor->setValue('time', htmlspecialchars(date('H:i'))); // On footer
|
||||
$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__))); // On header
|
||||
|
||||
// Simple table
|
||||
$templateProcessor->cloneRow('rowValue', 10);
|
||||
|
||||
$templateProcessor->setValue('rowValue#1', 'Sun');
|
||||
$templateProcessor->setValue('rowValue#2', 'Mercury');
|
||||
$templateProcessor->setValue('rowValue#3', 'Venus');
|
||||
$templateProcessor->setValue('rowValue#4', 'Earth');
|
||||
$templateProcessor->setValue('rowValue#5', 'Mars');
|
||||
$templateProcessor->setValue('rowValue#6', 'Jupiter');
|
||||
$templateProcessor->setValue('rowValue#7', 'Saturn');
|
||||
$templateProcessor->setValue('rowValue#8', 'Uranus');
|
||||
$templateProcessor->setValue('rowValue#9', 'Neptun');
|
||||
$templateProcessor->setValue('rowValue#10', 'Pluto');
|
||||
$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun'));
|
||||
$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury'));
|
||||
$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus'));
|
||||
$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth'));
|
||||
$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars'));
|
||||
$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter'));
|
||||
$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn'));
|
||||
$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus'));
|
||||
$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun'));
|
||||
$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto'));
|
||||
|
||||
$templateProcessor->setValue('rowNumber#1', '1');
|
||||
$templateProcessor->setValue('rowNumber#2', '2');
|
||||
$templateProcessor->setValue('rowNumber#3', '3');
|
||||
$templateProcessor->setValue('rowNumber#4', '4');
|
||||
$templateProcessor->setValue('rowNumber#5', '5');
|
||||
$templateProcessor->setValue('rowNumber#6', '6');
|
||||
$templateProcessor->setValue('rowNumber#7', '7');
|
||||
$templateProcessor->setValue('rowNumber#8', '8');
|
||||
$templateProcessor->setValue('rowNumber#9', '9');
|
||||
$templateProcessor->setValue('rowNumber#10', '10');
|
||||
$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1'));
|
||||
$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2'));
|
||||
$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3'));
|
||||
$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4'));
|
||||
$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5'));
|
||||
$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6'));
|
||||
$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7'));
|
||||
$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8'));
|
||||
$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9'));
|
||||
$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10'));
|
||||
|
||||
// Table with a spanned cell
|
||||
$templateProcessor->cloneRow('userId', 3);
|
||||
|
||||
$templateProcessor->setValue('userId#1', '1');
|
||||
$templateProcessor->setValue('userFirstName#1', 'James');
|
||||
$templateProcessor->setValue('userName#1', 'Taylor');
|
||||
$templateProcessor->setValue('userPhone#1', '+1 428 889 773');
|
||||
$templateProcessor->setValue('userId#1', htmlspecialchars('1'));
|
||||
$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James'));
|
||||
$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor'));
|
||||
$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773'));
|
||||
|
||||
$templateProcessor->setValue('userId#2', '2');
|
||||
$templateProcessor->setValue('userFirstName#2', 'Robert');
|
||||
$templateProcessor->setValue('userName#2', 'Bell');
|
||||
$templateProcessor->setValue('userPhone#2', '+1 428 889 774');
|
||||
$templateProcessor->setValue('userId#2', htmlspecialchars('2'));
|
||||
$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert'));
|
||||
$templateProcessor->setValue('userName#2', htmlspecialchars('Bell'));
|
||||
$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774'));
|
||||
|
||||
$templateProcessor->setValue('userId#3', '3');
|
||||
$templateProcessor->setValue('userFirstName#3', 'Michael');
|
||||
$templateProcessor->setValue('userName#3', 'Ray');
|
||||
$templateProcessor->setValue('userPhone#3', '+1 428 889 775');
|
||||
$templateProcessor->setValue('userId#3', htmlspecialchars('3'));
|
||||
$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael'));
|
||||
$templateProcessor->setValue('userName#3', htmlspecialchars('Ray'));
|
||||
$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775'));
|
||||
|
||||
echo date('H:i:s'), ' Saving the result document...', EOL;
|
||||
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');
|
||||
|
|
|
|||
|
|
@ -2,48 +2,75 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$phpWord->setDefaultParagraphStyle(array(
|
||||
'align' => 'both',
|
||||
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12),
|
||||
'spacing' => 120,
|
||||
));
|
||||
$phpWord->setDefaultParagraphStyle(
|
||||
array(
|
||||
'align' => 'both',
|
||||
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12),
|
||||
'spacing' => 120,
|
||||
)
|
||||
);
|
||||
|
||||
// Sample
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$section->addText('Below are the samples on how to control your paragraph ' .
|
||||
'pagination. See "Line and Page Break" tab on paragraph properties ' .
|
||||
'window to see the attribute set by these controls.',
|
||||
array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'Below are the samples on how to control your paragraph '
|
||||
. 'pagination. See "Line and Page Break" tab on paragraph properties '
|
||||
. 'window to see the attribute set by these controls.'
|
||||
),
|
||||
array('bold' => true),
|
||||
array('space' => array('before' => 360, 'after' => 480))
|
||||
);
|
||||
|
||||
$section->addText('Paragraph with widowControl = false (default: true). ' .
|
||||
'A "widow" is the last line of a paragraph printed by itself at the top ' .
|
||||
'of a page. An "orphan" is the first line of a paragraph printed by ' .
|
||||
'itself at the bottom of a page. Set this option to "false" if you want ' .
|
||||
'to disable this automatic control.',
|
||||
null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'Paragraph with widowControl = false (default: true). '
|
||||
. 'A "widow" is the last line of a paragraph printed by itself at the top '
|
||||
. 'of a page. An "orphan" is the first line of a paragraph printed by '
|
||||
. 'itself at the bottom of a page. Set this option to "false" if you want '
|
||||
. 'to disable this automatic control.'
|
||||
),
|
||||
null,
|
||||
array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))
|
||||
);
|
||||
|
||||
$section->addText('Paragraph with keepNext = true (default: false). ' .
|
||||
'"Keep with next" is used to prevent Word from inserting automatic page ' .
|
||||
'breaks between paragraphs. Set this option to "true" if you do not want ' .
|
||||
'your paragraph to be separated with the next paragraph.',
|
||||
null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'Paragraph with keepNext = true (default: false). '
|
||||
. '"Keep with next" is used to prevent Word from inserting automatic page '
|
||||
. 'breaks between paragraphs. Set this option to "true" if you do not want '
|
||||
. 'your paragraph to be separated with the next paragraph.'
|
||||
),
|
||||
null,
|
||||
array('keepNext' => true, 'indentation' => array('firstLine' => 240))
|
||||
);
|
||||
|
||||
$section->addText('Paragraph with keepLines = true (default: false). ' .
|
||||
'"Keep lines together" will prevent Word from inserting an automatic page ' .
|
||||
'break within a paragraph. Set this option to "true" if you do not want ' .
|
||||
'all lines of your paragraph to be in the same page.',
|
||||
null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'Paragraph with keepLines = true (default: false). '
|
||||
. '"Keep lines together" will prevent Word from inserting an automatic page '
|
||||
. 'break within a paragraph. Set this option to "true" if you do not want '
|
||||
. 'all lines of your paragraph to be in the same page.'
|
||||
),
|
||||
null,
|
||||
array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240))
|
||||
);
|
||||
|
||||
$section->addText('Keep scrolling. More below.');
|
||||
$section->addText(htmlspecialchars('Keep scrolling. More below.'));
|
||||
|
||||
$section->addText('Paragraph with pageBreakBefore = true (default: false). ' .
|
||||
'Different with all other control above, "page break before" separates ' .
|
||||
'your paragraph into the next page. This option is most useful for ' .
|
||||
'heading styles.',
|
||||
null, array('pageBreakBefore' => true));
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'Paragraph with pageBreakBefore = true (default: false). '
|
||||
. 'Different with all other control above, "page break before" separates '
|
||||
. 'your paragraph into the next page. This option is most useful for '
|
||||
. 'heading styles.'
|
||||
),
|
||||
null,
|
||||
array('pageBreakBefore' => true)
|
||||
);
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
$header = array('size' => 16, 'bold' => true);
|
||||
|
|
@ -11,20 +11,20 @@ $header = array('size' => 16, 'bold' => true);
|
|||
|
||||
$rows = 10;
|
||||
$cols = 5;
|
||||
$section->addText("Basic table", $header);
|
||||
$section->addText(htmlspecialchars('Basic table'), $header);
|
||||
|
||||
$table = $section->addTable();
|
||||
for($r = 1; $r <= 8; $r++) {
|
||||
for ($r = 1; $r <= 8; $r++) {
|
||||
$table->addRow();
|
||||
for($c = 1; $c <= 5; $c++) {
|
||||
$table->addCell(1750)->addText("Row $r, Cell $c");
|
||||
for ($c = 1; $c <= 5; $c++) {
|
||||
$table->addCell(1750)->addText(htmlspecialchars("Row {$r}, Cell {$c}"));
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Advanced table
|
||||
|
||||
$section->addTextBreak(1);
|
||||
$section->addText("Fancy table", $header);
|
||||
$section->addText(htmlspecialchars('Fancy table'), $header);
|
||||
|
||||
$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80);
|
||||
$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
|
||||
|
|
@ -34,25 +34,25 @@ $fontStyle = array('bold' => true, 'align' => 'center');
|
|||
$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
|
||||
$table = $section->addTable('Fancy Table');
|
||||
$table->addRow(900);
|
||||
$table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle);
|
||||
$table->addCell(2000, $styleCell)->addText('Row 2', $fontStyle);
|
||||
$table->addCell(2000, $styleCell)->addText('Row 3', $fontStyle);
|
||||
$table->addCell(2000, $styleCell)->addText('Row 4', $fontStyle);
|
||||
$table->addCell(500, $styleCellBTLR)->addText('Row 5', $fontStyle);
|
||||
for($i = 1; $i <= 8; $i++) {
|
||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1'), $fontStyle);
|
||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2'), $fontStyle);
|
||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3'), $fontStyle);
|
||||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4'), $fontStyle);
|
||||
$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5'), $fontStyle);
|
||||
for ($i = 1; $i <= 8; $i++) {
|
||||
$table->addRow();
|
||||
$table->addCell(2000)->addText("Cell $i");
|
||||
$table->addCell(2000)->addText("Cell $i");
|
||||
$table->addCell(2000)->addText("Cell $i");
|
||||
$table->addCell(2000)->addText("Cell $i");
|
||||
$text = ($i % 2 == 0) ? 'X' : '';
|
||||
$table->addCell(500)->addText($text);
|
||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||
$text = (0== $i % 2) ? 'X' : '';
|
||||
$table->addCell(500)->addText(htmlspecialchars($text));
|
||||
}
|
||||
|
||||
// 3. colspan (gridSpan) and rowspan (vMerge)
|
||||
|
||||
$section->addPageBreak();
|
||||
$section->addText("Table with colspan and rowspan", $header);
|
||||
$section->addText(htmlspecialchars('Table with colspan and rowspan'), $header);
|
||||
|
||||
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
|
||||
$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00');
|
||||
|
|
@ -68,32 +68,32 @@ $table->addRow();
|
|||
|
||||
$cell1 = $table->addCell(2000, $cellRowSpan);
|
||||
$textrun1 = $cell1->addTextRun($cellHCentered);
|
||||
$textrun1->addText('A');
|
||||
$textrun1->addFootnote()->addText('Row span');
|
||||
$textrun1->addText(htmlspecialchars('A'));
|
||||
$textrun1->addFootnote()->addText(htmlspecialchars('Row span'));
|
||||
|
||||
$cell2 = $table->addCell(4000, $cellColSpan);
|
||||
$textrun2 = $cell2->addTextRun($cellHCentered);
|
||||
$textrun2->addText('B');
|
||||
$textrun2->addFootnote()->addText('Colspan span');
|
||||
$textrun2->addText(htmlspecialchars('B'));
|
||||
$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span'));
|
||||
|
||||
$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered);
|
||||
$table->addCell(2000, $cellRowSpan)->addText(htmlspecialchars('E'), null, $cellHCentered);
|
||||
|
||||
$table->addRow();
|
||||
$table->addCell(null, $cellRowContinue);
|
||||
$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
|
||||
$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered);
|
||||
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C'), null, $cellHCentered);
|
||||
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D'), null, $cellHCentered);
|
||||
$table->addCell(null, $cellRowContinue);
|
||||
|
||||
// 4. Nested table
|
||||
|
||||
$section->addTextBreak(2);
|
||||
$section->addText('Nested table in a centered and 50% width table.', $header);
|
||||
$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.'), $header);
|
||||
|
||||
$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'align' => 'center'));
|
||||
$cell = $table->addRow()->addCell();
|
||||
$cell->addText('This cell contains nested table.');
|
||||
$cell->addText(htmlspecialchars('This cell contains nested table.'));
|
||||
$innerCell = $cell->addTable(array('align' => 'center'))->addRow()->addCell();
|
||||
$innerCell->addText('Inside nested table');
|
||||
$innerCell->addText(htmlspecialchars('Inside nested table'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
$header = array('size' => 16, 'bold' => true);
|
||||
//1.Use EastAisa FontStyle
|
||||
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
||||
$section->addText(htmlspecialchars('中文楷体样式测试'), array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// New portrait section
|
||||
|
|
@ -15,8 +15,8 @@ $table = $header->addTable();
|
|||
$table->addRow();
|
||||
$cell = $table->addCell(4500);
|
||||
$textrun = $cell->addTextRun();
|
||||
$textrun->addText('This is the header with ');
|
||||
$textrun->addLink('http://google.com', 'link to Google');
|
||||
$textrun->addText(htmlspecialchars('This is the header with '));
|
||||
$textrun->addLink('http://google.com', htmlspecialchars('link to Google'));
|
||||
$table->addCell(4500)->addImage(
|
||||
'resources/PhpWord.png',
|
||||
array('width' => 80, 'height' => 80, 'align' => 'right')
|
||||
|
|
@ -24,41 +24,41 @@ $table->addCell(4500)->addImage(
|
|||
|
||||
// Add header for all other pages
|
||||
$subsequent = $section->addHeader();
|
||||
$subsequent->addText("Subsequent pages in Section 1 will Have this!");
|
||||
$subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!'));
|
||||
$subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80));
|
||||
|
||||
// Add footer
|
||||
$footer = $section->addFooter();
|
||||
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center'));
|
||||
$footer->addLink('http://google.com', 'Direct Google');
|
||||
$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.'), array('align' => 'center'));
|
||||
$footer->addLink('http://google.com', htmlspecialchars('Direct Google'));
|
||||
|
||||
// Write some text
|
||||
$section->addTextBreak();
|
||||
$section->addText('Some text...');
|
||||
$section->addText(htmlspecialchars('Some text...'));
|
||||
|
||||
// Create a second page
|
||||
$section->addPageBreak();
|
||||
|
||||
// Write some text
|
||||
$section->addTextBreak();
|
||||
$section->addText('Some text...');
|
||||
$section->addText(htmlspecialchars('Some text...'));
|
||||
|
||||
// Create a third page
|
||||
$section->addPageBreak();
|
||||
|
||||
// Write some text
|
||||
$section->addTextBreak();
|
||||
$section->addText('Some text...');
|
||||
$section->addText(htmlspecialchars('Some text...'));
|
||||
|
||||
// New portrait section
|
||||
$section2 = $phpWord->addSection();
|
||||
|
||||
$sec2Header = $section2->addHeader();
|
||||
$sec2Header->addText("All pages in Section 2 will Have this!");
|
||||
$sec2Header->addText(htmlspecialchars('All pages in Section 2 will Have this!'));
|
||||
|
||||
// Write some text
|
||||
$section2->addTextBreak();
|
||||
$section2->addText('Some text...');
|
||||
$section2->addText(htmlspecialchars('Some text...'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('Local image without any styles:');
|
||||
$section->addText(htmlspecialchars('Local image without any styles:'));
|
||||
$section->addImage('resources/_mars.jpg');
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addText('Local image with styles:');
|
||||
$section->addText(htmlspecialchars('Local image with styles:'));
|
||||
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
// Remote image
|
||||
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
||||
$section->addText("Remote image from: {$source}");
|
||||
$section->addText(htmlspecialchars("Remote image from: {$source}"));
|
||||
$section->addImage($source);
|
||||
|
||||
//Wrapping style
|
||||
|
|
@ -25,43 +25,52 @@ $text = str_repeat('Hello World! ', 15);
|
|||
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
||||
foreach ($wrappingStyles as $wrappingStyle) {
|
||||
$section->addTextBreak(5);
|
||||
$section->addText('Wrapping style ' . $wrappingStyle);
|
||||
$section->addImage('resources/_earth.jpg', array('positioning' => 'relative', 'marginTop' => -1, 'marginLeft' => 1,
|
||||
'width' => 80, 'height' => 80, 'wrappingStyle' => $wrappingStyle));
|
||||
$section->addText($text);
|
||||
$section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}"));
|
||||
$section->addImage(
|
||||
'resources/_earth.jpg',
|
||||
array(
|
||||
'positioning' => 'relative',
|
||||
'marginTop' => -1,
|
||||
'marginLeft' => 1,
|
||||
'width' => 80,
|
||||
'height' => 80,
|
||||
'wrappingStyle' => $wrappingStyle,
|
||||
)
|
||||
);
|
||||
$section->addText(htmlspecialchars($text));
|
||||
}
|
||||
|
||||
//Absolute positioning
|
||||
$section->addTextBreak(3);
|
||||
$section->addText('Absolute positioning: see top right corner of page');
|
||||
$section->addText(htmlspecialchars('Absolute positioning: see top right corner of page'));
|
||||
$section->addImage(
|
||||
'resources/_mars.jpg',
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
|
||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
|
||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
|
||||
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.5),
|
||||
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1.55)
|
||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.5),
|
||||
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1.55),
|
||||
)
|
||||
);
|
||||
|
||||
//Relative positioning
|
||||
$section->addTextBreak(3);
|
||||
$section->addText('Relative positioning: Horizontal position center relative to column,');
|
||||
$section->addText('Vertical position top relative to line');
|
||||
$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,'));
|
||||
$section->addText(htmlspecialchars('Vertical position top relative to line'));
|
||||
$section->addImage(
|
||||
'resources/_mars.jpg',
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE,
|
||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE,
|
||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
|
||||
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN,
|
||||
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
|
||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE
|
||||
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
|
||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
|
|
@ -10,80 +10,83 @@ $section = $phpWord->addSection();
|
|||
|
||||
// Style definition
|
||||
|
||||
$phpWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
|
||||
$phpWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
|
||||
$phpWord->addFontStyle('myOwnStyle', array('color' => 'FF0000'));
|
||||
$phpWord->addParagraphStyle('P-Style', array('spaceAfter' => 95));
|
||||
$phpWord->addNumberingStyle(
|
||||
'multilevel',
|
||||
array('type' => 'multilevel', 'levels' => array(
|
||||
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
|
||||
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
|
||||
)
|
||||
array(
|
||||
'type' => 'multilevel',
|
||||
'levels' => array(
|
||||
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
|
||||
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
|
||||
),
|
||||
)
|
||||
);
|
||||
$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
|
||||
|
||||
// Lists
|
||||
|
||||
$section->addText('Multilevel list.');
|
||||
$section->addListItem('List Item I', 0, null, 'multilevel');
|
||||
$section->addListItem('List Item I.a', 1, null, 'multilevel');
|
||||
$section->addListItem('List Item I.b', 1, null, 'multilevel');
|
||||
$section->addListItem('List Item II', 0, null, 'multilevel');
|
||||
$section->addListItem('List Item II.a', 1, null, 'multilevel');
|
||||
$section->addListItem('List Item III', 0, null, 'multilevel');
|
||||
$section->addText(htmlspecialchars('Multilevel list.'));
|
||||
$section->addListItem(htmlspecialchars('List Item I'), 0, null, 'multilevel');
|
||||
$section->addListItem(htmlspecialchars('List Item I.a'), 1, null, 'multilevel');
|
||||
$section->addListItem(htmlspecialchars('List Item I.b'), 1, null, 'multilevel');
|
||||
$section->addListItem(htmlspecialchars('List Item II'), 0, null, 'multilevel');
|
||||
$section->addListItem(htmlspecialchars('List Item II.a'), 1, null, 'multilevel');
|
||||
$section->addListItem(htmlspecialchars('List Item III'), 0, null, 'multilevel');
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addText('Basic simple bulleted list.');
|
||||
$section->addListItem('List Item 1');
|
||||
$section->addListItem('List Item 2');
|
||||
$section->addListItem('List Item 3');
|
||||
$section->addText(htmlspecialchars('Basic simple bulleted list.'));
|
||||
$section->addListItem(htmlspecialchars('List Item 1'));
|
||||
$section->addListItem(htmlspecialchars('List Item 2'));
|
||||
$section->addListItem(htmlspecialchars('List Item 3'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addText('Continue from multilevel list above.');
|
||||
$section->addListItem('List Item IV', 0, null, 'multilevel');
|
||||
$section->addListItem('List Item IV.a', 1, null, 'multilevel');
|
||||
$section->addText(htmlspecialchars('Continue from multilevel list above.'));
|
||||
$section->addListItem(htmlspecialchars('List Item IV'), 0, null, 'multilevel');
|
||||
$section->addListItem(htmlspecialchars('List Item IV.a'), 1, null, 'multilevel');
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addText('Multilevel predefined list.');
|
||||
$section->addListItem('List Item 1', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem('List Item 2', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem('List Item 3', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem('List Item 4', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem('List Item 5', 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem('List Item 6', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem('List Item 7', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addText(htmlspecialchars('Multilevel predefined list.'));
|
||||
$section->addListItem(htmlspecialchars('List Item 1'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem(htmlspecialchars('List Item 2'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem(htmlspecialchars('List Item 3'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem(htmlspecialchars('List Item 4'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem(htmlspecialchars('List Item 5'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem(htmlspecialchars('List Item 6'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addListItem(htmlspecialchars('List Item 7'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addText('List with inline formatting.');
|
||||
$section->addText(htmlspecialchars('List with inline formatting.'));
|
||||
$listItemRun = $section->addListItemRun();
|
||||
$listItemRun->addText('List item 1');
|
||||
$listItemRun->addText(' in bold', array('bold'=>true));
|
||||
$listItemRun->addText(htmlspecialchars('List item 1'));
|
||||
$listItemRun->addText(htmlspecialchars(' in bold'), array('bold' => true));
|
||||
$listItemRun = $section->addListItemRun();
|
||||
$listItemRun->addText('List item 2');
|
||||
$listItemRun->addText(' in italic', array('italic'=>true));
|
||||
$listItemRun->addText(htmlspecialchars('List item 2'));
|
||||
$listItemRun->addText(htmlspecialchars(' in italic'), array('italic' => true));
|
||||
$listItemRun = $section->addListItemRun();
|
||||
$listItemRun->addText('List item 3');
|
||||
$listItemRun->addText(' underlined', array('underline'=>'dash'));
|
||||
$listItemRun->addText(htmlspecialchars('List item 3'));
|
||||
$listItemRun->addText(htmlspecialchars(' underlined'), array('underline' => 'dash'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
// Numbered heading
|
||||
|
||||
$phpWord->addNumberingStyle(
|
||||
'headingNumbering',
|
||||
array('type' => 'multilevel', 'levels' => array(
|
||||
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
||||
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
|
||||
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
|
||||
)
|
||||
array('type' => 'multilevel',
|
||||
'levels' => array(
|
||||
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
||||
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
|
||||
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
|
||||
),
|
||||
)
|
||||
);
|
||||
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0));
|
||||
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
|
||||
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
|
||||
|
||||
$section->addTitle('Heading 1', 1);
|
||||
$section->addTitle('Heading 2', 2);
|
||||
$section->addTitle('Heading 3', 3);
|
||||
$section->addTitle(htmlspecialchars('Heading 1'), 1);
|
||||
$section->addTitle(htmlspecialchars('Heading 2'), 2);
|
||||
$section->addTitle(htmlspecialchars('Heading 3'), 3);
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,17 +2,21 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
// Add hyperlink elements
|
||||
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
||||
$section->addLink(
|
||||
'http://www.google.com',
|
||||
htmlspecialchars('Best search engine'),
|
||||
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
||||
);
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$phpWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'));
|
||||
$phpWord->addLinkStyle('myOwnLinkStyle', array('bold' => true, 'color' => '808000'));
|
||||
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
|
||||
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('You can open this OLE object by double clicking on the icon:');
|
||||
$section->addText(htmlspecialchars('You can open this OLE object by double clicking on the icon:'));
|
||||
$section->addTextBreak(2);
|
||||
$section->addObject('resources/_sheet.xls');
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
|
|
@ -19,7 +19,7 @@ $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
|
|||
$phpWord->addTitleStyle(4, array('size' => 12));
|
||||
|
||||
// Add text elements
|
||||
$section->addText('Table of contents 1');
|
||||
$section->addText(htmlspecialchars('Table of contents 1'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
// Add TOC #1
|
||||
|
|
@ -27,11 +27,11 @@ $toc = $section->addTOC($fontStyle);
|
|||
$section->addTextBreak(2);
|
||||
|
||||
// Filler
|
||||
$section->addText('Text between TOC');
|
||||
$section->addText(htmlspecialchars('Text between TOC'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
// Add TOC #1
|
||||
$section->addText('Table of contents 2');
|
||||
$section->addText(htmlspecialchars('Table of contents 2'));
|
||||
$section->addTextBreak(2);
|
||||
$toc2 = $section->addTOC($fontStyle2);
|
||||
$toc2->setMinDepth(2);
|
||||
|
|
@ -40,33 +40,33 @@ $toc2->setMaxDepth(3);
|
|||
|
||||
// Add Titles
|
||||
$section->addPageBreak();
|
||||
$section->addTitle('I am Title 1', 1);
|
||||
$section->addText('Some text...');
|
||||
$section->addTitle(htmlspecialchars('Foo & Bar'), 1);
|
||||
$section->addText(htmlspecialchars('Some text...'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addTitle('I am a Subtitle of Title 1', 2);
|
||||
$section->addTitle(htmlspecialchars('I am a Subtitle of Title 1'), 2);
|
||||
$section->addTextBreak(2);
|
||||
$section->addText('Some more text...');
|
||||
$section->addText(htmlspecialchars('Some more text...'));
|
||||
$section->addTextBreak(2);
|
||||
|
||||
$section->addTitle('Another Title (Title 2)', 1);
|
||||
$section->addText('Some text...');
|
||||
$section->addTitle(htmlspecialchars('Another Title (Title 2)'), 1);
|
||||
$section->addText(htmlspecialchars('Some text...'));
|
||||
$section->addPageBreak();
|
||||
$section->addTitle('I am Title 3', 1);
|
||||
$section->addText('And more text...');
|
||||
$section->addTitle(htmlspecialchars('I am Title 3'), 1);
|
||||
$section->addText(htmlspecialchars('And more text...'));
|
||||
$section->addTextBreak(2);
|
||||
$section->addTitle('I am a Subtitle of Title 3', 2);
|
||||
$section->addText('Again and again, more text...');
|
||||
$section->addTitle('Subtitle 3.1.1', 3);
|
||||
$section->addText('Text');
|
||||
$section->addTitle('Subtitle 3.1.1.1', 4);
|
||||
$section->addText('Text');
|
||||
$section->addTitle('Subtitle 3.1.1.2', 4);
|
||||
$section->addText('Text');
|
||||
$section->addTitle('Subtitle 3.1.2', 3);
|
||||
$section->addText('Text');
|
||||
$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3'), 2);
|
||||
$section->addText(htmlspecialchars('Again and again, more text...'));
|
||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.1'), 3);
|
||||
$section->addText(htmlspecialchars('Text'));
|
||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1'), 4);
|
||||
$section->addText(htmlspecialchars('Text'));
|
||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2'), 4);
|
||||
$section->addText(htmlspecialchars('Text'));
|
||||
$section->addTitle(htmlspecialchars('Subtitle 3.1.2'), 3);
|
||||
$section->addText(htmlspecialchars('Text'));
|
||||
|
||||
echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL;
|
||||
echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL;
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
|
|
@ -10,7 +10,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|||
$section = $phpWord->addSection();
|
||||
$header = $section->addHeader();
|
||||
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
|
||||
$section->addText('The header reference to the current section includes a watermark image.');
|
||||
$section->addText(htmlspecialchars('The header reference to the current section includes a watermark image.'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
|
|
@ -13,17 +13,17 @@ $phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
|
|||
$fontStyle = array('size' => 24);
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('Text break with no style:');
|
||||
$section->addText(htmlspecialchars('Text break with no style:'));
|
||||
$section->addTextBreak();
|
||||
$section->addText('Text break with defined font style:');
|
||||
$section->addText(htmlspecialchars('Text break with defined font style:'));
|
||||
$section->addTextBreak(1, 'fontStyle');
|
||||
$section->addText('Text break with defined paragraph style:');
|
||||
$section->addText(htmlspecialchars('Text break with defined paragraph style:'));
|
||||
$section->addTextBreak(1, null, 'paragraphStyle');
|
||||
$section->addText('Text break with inline font style:');
|
||||
$section->addText(htmlspecialchars('Text break with inline font style:'));
|
||||
$section->addTextBreak(1, $fontStyle);
|
||||
$section->addText('Text break with inline paragraph style:');
|
||||
$section->addText(htmlspecialchars('Text break with inline paragraph style:'));
|
||||
$section->addTextBreak(1, null, $paragraphStyle);
|
||||
$section->addText('Done.');
|
||||
$section->addText(htmlspecialchars('Done.'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,13 +2,19 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$section->addText("This is some text highlighted using fgColor (limited to 15 colors) ", array("fgColor" => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW));
|
||||
$section->addText("This one uses bgColor and is using hex value (0xfbbb10)", array("bgColor" => "fbbb10"));
|
||||
$section->addText("Compatible with font colors", array("color"=>"0000ff", "bgColor" => "fbbb10"));
|
||||
$section->addText(
|
||||
htmlspecialchars('This is some text highlighted using fgColor (limited to 15 colors) '),
|
||||
array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW)
|
||||
);
|
||||
$section->addText(
|
||||
htmlspecialchars('This one uses bgColor and is using hex value (0xfbbb10)'),
|
||||
array('bgColor' => 'fbbb10')
|
||||
);
|
||||
$section->addText(htmlspecialchars('Compatible with font colors'), array('color' => '0000ff', 'bgColor' => 'fbbb10'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,30 +2,50 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$section->addText("By default, when you insert an image, it adds a textbreak after its content.");
|
||||
$section->addText("If we want a simple border around an image, we wrap the image inside a table->row->cell");
|
||||
$section->addText("On the image with the red border, even if we set the row height to the height of the image, the textbreak is still there:");
|
||||
$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.'));
|
||||
$section->addText(
|
||||
htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell')
|
||||
);
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
'On the image with the red border, even if we set the row height to the height of the image, '
|
||||
. 'the textbreak is still there:'
|
||||
)
|
||||
);
|
||||
|
||||
$table1 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
|
||||
$table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0));
|
||||
$table1->addRow(3750);
|
||||
$cell1 = $table1->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "ff0000"));
|
||||
$cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
|
||||
$cell1 = $table1->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => 'ff0000'));
|
||||
$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'align' => 'center'));
|
||||
|
||||
$section->addTextBreak();
|
||||
$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:");
|
||||
$section->addText(
|
||||
htmlspecialchars(
|
||||
"But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:"
|
||||
)
|
||||
);
|
||||
|
||||
$table2 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
|
||||
$table2->addRow(3750, array("exactHeight" => true));
|
||||
$cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00"));
|
||||
$cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
|
||||
$table2 = $section->addTable(
|
||||
array(
|
||||
'cellMargin' => 0,
|
||||
'cellMarginRight' => 0,
|
||||
'cellMarginBottom' => 0,
|
||||
'cellMarginLeft' => 0,
|
||||
)
|
||||
);
|
||||
$table2->addRow(3750, array('exactHeight' => true));
|
||||
$cell2 = $table2->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => '00ff00'));
|
||||
$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'align' => 'center'));
|
||||
|
||||
$section->addTextBreak();
|
||||
$section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.");
|
||||
$section->addText("So: $"."table2->addRow(3750, array('exactHeight'=>true));");
|
||||
$section->addText(
|
||||
htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.')
|
||||
);
|
||||
$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));"));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
$section->addText('Check box in section');
|
||||
$section->addCheckBox('chkBox1', 'Checkbox 1');
|
||||
$section->addText('Check box in table cell');
|
||||
$section->addText(htmlspecialchars('Check box in section'));
|
||||
$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1'));
|
||||
$section->addText(htmlspecialchars('Check box in table cell'));
|
||||
$table = $section->addTable();
|
||||
$table->addRow();
|
||||
$cell = $table->addCell();
|
||||
$cell->addCheckBox('chkBox2', 'Checkbox 2');
|
||||
$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,35 +2,43 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word Document
|
||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
// In section
|
||||
$textbox = $section->addTextBox(array('align' => 'center', 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000'));
|
||||
$textbox->addText('Text box content in section.');
|
||||
$textbox->addText('Another line.');
|
||||
$textbox = $section->addTextBox(
|
||||
array(
|
||||
'align' => 'center',
|
||||
'width' => 400,
|
||||
'height' => 150,
|
||||
'borderSize' => 1,
|
||||
'borderColor' => '#FF0000',
|
||||
)
|
||||
);
|
||||
$textbox->addText(htmlspecialchars('Text box content in section.'));
|
||||
$textbox->addText(htmlspecialchars('Another line.'));
|
||||
$cell = $textbox->addTable()->addRow()->addCell();
|
||||
$cell->addText('Table inside textbox');
|
||||
$cell->addText(htmlspecialchars('Table inside textbox'));
|
||||
|
||||
// Inside table
|
||||
$section->addTextBreak(2);
|
||||
$cell = $section->addTable()->addRow()->addCell(300);
|
||||
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
|
||||
$textbox->addText('Textbox inside table');
|
||||
$textbox->addText(htmlspecialchars('Textbox inside table'));
|
||||
|
||||
// Inside header with textrun
|
||||
$header = $section->addHeader();
|
||||
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
||||
$textrun = $textbox->addTextRun();
|
||||
$textrun->addText('TextBox in header. TextBox can contain a TextRun ');
|
||||
$textrun->addText('with bold text', array('bold' => true));
|
||||
$textrun->addText(', ');
|
||||
$textrun->addLink('http://www.google.com', 'link');
|
||||
$textrun->addText(', and image ');
|
||||
$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun '));
|
||||
$textrun->addText(htmlspecialchars('with bold text'), array('bold' => true));
|
||||
$textrun->addText(htmlspecialchars(', '));
|
||||
$textrun->addLink('http://www.google.com', htmlspecialchars('link'));
|
||||
$textrun->addText(htmlspecialchars(', and image '));
|
||||
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||
$textrun->addText('.');
|
||||
$textrun->addText(htmlspecialchars('.'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -20,4 +20,4 @@ $html .= '<ol><li>Item 1</li><li>Item 2</li></ol>';
|
|||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
if (!CLI) {
|
||||
include_once 'Sample_Footer.php';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
|
|
@ -10,19 +10,19 @@ $section = $phpWord->addSection();
|
|||
|
||||
// Add Field elements
|
||||
// See Element/Field.php for all options
|
||||
$section->addText('Date field:');
|
||||
$section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
|
||||
$section->addText(htmlspecialchars('Date field:'));
|
||||
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
|
||||
|
||||
$section->addText('Page field:');
|
||||
$section->addField('PAGE', array('format'=>'ArabicDash'));
|
||||
$section->addText(htmlspecialchars('Page field:'));
|
||||
$section->addField('PAGE', array('format' => 'ArabicDash'));
|
||||
|
||||
$section->addText('Number of pages field:');
|
||||
$section->addField('NUMPAGES', array('format'=>'Arabic', 'numformat'=>'0,00'), array('PreserveFormat'));
|
||||
$section->addText(htmlspecialchars('Number of pages field:'));
|
||||
$section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
|
||||
|
||||
$textrun = $section->addTextRun(array('align' => 'center'));
|
||||
$textrun->addText('This is the date of lunar calendar ');
|
||||
$textrun->addField('DATE', array('dateformat'=>'d-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
|
||||
$textrun->addText(' written in a textrun.');
|
||||
$textrun->addText(htmlspecialchars('This is the date of lunar calendar '));
|
||||
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
|
||||
$textrun->addText(htmlspecialchars(' written in a textrun.'));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
// Begin code
|
||||
|
|
@ -10,50 +10,50 @@ $section = $phpWord->addSection();
|
|||
|
||||
// Add Line elements
|
||||
// See Element/Line.php for all options
|
||||
$section->addText('Horizontal Line (Inline style):');
|
||||
$section->addText(htmlspecialchars('Horizontal Line (Inline style):'));
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||
'positioning' => 'absolute'
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||
'positioning' => 'absolute',
|
||||
)
|
||||
);
|
||||
$section->addText('Vertical Line (Inline style):');
|
||||
$section->addText(htmlspecialchars('Vertical Line (Inline style):'));
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
|
||||
'positioning' => 'absolute'
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
|
||||
'positioning' => 'absolute',
|
||||
)
|
||||
);
|
||||
// Two text break
|
||||
$section->addTextBreak(1);
|
||||
|
||||
$section->addText('Positioned Line (red):');
|
||||
$section->addText(htmlspecialchars('Positioned Line (red):'));
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
|
||||
'positioning' => 'absolute',
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
|
||||
'positioning' => 'absolute',
|
||||
'posHorizontalRel' => 'page',
|
||||
'posVerticalRel' => 'page',
|
||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(10),
|
||||
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(8),
|
||||
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
|
||||
'color' => 'red'
|
||||
'posVerticalRel' => 'page',
|
||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(10),
|
||||
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(8),
|
||||
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
|
||||
'color' => 'red',
|
||||
)
|
||||
);
|
||||
|
||||
$section->addText('Horizontal Formatted Line');
|
||||
$section->addText(htmlspecialchars('Horizontal Formatted Line'));
|
||||
$section->addLine(
|
||||
array(
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15),
|
||||
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||
'positioning' => 'absolute',
|
||||
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
|
||||
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
|
||||
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
|
||||
'weight' => 10
|
||||
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
|
||||
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
|
||||
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
|
||||
'weight' => 10,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true));
|
||||
|
|
@ -10,67 +10,80 @@ $phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true));
|
|||
$section = $phpWord->addSection();
|
||||
|
||||
// Arc
|
||||
$section->addTitle('Arc', 1);
|
||||
$section->addTitle(htmlspecialchars('Arc'), 1);
|
||||
$section->addShape(
|
||||
'arc',
|
||||
array(
|
||||
'points' => '-90 20',
|
||||
'frame' => array('width' => 120, 'height' => 120),
|
||||
'points' => '-90 20',
|
||||
'frame' => array('width' => 120, 'height' => 120),
|
||||
'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'),
|
||||
)
|
||||
);
|
||||
|
||||
// Curve
|
||||
$section->addTitle('Curve', 1);
|
||||
$section->addTitle(htmlspecialchars('Curve'), 1);
|
||||
$section->addShape(
|
||||
'curve',
|
||||
array(
|
||||
'points' => '1,100 200,1 1,50 200,50', 'connector' => 'elbow',
|
||||
'outline' => array('color' => '#66cc00', 'weight' => 2, 'dash' => 'dash', 'startArrow' => 'diamond', 'endArrow' => 'block'),
|
||||
'points' => '1,100 200,1 1,50 200,50',
|
||||
'connector' => 'elbow',
|
||||
'outline' => array(
|
||||
'color' => '#66cc00',
|
||||
'weight' => 2,
|
||||
'dash' => 'dash',
|
||||
'startArrow' => 'diamond',
|
||||
'endArrow' => 'block',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Line
|
||||
$section->addTitle('Line', 1);
|
||||
$section->addTitle(htmlspecialchars('Line'), 1);
|
||||
$section->addShape(
|
||||
'line',
|
||||
array(
|
||||
'points' => '1,1 150,30',
|
||||
'outline' => array('color' => '#cc00ff', 'line' => 'thickThin', 'weight' => 3, 'startArrow' => 'oval', 'endArrow' => 'classic'),
|
||||
'points' => '1,1 150,30',
|
||||
'outline' => array(
|
||||
'color' => '#cc00ff',
|
||||
'line' => 'thickThin',
|
||||
'weight' => 3,
|
||||
'startArrow' => 'oval',
|
||||
'endArrow' => 'classic',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Polyline
|
||||
$section->addTitle('Polyline', 1);
|
||||
$section->addTitle(htmlspecialchars('Polyline'), 1);
|
||||
$section->addShape(
|
||||
'polyline',
|
||||
array(
|
||||
'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50',
|
||||
'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50',
|
||||
'outline' => array('color' => '#cc6666', 'weight' => 2, 'startArrow' => 'none', 'endArrow' => 'classic'),
|
||||
)
|
||||
);
|
||||
|
||||
// Rectangle
|
||||
$section->addTitle('Rectangle', 1);
|
||||
$section->addTitle(htmlspecialchars('Rectangle'), 1);
|
||||
$section->addShape(
|
||||
'rect',
|
||||
array(
|
||||
'roundness' => 0.2,
|
||||
'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1),
|
||||
'fill' => array('color' => '#FFCC33'),
|
||||
'outline' => array('color' => '#990000', 'weight' => 1),
|
||||
'shadow' => array(),
|
||||
'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1),
|
||||
'fill' => array('color' => '#FFCC33'),
|
||||
'outline' => array('color' => '#990000', 'weight' => 1),
|
||||
'shadow' => array(),
|
||||
)
|
||||
);
|
||||
|
||||
// Oval
|
||||
$section->addTitle('Oval', 1);
|
||||
$section->addTitle(htmlspecialchars('Oval'), 1);
|
||||
$section->addShape(
|
||||
'oval',
|
||||
array(
|
||||
'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1),
|
||||
'fill' => array('color' => '#33CC99'),
|
||||
'outline' => array('color' => '#333333', 'weight' => 2),
|
||||
'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1),
|
||||
'fill' => array('color' => '#33CC99'),
|
||||
'outline' => array('color' => '#333333', 'weight' => 2),
|
||||
'extrusion' => array(),
|
||||
)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ include_once 'Sample_Header.php';
|
|||
use PhpOffice\PhpWord\Shared\Converter;
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
|
||||
|
|
@ -12,7 +12,7 @@ $phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext'
|
|||
|
||||
// 2D charts
|
||||
$section = $phpWord->addSection();
|
||||
$section->addTitle('2D charts', 1);
|
||||
$section->addTitle(htmlspecialchars('2D charts'), 1);
|
||||
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
||||
|
||||
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
|
||||
|
|
@ -26,9 +26,7 @@ $series3 = array(8, 3, 2, 5, 4);
|
|||
foreach ($chartTypes as $chartType) {
|
||||
$section->addTitle(ucfirst($chartType), 2);
|
||||
$chart = $section->addChart($chartType, $categories, $series1);
|
||||
$chart->getStyle()
|
||||
->setWidth(Converter::inchToEmu(2.5))
|
||||
->setHeight(Converter::inchToEmu(2));
|
||||
$chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
|
||||
if (in_array($chartType, $twoSeries)) {
|
||||
$chart->addSeries($categories, $series2);
|
||||
}
|
||||
|
|
@ -40,7 +38,7 @@ foreach ($chartTypes as $chartType) {
|
|||
|
||||
// 3D charts
|
||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||
$section->addTitle('3D charts', 1);
|
||||
$section->addTitle(htmlspecialchars('3D charts'), 1);
|
||||
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
||||
|
||||
$chartTypes = array('pie', 'bar', 'column', 'line', 'area');
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
$phpWord->getProtection()->setEditing('forms');
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('Form fields can be added in a text run and can be in form of textinput ');
|
||||
$textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput '));
|
||||
$textrun->addFormField('textinput')->setName('MyTextBox');
|
||||
$textrun->addText(', checkbox ');
|
||||
$textrun->addText(htmlspecialchars(', checkbox '));
|
||||
$textrun->addFormField('checkbox')->setDefault(true);
|
||||
$textrun->addText(', or dropdown ');
|
||||
$textrun->addText(htmlspecialchars(', or dropdown '));
|
||||
$textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3'));
|
||||
$textrun->addText('. You have to set document protection to "forms" to enable dropdown.');
|
||||
$textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.'));
|
||||
|
||||
$section->addText('They can also be added as a stand alone paragraph.');
|
||||
$section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.'));
|
||||
$section->addFormField('textinput')->setValue('Your name');
|
||||
|
||||
// Save file
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('Combobox: ');
|
||||
$textrun->addText(htmlspecialchars('Combobox: '));
|
||||
$textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
||||
|
||||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('Date: ');
|
||||
$textrun->addText(htmlspecialchars('Date: '));
|
||||
$textrun->addSDT('date');
|
||||
|
||||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('Drop down list: ');
|
||||
$textrun->addText(htmlspecialchars('Drop down list: '));
|
||||
$textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
||||
|
||||
// Save file
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
$section->addTitle( 'This is page 1', 1 );
|
||||
$section->addTitle(htmlspecialchars('This is page 1'), 1);
|
||||
$linkIsInternal = true;
|
||||
$section->addLink('MyBookmark', 'Take me to page 3', null ,null,$linkIsInternal);
|
||||
$section->addLink('MyBookmark', htmlspecialchars('Take me to page 3'), null, null, $linkIsInternal);
|
||||
$section->addPageBreak();
|
||||
$section->addTitle( 'This is page 2', 1 );
|
||||
$section->addTitle(htmlspecialchars('This is page 2'), 1);
|
||||
$section->addPageBreak();
|
||||
$section->addTitle( 'This is page 3', 1 );
|
||||
$section->addTitle(htmlspecialchars('This is page 3'), 1);
|
||||
$section->addBookmark('MyBookmark');
|
||||
|
||||
// Save file
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
include_once 'Sample_Header.php';
|
||||
|
||||
// New Word document
|
||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
||||
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
|
||||
$section = $phpWord->addSection();
|
||||
$textrun = $section->addTextRun();
|
||||
$textrun->addText('This is a Left to Right paragraph.');
|
||||
$textrun->addText(htmlspecialchars('This is a Left to Right paragraph.'));
|
||||
|
||||
$textrun = $section->addTextRun(array('align' => 'right'));
|
||||
$textrun->addText('سلام این یک پاراگراف راست به چپ است', array('rtl' => true));
|
||||
$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است'), array('rtl' => true));
|
||||
|
||||
// Save file
|
||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||
|
|
|
|||
Loading…
Reference in New Issue