Skip to content

Commit eb7f0a3

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into #189-pyreweb
2 parents a84171d + 61885e0 commit eb7f0a3

File tree

16 files changed

+135
-20
lines changed

16 files changed

+135
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
1515
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
1616
- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin GH-106 GH-140 GH-185
1717
- Template: Ability to find & replace variables in headers & footers - @dgudgeon GH-190
18+
- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira GH-191
1819

1920
### Bugfixes
2021

docs/templates.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Example:
1919
$template->setValue('Name', 'Somebody someone');
2020
$template->setValue('Street', 'Coming-Undone-Street 32');
2121
22-
See ``Sample_07_TemplateCloneRow.php`` for more code sample, including
23-
how to create multirow from a single row in a template by using
24-
``cloneRow``.
22+
See ``Sample_07_TemplateCloneRow.php`` for example on how to create multirow
23+
from a single row in a template by using ``cloneRow``.
24+
25+
See ``Sample_23_TemplateBlock.php`` for example on how to clone a block of
26+
text using ``cloneBlock`` and delete a block of text using ``deleteBlock``.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
include_once 'Sample_Header.php';
3+
4+
// New Word document
5+
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
6+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
7+
8+
$document = $phpWord->loadTemplate('resources/Sample_23_TemplateBlock.docx');
9+
10+
// Will clone everything between ${tag} and ${/tag}, the number of times. By default, 1.
11+
$document->cloneBlock('CLONEME', 3);
12+
13+
// Everything between ${tag} and ${/tag}, will be deleted/erased.
14+
$document->deleteBlock('DELETEME');
15+
16+
$name = 'Sample_23_TemplateBlock.docx';
17+
echo date('H:i:s'), " Write to Word2007 format", EOL;
18+
$document->saveAs($name);
19+
rename($name, "results/{$name}");
20+
21+
include_once 'Sample_Footer.php';
22 KB
Binary file not shown.

src/PhpWord/PhpWord.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function getSections()
232232
*/
233233
public function loadTemplate($filename)
234234
{
235-
if (\file_exists($filename)) {
235+
if (file_exists($filename)) {
236236
return new Template($filename);
237237
} else {
238238
throw new Exception("Template file {$filename} not found.");

src/PhpWord/Reader/Reader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function setReadDataOnly($pValue = true)
6565
protected function openFile($pFilename)
6666
{
6767
// Check if file exists
68-
if (!\file_exists($pFilename) || !is_readable($pFilename)) {
68+
if (!file_exists($pFilename) || !is_readable($pFilename)) {
6969
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
7070
}
7171

src/PhpWord/Reader/Word2007.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Word2007 extends Reader implements IReader
2929
public function canRead($pFilename)
3030
{
3131
// Check if file exists
32-
if (!\file_exists($pFilename)) {
32+
if (!file_exists($pFilename)) {
3333
throw new Exception("Could not open {$pFilename} for reading! File does not exist.");
3434
}
3535

src/PhpWord/Section/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function __construct($source, $style = null, $isWatermark = false)
112112
\IMAGETYPE_PNG, \IMAGETYPE_BMP,
113113
\IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM
114114
);
115-
if (!\file_exists($source)) {
115+
if (!file_exists($source)) {
116116
throw new InvalidImageException;
117117
}
118118
$imgData = getimagesize($source);

src/PhpWord/Section/Object.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct($src, $style = null)
6161
$_supportedObjectTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
6262
$inf = pathinfo($src);
6363

64-
if (\file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
64+
if (file_exists($src) && in_array($inf['extension'], $_supportedObjectTypes)) {
6565
$this->_src = $src;
6666
$this->_style = new \PhpOffice\PhpWord\Style\Image();
6767

src/PhpWord/Section/Table/Cell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function addObject($src, $style = null)
234234
}
235235

236236
$iconSrc = __DIR__ . '/../../_staticDocParts/';
237-
if (!\file_exists($iconSrc . '_' . $ext . '.png')) {
237+
if (!file_exists($iconSrc . '_' . $ext . '.png')) {
238238
$iconSrc = $iconSrc . '_default.png';
239239
} else {
240240
$iconSrc .= '_' . $ext . '.png';

0 commit comments

Comments
 (0)