Skip to content

Commit 3055a0e

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into #160-refactoring
2 parents 8aba90d + 2d7126e commit 3055a0e

File tree

9 files changed

+93
-146
lines changed

9 files changed

+93
-146
lines changed

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,73 @@ With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your
2929
* Use XSL 1.0 style sheets to transform main document part of OOXML template
3030
* ... and many more features on progress
3131

32+
## Requirements
33+
* PHP 5.3+
34+
* PHP [Zip](http://php.net/manual/en/book.zip.php) extension
35+
* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension
36+
37+
### Optional PHP extensions
38+
* PHP [GD](http://php.net/manual/en/book.image.php) extension
39+
* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension
40+
* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension
41+
42+
## Installation
43+
44+
It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add
45+
the following lines to your ``composer.json``.
46+
47+
```json
48+
{
49+
"require": {
50+
"phpoffice/phpword": "dev-master"
51+
}
52+
}
53+
```
54+
55+
## Basic usage
56+
57+
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
58+
59+
```php
60+
$PHPWord = new PHPWord();
61+
62+
// Every element you want to append to the word document is placed in a section.
63+
// To create a basic section:
64+
$section = $PHPWord->createSection();
65+
66+
// After creating a section, you can append elements:
67+
$section->addText('Hello world!');
68+
69+
// You can directly style your text by giving the addText function an array:
70+
$section->addText('Hello world! I am formatted.',
71+
array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
72+
73+
// If you often need the same style again you can create a user defined style
74+
// to the word document and give the addText function the name of the style:
75+
$PHPWord->addFontStyle('myOwnStyle',
76+
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
77+
$section->addText('Hello world! I am formatted by a user defined style',
78+
'myOwnStyle');
79+
80+
// You can also put the appended element to local object like this:
81+
$fontStyle = new PHPWord_Style_Font();
82+
$fontStyle->setBold(true);
83+
$fontStyle->setName('Verdana');
84+
$fontStyle->setSize(22);
85+
$myTextElement = $section->addText('Hello World!');
86+
$myTextElement->setFontStyle($fontStyle);
87+
88+
// Finally, write the document:
89+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
90+
$objWriter->save('helloWorld.docx');
91+
92+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText');
93+
$objWriter->save('helloWorld.odt');
94+
95+
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF');
96+
$objWriter->save('helloWorld.rtf');
97+
```
98+
3299
__Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us.
33100

34101
__Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/en/develop/).
35-

src/PhpWord/Reader/Word2007.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use PhpOffice\PhpWord\PhpWord;
2929
use PhpOffice\PhpWord\DocumentProperties;
3030
use PhpOffice\PhpWord\Exceptions\Exception;
31-
use PhpOffice\PhpWord\Shared\File;
3231

3332
/**
3433
* Reader for Word2007
@@ -84,10 +83,10 @@ public function canRead($pFilename)
8483
public function getFromZipArchive($archive, $fileName = '', $removeNamespace = false)
8584
{
8685
// Root-relative paths
87-
if (strpos($fileName, '//') !== false) {
88-
$fileName = substr($fileName, strpos($fileName, '//') + 1);
89-
}
90-
$fileName = File::realpath($fileName);
86+
// if (strpos($fileName, '//') !== false) {
87+
// $fileName = substr($fileName, strpos($fileName, '//') + 1);
88+
// }
89+
// $fileName = realpath($fileName);
9190

9291
// Apache POI fixes
9392
$contents = $archive->getFromName($fileName);

src/PhpWord/Shared/File.php

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/PhpWord/Writer/ODText/Manifest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
use PhpOffice\PhpWord\Exceptions\Exception;
2929
use PhpOffice\PhpWord\PhpWord;
30-
use PhpOffice\PhpWord\Shared\File;
3130
use PhpOffice\PhpWord\Shared\XMLWriter;
3231

3332
/**
@@ -123,7 +122,7 @@ public function writeManifest(PhpWord $phpWord = null)
123122
*/
124123
private function _getImageMimeType($pFile = '')
125124
{
126-
if (File::fileExists($pFile)) {
125+
if (file_exists($pFile)) {
127126
$image = getimagesize($pFile);
128127
return image_type_to_mime_type($image[2]);
129128
} else {

src/PhpWord/Writer/Word2007/ContentTypes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
namespace PhpOffice\PhpWord\Writer\Word2007;
2727

2828
use PhpOffice\PhpWord\Exceptions\Exception;
29-
use PhpOffice\PhpWord\Shared\File;
3029
use PhpOffice\PhpWord\Shared\XMLWriter;
3130

3231
/**
@@ -189,7 +188,7 @@ public function writeContentTypes($_imageTypes, $_objectTypes, $_cHdrs, $footers
189188
*/
190189
private function _getImageMimeType($pFile = '')
191190
{
192-
if (File::fileExists($pFile)) {
191+
if (file_exists($pFile)) {
193192
$image = getimagesize($pFile);
194193
return image_type_to_mime_type($image[2]);
195194
} else {

tests/PhpWord/Tests/PhpWordTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function testLoadTemplateException()
147147
{
148148
$templateFqfn = \join(
149149
\DIRECTORY_SEPARATOR,
150-
array(\PHPWORD_TESTS_BASE_DIR, 'data', 'templates', 'blanks.docx')
150+
array(\PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', 'data', 'templates', 'blanks.docx')
151151
);
152152
$phpWord = new PhpWord();
153153
$phpWord->loadTemplate($templateFqfn);

tests/PhpWord/Tests/Reader/Word2007Test.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,35 @@ public function tearDown()
1818
*/
1919
public function testCanRead()
2020
{
21-
$dir = __DIR__ . "/../_files/documents";
22-
$object = new Word2007;
23-
$file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx';
24-
$this->assertTrue($object->canRead($file));
21+
$object = new Word2007();
22+
$fqFilename = join(
23+
DIRECTORY_SEPARATOR,
24+
array(PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', '_files', 'documents', 'reader.docx')
25+
);
26+
$this->assertTrue($object->canRead($fqFilename));
2527
}
2628

2729
/**
2830
* @expectedException \PhpOffice\PhpWord\Exceptions\Exception
2931
*/
3032
public function testCanReadFailed()
3133
{
32-
$dir = __DIR__ . "/../_files/documents";
33-
$object = new Word2007;
34-
$file = $dir . \DIRECTORY_SEPARATOR . 'foo.docx';
35-
$this->assertFalse($object->canRead($file));
36-
$object = IOFactory::load($file);
34+
$object = new Word2007();
35+
$fqFilename = join(
36+
DIRECTORY_SEPARATOR,
37+
array(PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', '_files', 'documents', 'foo.docx')
38+
);
39+
$this->assertFalse($object->canRead($fqFilename));
40+
$object = IOFactory::load($fqFilename);
3741
}
3842

39-
/**
40-
* Test load document
41-
*/
4243
public function testLoad()
4344
{
44-
$dir = __DIR__ . "/../_files/documents";
45-
$file = $dir . \DIRECTORY_SEPARATOR . 'reader.docx';
46-
$object = IOFactory::load($file);
45+
$fqFilename = join(
46+
DIRECTORY_SEPARATOR,
47+
array(PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', '_files', 'documents', 'reader.docx')
48+
);
49+
$object = IOFactory::load($fqFilename);
4750
$this->assertInstanceOf('PhpOffice\\PhpWord\\PhpWord', $object);
4851
}
4952
}

tests/PhpWord/Tests/Shared/FileTest.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// defining base dir for tests
55
if (!defined('PHPWORD_TESTS_BASE_DIR')) {
6-
define('PHPWORD_TESTS_BASE_DIR', realpath(__DIR__ . '/..'));
6+
define('PHPWORD_TESTS_BASE_DIR', realpath(__DIR__));
77
}
88

99
$vendor = realpath(__DIR__ . '/../vendor');

0 commit comments

Comments
 (0)