Skip to content

Commit 938d78f

Browse files
committed
Samples: (1) Superscript and subscript; (2) Multicolumn
1 parent f1c2c2f commit 938d78f

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

samples/Sample_04_Textrun.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030

3131
$textrun->addText('Each textrun can contain native text, link elements or an image.');
3232
$textrun->addText(' No break is placed after adding an element.', 'BoldText');
33+
$textrun->addText(' Both ');
34+
$textrun->addText('superscript', array('superScript' => true));
35+
$textrun->addText(' and ');
36+
$textrun->addText('subscript', array('subScript' => true));
37+
$textrun->addText(' are also available.');
3338
$textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText');
3439
$textrun->addText(' Sample Link: ');
3540
$textrun->addLink('http://www.google.com', null, 'NLink');

samples/Sample_05_Multicolumn.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
error_reporting(E_ALL);
4+
5+
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
6+
define('EOL', PHP_EOL);
7+
}
8+
else {
9+
define('EOL', '<br />');
10+
}
11+
12+
require_once '../Classes/PHPWord.php';
13+
14+
// New Word Document
15+
echo date('H:i:s') , " Create new PHPWord object" , EOL;
16+
$PHPWord = new PHPWord();
17+
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
18+
'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' .
19+
'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' .
20+
'Suspendisse congue congue leo sed pellentesque.';
21+
22+
// Normal
23+
$section = $PHPWord->createSection();
24+
$section->addText('Normal paragraph. ' . $filler);
25+
26+
// Two columns
27+
$section = $PHPWord->createSection(array(
28+
'colsNum' => 2,
29+
'colsSpace' => 1440,
30+
'breakType' => 'continuous'));
31+
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
32+
33+
// Normal
34+
$section = $PHPWord->createSection(array('breakType' => 'continuous'));
35+
$section->addText('Normal paragraph again. ' . $filler);
36+
37+
// Three columns
38+
$section = $PHPWord->createSection(array(
39+
'colsNum' => 3,
40+
'colsSpace' => 720,
41+
'breakType' => 'continuous'));
42+
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
43+
44+
// Normal
45+
$section = $PHPWord->createSection(array('breakType' => 'continuous'));
46+
$section->addText('Normal paragraph again.');
47+
48+
// Save File
49+
echo date('H:i:s') , " Write to Word2007 format" , EOL;
50+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
51+
$objWriter->save(str_replace('.php', '.docx', __FILE__));
52+
53+
// echo date('H:i:s') , " Write to OpenDocumentText format" , EOL;
54+
// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText');
55+
// $objWriter->save(str_replace('.php', '.odt', __FILE__));
56+
57+
// echo date('H:i:s') , " Write to RTF format" , EOL;
58+
// $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF');
59+
// $objWriter->save(str_replace('.php', '.rtf', __FILE__));
60+
61+
62+
// Echo memory peak usage
63+
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
64+
65+
// Echo done
66+
echo date('H:i:s') , " Done writing file" , EOL;

0 commit comments

Comments
 (0)