Skip to content

Commit f472bfb

Browse files
authored
Merge branch 'develop' into add_html_table_layout
2 parents b50de97 + 7aef21f commit f472bfb

File tree

12 files changed

+60
-12
lines changed

12 files changed

+60
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ v0.16.0 (xx xxx 2018)
1111
- Fix regex in `cloneBlock` function @nicoder #1269
1212
- HTML Title Writer loses text when Title contains a TextRun instead a string. @begnini #1436
1313
- Adding table layout to the generated HTML @aarangara #1441
14+
- Fix loading of Sharepoint document @Garrcomm #1498
15+
- RTF writer: Round getPageSizeW and getPageSizeH to avoid decimals @Patrick64 #1493
16+
- Fix parsing of Office 365 documents @Timanx #1485
1417

1518
v0.15.0 (14 Jul 2018)
1619
----------------------

docs/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Fixes # (issue)
88

99
- [ ] I have run `composer run-script check --timeout=0` and no errors were reported
1010
- [ ] The new code is covered by unit tests (check build/coverage for coverage report)
11-
- [ ] I have update the documentation to describe the changes
11+
- [ ] I have updated the documentation to describe the changes

docs/styles.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Available Section style options:
2929
- ``marginRight``. Page margin right in *twip*.
3030
- ``marginBottom``. Page margin bottom in *twip*.
3131
- ``orientation``. Page orientation (``portrait``, which is default, or ``landscape``).
32+
See ``\PhpOffice\PhpWord\Style\Section::ORIENTATION_...`` class constants for possible values
3233
- ``pageSizeH``. Page height in *twip*. Implicitly defined by ``orientation`` option. Any changes are discouraged.
3334
- ``pageSizeW``. Page width in *twip*. Implicitly defined by ``orientation`` option. Any changes are discouraged.
3435

@@ -45,7 +46,7 @@ Available Font style options:
4546
- ``color``. Font color, e.g. *FF0000*.
4647
- ``doubleStrikethrough``. Double strikethrough, *true* or *false*.
4748
- ``fgColor``. Font highlight color, e.g. *yellow*, *green*, *blue*.
48-
See ``\PhpOffice\PhpWord\Style\Font::FGCOLOR_...`` constants for more values
49+
See ``\PhpOffice\PhpWord\Style\Font::FGCOLOR_...`` class constants for possible values
4950
- ``hint``. Font content type, *default*, *eastAsia*, or *cs*.
5051
- ``italic``. Italic, *true* or *false*.
5152
- ``name``. Font name, e.g. *Arial*.
@@ -56,7 +57,7 @@ Available Font style options:
5657
- ``subScript``. Subscript, *true* or *false*.
5758
- ``superScript``. Superscript, *true* or *false*.
5859
- ``underline``. Underline, *single*, *dash*, *dotted*, etc.
59-
See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` constants for more values
60+
See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` class constants for possible values
6061
- ``lang``. Language, either a language code like *en-US*, *fr-BE*, etc. or an object (or as an array) if you need to set eastAsian or bidirectional languages
6162
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
6263
- ``position``. The text position, raised or lowered, in half points
@@ -69,7 +70,7 @@ Paragraph
6970
Available Paragraph style options:
7071

7172
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
72-
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
73+
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
7374
- ``basedOn``. Parent style.
7475
- ``hanging``. Hanging in *twip*.
7576
- ``indent``. Indent in *twip*.
@@ -82,14 +83,15 @@ Available Paragraph style options:
8283
- ``spaceAfter``. Space after paragraph in *twip*.
8384
- ``spacing``. Space between lines.
8485
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
86+
See ``\PhpOffice\PhpWord\SimpleType\LineSpacingRule`` class constants for possible values.
8587
- ``suppressAutoHyphens``. Hyphenation for paragraph, *true* or *false*.
8688
- ``tabs``. Set of custom tab stops.
8789
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
8890
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.
8991
- ``bidi``. Right to Left Paragraph Layout, *true* or *false*.
9092
- ``shading``. Paragraph Shading.
9193
- ``textAlignment``. Vertical Character Alignment on Line.
92-
See ``\PhpOffice\PhpWord\SimpleType\TextAlignment`` class for possible values.
94+
See ``\PhpOffice\PhpWord\SimpleType\TextAlignment`` class constants for possible values.
9395

9496
.. _table-style:
9597

@@ -99,7 +101,7 @@ Table
99101
Available Table style options:
100102

101103
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
102-
See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` classes for the details.
104+
See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
103105
- ``bgColor``. Background color, e.g. '9966CC'.
104106
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
105107
- ``border(Top|Right|Bottom|Left)Size``. Border size in *twip*.
@@ -168,7 +170,7 @@ Numbering level
168170
Available NumberingLevel style options:
169171

170172
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
171-
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
173+
See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
172174
- ``font``. Font name.
173175
- ``format``. Numbering format bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter.
174176
- ``hanging``. See paragraph style.

src/PhpWord/Reader/Word2007.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public function load($docFile)
6262
foreach ($steps as $step) {
6363
$stepPart = $step['stepPart'];
6464
$stepItems = $step['stepItems'];
65+
if (!isset($relationships[$stepPart])) {
66+
continue;
67+
}
6568
foreach ($relationships[$stepPart] as $relItem) {
6669
$relType = $relItem['type'];
6770
if (isset($stepItems[$relType])) {

src/PhpWord/Style/Language.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ final class Language extends AbstractStyle
6565
const PT_BR = 'pt-BR';
6666
const PT_BR_ID = 1046;
6767

68+
const NL_NL = 'nl-NL';
69+
const NL_NL_ID = 1043;
70+
6871
/**
6972
* Language ID, used for RTF document generation
7073
*

src/PhpWord/TemplateProcessor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,19 @@ protected function getHeaderName($index)
503503
}
504504

505505
/**
506+
* Usually, the name of main part document will be 'document.xml'. However, some .docx files (possibly those from Office 365, experienced also on documents from Word Online created from blank templates) have file 'document22.xml' in their zip archive instead of 'document.xml'. This method searches content types file to correctly determine the file name.
507+
*
506508
* @return string
507509
*/
508510
protected function getMainPartName()
509511
{
510-
return 'word/document.xml';
512+
$contentTypes = $this->zipClass->getFromName('[Content_Types].xml');
513+
514+
$pattern = '~PartName="\/(word\/document.*?\.xml)" ContentType="application\/vnd\.openxmlformats-officedocument\.wordprocessingml\.document\.main\+xml"~';
515+
516+
preg_match($pattern, $contentTypes, $matches);
517+
518+
return array_key_exists(1, $matches) ? $matches[1] : 'word/document.xml';
511519
}
512520

513521
/**

src/PhpWord/Writer/RTF/Style/Section.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function write()
4343
$content .= '\sectd ';
4444

4545
// Size & margin
46-
$content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . $style->getPageSizeW());
47-
$content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . $style->getPageSizeH());
46+
$content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW()));
47+
$content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH()));
4848
$content .= ' ';
4949
$content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . $style->getMarginTop());
5050
$content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . $style->getMarginRight());

src/PhpWord/Writer/Word2007/Element/Image.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ private function writeWatermark(XMLWriter $xmlWriter, ImageElement $element)
103103
$style->setPositioning('absolute');
104104
$styleWriter = new ImageStyleWriter($xmlWriter, $style);
105105

106-
$xmlWriter->startElement('w:p');
106+
if (!$this->withoutP) {
107+
$xmlWriter->startElement('w:p');
108+
}
107109
$xmlWriter->startElement('w:r');
108110
$xmlWriter->startElement('w:pict');
109111
$xmlWriter->startElement('v:shape');
@@ -118,6 +120,8 @@ private function writeWatermark(XMLWriter $xmlWriter, ImageElement $element)
118120
$xmlWriter->endElement(); // v:shape
119121
$xmlWriter->endElement(); // w:pict
120122
$xmlWriter->endElement(); // w:r
121-
$xmlWriter->endElement(); // w:p
123+
if (!$this->withoutP) {
124+
$xmlWriter->endElement(); // w:p
125+
}
122126
}
123127
}

src/PhpWord/Writer/Word2007/Style/Frame.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function write()
6161
'hPos' => 'mso-position-horizontal',
6262
'vPos' => 'mso-position-vertical',
6363
'hPosRelTo' => 'mso-position-horizontal-relative',
64+
'vPosRelTo' => 'mso-position-vertical-relative',
6465
);
6566
$posStyles = $this->getStyles($style, $properties);
6667

tests/PhpWord/Shared/HtmlTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ public function testParseFullHtml()
8686
$this->assertCount(2, $section->getElements());
8787
}
8888

89+
/**
90+
* Test HTML entities
91+
*/
92+
public function testParseHtmlEntities()
93+
{
94+
\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
95+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
96+
$section = $phpWord->addSection();
97+
Html::addHtml($section, 'text with entities <my text>');
98+
99+
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
100+
$this->assertTrue($doc->elementExists('/w:document/w:body/w:p[1]/w:r/w:t'));
101+
$this->assertEquals('text with entities <my text>', $doc->getElement('/w:document/w:body/w:p[1]/w:r/w:t')->nodeValue);
102+
}
103+
89104
/**
90105
* Test underline
91106
*/

0 commit comments

Comments
 (0)