diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1536c064..587d0ad5 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@ This release marked heavy refactorings on internal code structure with the creat
- HTML Writer: Basic HTML writer: text, textrun, link, title, textbreak, table, image (as Base64), footnote, endnote - @ivanlanin GH-203 GH-67 GH-147
- PDF Writer: Basic PDF writer using DomPDF: All HTML element except image - @ivanlanin GH-68
- DOCX Writer: Change `docProps/app.xml` `Application` to `PHPWord` - @ivanlanin
+- DOCX Writer: Create `word/settings.xml` and `word/webSettings.xml` dynamically - @ivanlanin
### Bugfixes
diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php
index 920a159c..5cc72f5c 100755
--- a/src/PhpWord/Writer/Word2007.php
+++ b/src/PhpWord/Writer/Word2007.php
@@ -21,6 +21,8 @@ use PhpOffice\PhpWord\Writer\Word2007\Header;
use PhpOffice\PhpWord\Writer\Word2007\Notes;
use PhpOffice\PhpWord\Writer\Word2007\Numbering;
use PhpOffice\PhpWord\Writer\Word2007\Rels;
+use PhpOffice\PhpWord\Writer\Word2007\Settings;
+use PhpOffice\PhpWord\Writer\Word2007\WebSettings;
use PhpOffice\PhpWord\Writer\Word2007\Styles;
/**
@@ -59,6 +61,8 @@ class Word2007 extends AbstractWriter implements WriterInterface
$this->writerParts['document'] = new Document();
$this->writerParts['styles'] = new Styles();
$this->writerParts['numbering'] = new Numbering();
+ $this->writerParts['settings'] = new Settings();
+ $this->writerParts['websettings'] = new WebSettings();
$this->writerParts['header'] = new Header();
$this->writerParts['footer'] = new Footer();
$this->writerParts['footnotes'] = new Notes();
@@ -118,11 +122,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
$objZip->addFromString('word/document.xml', $this->getWriterPart('document')->writeDocument($this->phpWord));
$objZip->addFromString('word/styles.xml', $this->getWriterPart('styles')->writeStyles($this->phpWord));
$objZip->addFromString('word/numbering.xml', $this->getWriterPart('numbering')->writeNumbering());
+ $objZip->addFromString('word/settings.xml', $this->getWriterPart('settings')->writeSettings());
+ $objZip->addFromString('word/webSettings.xml', $this->getWriterPart('websettings')->writeWebSettings());
// Write static files
- $objZip->addFile(__DIR__ . '/../_staticDocParts/settings.xml', 'word/settings.xml');
$objZip->addFile(__DIR__ . '/../_staticDocParts/theme1.xml', 'word/theme/theme1.xml');
- $objZip->addFile(__DIR__ . '/../_staticDocParts/webSettings.xml', 'word/webSettings.xml');
$objZip->addFile(__DIR__ . '/../_staticDocParts/fontTable.xml', 'word/fontTable.xml');
// Close file
diff --git a/src/PhpWord/Writer/Word2007/ContentTypes.php b/src/PhpWord/Writer/Word2007/ContentTypes.php
index a27ef43c..e3b40b4a 100755
--- a/src/PhpWord/Writer/Word2007/ContentTypes.php
+++ b/src/PhpWord/Writer/Word2007/ContentTypes.php
@@ -46,12 +46,15 @@ class ContentTypes extends AbstractWriterPart
}
$xmlWriter = $this->getXmlWriter();
+
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('Types');
$xmlWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types');
+
$this->writeContentType($xmlWriter, $defaults, true);
$this->writeContentType($xmlWriter, $overrides, false);
- $xmlWriter->endElement();
+
+ $xmlWriter->endElement(); // Types
return $xmlWriter->getData();
}
diff --git a/src/PhpWord/Writer/Word2007/Document.php b/src/PhpWord/Writer/Word2007/Document.php
index 0637c689..754ec10c 100644
--- a/src/PhpWord/Writer/Word2007/Document.php
+++ b/src/PhpWord/Writer/Word2007/Document.php
@@ -34,16 +34,10 @@ class Document extends Base
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
-
- // Create XML writer
$xmlWriter = $this->getXmlWriter();
- // XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
- // w:document
$xmlWriter->startElement('w:document');
-
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
@@ -74,8 +68,9 @@ class Document extends Base
}
}
- $xmlWriter->endElement(); // End w:body
- $xmlWriter->endElement(); // End w:document
+ $xmlWriter->endElement(); // w:body
+
+ $xmlWriter->endElement(); // w:document
// Return
return $xmlWriter->getData();
diff --git a/src/PhpWord/Writer/Word2007/Footer.php b/src/PhpWord/Writer/Word2007/Footer.php
index dc726114..e3a83420 100644
--- a/src/PhpWord/Writer/Word2007/Footer.php
+++ b/src/PhpWord/Writer/Word2007/Footer.php
@@ -23,12 +23,9 @@ class Footer extends Base
*/
public function writeFooter(FooterElement $footer)
{
- // Create XML writer
$xmlWriter = $this->getXmlWriter();
- // XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
$xmlWriter->startElement('w:ftr');
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
@@ -42,9 +39,8 @@ class Footer extends Base
$this->writeContainerElements($xmlWriter, $footer);
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // w:ftr
- // Return
return $xmlWriter->getData();
}
}
diff --git a/src/PhpWord/Writer/Word2007/Header.php b/src/PhpWord/Writer/Word2007/Header.php
index 95e57340..d9aad6d5 100644
--- a/src/PhpWord/Writer/Word2007/Header.php
+++ b/src/PhpWord/Writer/Word2007/Header.php
@@ -23,12 +23,9 @@ class Header extends Base
*/
public function writeHeader(HeaderElement $header)
{
- // Create XML writer
$xmlWriter = $this->getXmlWriter();
- // XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
-
$xmlWriter->startElement('w:hdr');
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
@@ -42,9 +39,8 @@ class Header extends Base
$this->writeContainerElements($xmlWriter, $header);
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // w:hdr
- // Return
return $xmlWriter->getData();
}
}
diff --git a/src/PhpWord/Writer/Word2007/Notes.php b/src/PhpWord/Writer/Word2007/Notes.php
index 3b70ee74..d64fd881 100644
--- a/src/PhpWord/Writer/Word2007/Notes.php
+++ b/src/PhpWord/Writer/Word2007/Notes.php
@@ -31,7 +31,6 @@ class Notes extends Base
$elementNode = $isFootnote ? 'w:footnote' : 'w:endnote';
$xmlWriter = $this->getXmlWriter();
- // XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement($rootNode);
$xmlWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
@@ -73,7 +72,7 @@ class Notes extends Base
}
}
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // $rootNode
return $xmlWriter->getData();
}
diff --git a/src/PhpWord/Writer/Word2007/Numbering.php b/src/PhpWord/Writer/Word2007/Numbering.php
index da127891..26d86ef5 100644
--- a/src/PhpWord/Writer/Word2007/Numbering.php
+++ b/src/PhpWord/Writer/Word2007/Numbering.php
@@ -159,7 +159,7 @@ class Numbering extends Base
}
}
- $xmlWriter->endElement();
+ $xmlWriter->endElement(); // w:numbering
return $xmlWriter->getData();
}
diff --git a/src/PhpWord/Writer/Word2007/Rels.php b/src/PhpWord/Writer/Word2007/Rels.php
index ab3198dd..19222b98 100755
--- a/src/PhpWord/Writer/Word2007/Rels.php
+++ b/src/PhpWord/Writer/Word2007/Rels.php
@@ -107,7 +107,8 @@ class Rels extends AbstractWriterPart
$this->writeRel($xmlWriter, $id++, "officeDocument/2006/relationships/{$type}", $target, $targetMode);
}
}
- $xmlWriter->endElement();
+
+ $xmlWriter->endElement(); // Relationships
}
/**
diff --git a/src/PhpWord/Writer/Word2007/Settings.php b/src/PhpWord/Writer/Word2007/Settings.php
new file mode 100644
index 00000000..1a81e521
--- /dev/null
+++ b/src/PhpWord/Writer/Word2007/Settings.php
@@ -0,0 +1,133 @@
+ array('@attributes' => array('w:percent' => '100')),
+ 'w:embedSystemFonts' => '',
+ 'w:defaultTabStop' => array('@attributes' => array('w:val' => '708')),
+ 'w:hyphenationZone' => array('@attributes' => array('w:val' => '425')),
+ 'w:doNotHyphenateCaps' => '',
+ 'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')),
+ 'w:doNotValidateAgainstSchema' => '',
+ 'w:doNotDemarcateInvalidXml' => '',
+ 'w:compat' => array(
+ 'w:useNormalStyleForList' => '',
+ 'w:doNotUseIndentAsNumberingTabStop' => '',
+ 'w:useAltKinsokuLineBreakRules' => '',
+ 'w:allowSpaceOfSameStyleInTable' => '',
+ 'w:doNotSuppressIndentation' => '',
+ 'w:doNotAutofitConstrainedTables' => '',
+ 'w:autofitToFirstFixedWidthCell' => '',
+ 'w:underlineTabInNumList' => '',
+ 'w:displayHangulFixedWidth' => '',
+ 'w:splitPgBreakAndParaMark' => '',
+ 'w:doNotVertAlignCellWithSp' => '',
+ 'w:doNotBreakConstrainedForcedTable' => '',
+ 'w:doNotVertAlignInTxbx' => '',
+ 'w:useAnsiKerningPairs' => '',
+ 'w:cachedColBalance' => '',
+ ),
+ 'm:mathPr' => array(
+ 'm:mathFont' => array('@attributes' => array('m:val' => 'Cambria Math')),
+ 'm:brkBin' => array('@attributes' => array('m:val' => 'before')),
+ 'm:brkBinSub' => array('@attributes' => array('m:val' => '--')),
+ 'm:smallFrac' => array('@attributes' => array('m:val' => 'off')),
+ 'm:dispDef' => '',
+ 'm:lMargin' => array('@attributes' => array('m:val' => '0')),
+ 'm:rMargin' => array('@attributes' => array('m:val' => '0')),
+ 'm:defJc' => array('@attributes' => array('m:val' => 'centerGroup')),
+ 'm:wrapIndent' => array('@attributes' => array('m:val' => '1440')),
+ 'm:intLim' => array('@attributes' => array('m:val' => 'subSup')),
+ 'm:naryLim' => array('@attributes' => array('m:val' => 'undOvr')),
+ ),
+ 'w:uiCompat97To2003' => '',
+ 'w:themeFontLang' => array('@attributes' => array('w:val' => 'de-DE')),
+ 'w:clrSchemeMapping' => array(
+ '@attributes' => array(
+ 'w:bg1' => 'light1',
+ 'w:t1' => 'dark1',
+ 'w:bg2' => 'light2',
+ 'w:t2' => 'dark2',
+ 'w:accent1' => 'accent1',
+ 'w:accent2' => 'accent2',
+ 'w:accent3' => 'accent3',
+ 'w:accent4' => 'accent4',
+ 'w:accent5' => 'accent5',
+ 'w:accent6' => 'accent6',
+ 'w:hyperlink' => 'hyperlink',
+ 'w:followedHyperlink' => 'followedHyperlink',
+ ),
+ ),
+ 'w:doNotIncludeSubdocsInStats' => '',
+ 'w:doNotAutoCompressPictures' => '',
+ 'w:decimalSymbol' => array('@attributes' => array('w:val' => ',')),
+ 'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
+ );
+
+ $xmlWriter = $this->getXmlWriter();
+
+ $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
+ $xmlWriter->startElement('w:settings');
+ $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
+ $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
+ $xmlWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
+ $xmlWriter->writeAttribute('xmlns:sl', 'http://schemas.openxmlformats.org/schemaLibrary/2006/main');
+ $xmlWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
+ $xmlWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
+ $xmlWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
+
+ foreach ($settings as $settingKey => $settingValue) {
+ $this->writeSetting($xmlWriter, $settingKey, $settingValue);
+ }
+
+ $xmlWriter->endElement(); // w:settings
+
+ return $xmlWriter->getData();
+ }
+
+ /**
+ * Write indivual setting, recursive to any child settings
+ *
+ * @param XMLWriter $xmlWriter XML Writer
+ * @param string $settingKey
+ * @param array $settingValue
+ */
+ protected function writeSetting($xmlWriter, $settingKey, $settingValue)
+ {
+ if ($settingValue == '') {
+ $xmlWriter->writeElement($settingKey);
+ } else {
+ $xmlWriter->startElement($settingKey);
+ foreach ($settingValue as $childKey => $childValue) {
+ if ($childKey == '@attributes') {
+ foreach ($childValue as $key => $val) {
+ $xmlWriter->writeAttribute($key, $val);
+ }
+ } else {
+ $this->writeSetting($xmlWriter, $childKey, $childValue);
+ }
+ }
+ $xmlWriter->endElement();
+ }
+ }
+}
diff --git a/src/PhpWord/Writer/Word2007/Styles.php b/src/PhpWord/Writer/Word2007/Styles.php
index 38217847..0af809c9 100644
--- a/src/PhpWord/Writer/Word2007/Styles.php
+++ b/src/PhpWord/Writer/Word2007/Styles.php
@@ -33,11 +33,8 @@ class Styles extends Base
if (is_null($phpWord)) {
throw new Exception("No PhpWord assigned.");
}
-
- // Create XML writer
$xmlWriter = $this->getXmlWriter();
- // XML header
$xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
$xmlWriter->startElement('w:styles');
$xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
diff --git a/src/PhpWord/Writer/Word2007/WebSettings.php b/src/PhpWord/Writer/Word2007/WebSettings.php
new file mode 100644
index 00000000..3edd1ac1
--- /dev/null
+++ b/src/PhpWord/Writer/Word2007/WebSettings.php
@@ -0,0 +1,43 @@
+ '',
+ );
+
+ $xmlWriter = $this->getXmlWriter();
+
+ $xmlWriter->startDocument('1.0', 'UTF-8', 'yes');
+ $xmlWriter->startElement('w:webSettings');
+ $xmlWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
+ $xmlWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
+
+ foreach ($settings as $settingKey => $settingValue) {
+ $this->writeSetting($xmlWriter, $settingKey, $settingValue);
+ }
+
+ $xmlWriter->endElement(); // w:settings
+
+ return $xmlWriter->getData();
+ }
+}
diff --git a/src/PhpWord/_staticDocParts/settings.xml b/src/PhpWord/_staticDocParts/settings.xml
deleted file mode 100644
index 5eb22891..00000000
--- a/src/PhpWord/_staticDocParts/settings.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/PhpWord/_staticDocParts/webSettings.xml b/src/PhpWord/_staticDocParts/webSettings.xml
deleted file mode 100644
index 72d28307..00000000
--- a/src/PhpWord/_staticDocParts/webSettings.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/tests/PhpWord/Tests/Writer/Word2007Test.php b/tests/PhpWord/Tests/Writer/Word2007Test.php
index 5e990615..ce850c21 100644
--- a/tests/PhpWord/Tests/Writer/Word2007Test.php
+++ b/tests/PhpWord/Tests/Writer/Word2007Test.php
@@ -40,6 +40,9 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
'DocProps' => 'DocProps',
'Document' => 'Document',
'Styles' => 'Styles',
+ 'Numbering' => 'Numbering',
+ 'Settings' => 'Settings',
+ 'WebSettings' => 'WebSettings',
'Header' => 'Header',
'Footer' => 'Footer',
'Footnotes' => 'Notes',