File tree Expand file tree Collapse file tree 8 files changed +48
-2
lines changed Expand file tree Collapse file tree 8 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,9 @@ This is the last version to support PHP 5.3
1818- Support for Comments - @troosan #1067
1919- Support for paragraph textAlignment - @troosan #1165
2020- Add support for HTML underline tag <u > in addHtml - @zNightFalLz #1186
21- - Allow to change cell width unit - guillaume-ro-fr #986
21+ - Allow to change cell width unit - @ guillaume-ro-fr #986
2222- Allow to change the line height rule @troosan
23+ - Allow to force an update of all fields on opening a document - @troosan #951
2324
2425### Fixed
2526- Loosen dependency to Zend
Original file line number Diff line number Diff line change @@ -297,7 +297,7 @@ Your TOC can only be generated if you have add at least one title (See "Titles")
297297
298298Options for ``$tocStyle ``:
299299
300- - ``tabLeader ``. Fill type between the title text and the page number. Use the defined constants in PHPWord \\ Style\\ TOC.
300+ - ``tabLeader ``. Fill type between the title text and the page number. Use the defined constants in `` \PhpOffice\PhpWord\ Style\TOC`` .
301301- ``tabPos ``. The position of the tab where the page number appears in twips.
302302- ``indent ``. The indent factor of the titles in twips.
303303
Original file line number Diff line number Diff line change @@ -271,3 +271,12 @@ points to twips.
271271 $sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
272272 // 2 cm right margin
273273 $sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
274+
275+ Automatically Recalculate Fields on Open
276+ ----------------------------------------
277+
278+ To force an update of the fields present in the document, set updateFields to true
279+
280+ .. code-block :: php
281+
282+ $phpWord->getSettings()->setUpdateFields(true);
Original file line number Diff line number Diff line change 44// New Word document
55echo date ('H:i:s ' ), ' Create new PhpWord object ' , EOL ;
66$ phpWord = new \PhpOffice \PhpWord \PhpWord ();
7+ $ phpWord ->getSettings ()->setUpdateFields (true );
78
89// New section
910$ section = $ phpWord ->addSection ();
Original file line number Diff line number Diff line change @@ -116,6 +116,13 @@ class Settings
116116 */
117117 private $ themeFontLang ;
118118
119+ /**
120+ * Automatically Recalculate Fields on Open
121+ *
122+ * @var bool
123+ */
124+ private $ updateFields = false ;
125+
119126 /**
120127 * Radix Point for Field Code Evaluation
121128 *
@@ -345,6 +352,22 @@ public function setThemeFontLang($themeFontLang)
345352 $ this ->themeFontLang = $ themeFontLang ;
346353 }
347354
355+ /**
356+ * @return bool
357+ */
358+ public function hasUpdateFields ()
359+ {
360+ return $ this ->updateFields ;
361+ }
362+
363+ /**
364+ * @param bool $updateFields
365+ */
366+ public function setUpdateFields ($ updateFields )
367+ {
368+ $ this ->updateFields = $ updateFields === null ? false : $ updateFields ;
369+ }
370+
348371 /**
349372 * Returns the Radix Point for Field Code Evaluation
350373 *
Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ private function getSettings()
147147 $ this ->setOnOffValue ('w:doNotTrackMoves ' , $ documentSettings ->hasDoNotTrackMoves ());
148148 $ this ->setOnOffValue ('w:doNotTrackFormatting ' , $ documentSettings ->hasDoNotTrackFormatting ());
149149 $ this ->setOnOffValue ('w:evenAndOddHeaders ' , $ documentSettings ->hasEvenAndOddHeaders ());
150+ $ this ->setOnOffValue ('w:updateFields ' , $ documentSettings ->hasUpdateFields ());
150151
151152 $ this ->setThemeFontLang ($ documentSettings ->getThemeFontLang ());
152153 $ this ->setRevisionView ($ documentSettings ->getRevisionView ());
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ private function writeStyle()
104104
105105 // Bold, italic
106106 $ xmlWriter ->writeElementIf ($ style ->isBold (), 'w:b ' );
107+ $ xmlWriter ->writeElementIf ($ style ->isBold (), 'w:bCs ' );
107108 $ xmlWriter ->writeElementIf ($ style ->isItalic (), 'w:i ' );
108109 $ xmlWriter ->writeElementIf ($ style ->isItalic (), 'w:iCs ' );
109110
Original file line number Diff line number Diff line change @@ -153,4 +153,14 @@ public function testZoomEnum()
153153 $ oSettings ->setZoom (Zoom::FULL_PAGE );
154154 $ this ->assertEquals ('fullPage ' , $ oSettings ->getZoom ());
155155 }
156+
157+ /**
158+ * Test Update Fields on update
159+ */
160+ public function testUpdateFields ()
161+ {
162+ $ oSettings = new Settings ();
163+ $ oSettings ->setUpdateFields (true );
164+ $ this ->assertTrue ($ oSettings ->hasUpdateFields ());
165+ }
156166}
You can’t perform that action at this time.
0 commit comments