Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ composer.lock
composer.phar
vendor
/report
/build
/samples/resources
/samples/results
/.settings
phpword.ini
/.buildpath
/.project
/.project
28 changes: 26 additions & 2 deletions docs/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ Zip class
By default, PHPWord uses `Zip extension <http://php.net/manual/en/book.zip.php>`__
to deal with ZIP compressed archives and files inside them. If you can't have
Zip extension installed on your server, you can use pure PHP library
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which
included with PHPWord.
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which is
included in PHPWord.

.. code-block:: php

Expand All @@ -130,6 +130,17 @@ To turn it on set ``outputEscapingEnabled`` option to ``true`` in your PHPWord c

\PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);

Spelling and grammatical checks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By default spelling and grammatical errors are shown as soon as you open a word document.
For big documents this can slow down the opening of the document. You can hide the spelling and/or grammatical errors with:

.. code-block:: php

\PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true);
\PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true);

Default font
~~~~~~~~~~~~

Expand Down Expand Up @@ -183,3 +194,16 @@ points to twips.
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));

Language
--------

You can hide spelling errors:

.. code-block:: php
\PhpOffice\PhpWord\Settings::setSpellingErrorsHidden(true);

And hide grammatical errors:

.. code-block:: php
\PhpOffice\PhpWord\Settings::setGrammaticalErrorsHidden(true);
52 changes: 52 additions & 0 deletions src/PhpWord/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ class Settings
*/
private static $defaultFontSize = self::DEFAULT_FONT_SIZE;

/**
* Hide spelling errors
* @var boolean
*/
private static $spellingErrorsHidden = false;

/**
* Hide grammatical errors
* @var boolean
*/
private static $grammaticalErrorsHidden = false;

/**
* The user defined temporary directory.
*
Expand Down Expand Up @@ -416,6 +428,46 @@ public static function setDefaultFontSize($value)
return false;
}

/**
* Are spelling errors hidden
*
* @return boolean
*/
public static function isSpellingErrorsHidden()
{
return self::$spellingErrorsHidden;
}

/**
* Hide spelling errors
*
* @param boolean $spellingErrorsHidden
*/
public static function setSpellingErrorsHidden($spellingErrorsHidden)
{
self::$spellingErrorsHidden = $spellingErrorsHidden;
}

/**
* Are grammatical errors hidden
*
* @return boolean
*/
public static function isGrammaticalErrorsHidden()
{
return self::$grammaticalErrorsHidden;
}

/**
* Hide grammatical errors
*
* @param boolean $grammaticalErrorsHidden
*/
public static function setGrammaticalErrorsHidden($grammaticalErrorsHidden)
{
self::$grammaticalErrorsHidden = $grammaticalErrorsHidden;
}

/**
* Load setting from phpword.yml or phpword.yml.dist
*
Expand Down
2 changes: 2 additions & 0 deletions src/PhpWord/Writer/Word2007/Part/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ private function getSettings()
'w:characterSpacingControl' => array('@attributes' => array('w:val' => 'doNotCompress')),
'w:evenAndOddHeaders' => array('@attributes' => array('w:val' => DocumentSettings::isEvenAndOddHeaders() ? 'true': 'false')),
'w:themeFontLang' => array('@attributes' => array('w:val' => 'en-US')),
'w:hideSpellingErrors' => array('@attributes' => array('w:val' => DocumentSettings::isSpellingErrorsHidden() ? 'true' : 'false')),
'w:hideGrammaticalErrors' => array('@attributes' => array('w:val' => DocumentSettings::isGrammaticalErrorsHidden() ? 'true' : 'false')),
'w:decimalSymbol' => array('@attributes' => array('w:val' => '.')),
'w:listSeparator' => array('@attributes' => array('w:val' => ';')),
'w:compat' => array(),
Expand Down
14 changes: 14 additions & 0 deletions tests/PhpWord/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ public function testSetGetDefaultFontSize()
$this->assertFalse(Settings::setDefaultFontSize(null));
}

/**
* Test set/get spelling and grammar
*/
public function testSetGetSpellingGrammar()
{
$this->assertFalse(Settings::isSpellingErrorsHidden());
Settings::setSpellingErrorsHidden(true);
$this->assertTrue(Settings::isSpellingErrorsHidden());

$this->assertFalse(Settings::isGrammaticalErrorsHidden());
Settings::setGrammaticalErrorsHidden(true);
$this->assertTrue(Settings::isGrammaticalErrorsHidden());
}

/**
* Test set/get even and odd headers
*/
Expand Down
45 changes: 41 additions & 4 deletions tests/PhpWord/Writer/Word2007/Part/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,58 @@ public function testCompatibility()
$this->assertEquals($phpWord->getCompatibility()->getOoxmlVersion(), 15);
}

/**
* Test language
*/
public function testLanguage()
{
$phpWord = new PhpWord();

$doc = TestHelperDOCX::getDocument($phpWord);

$file = 'word/settings.xml';

$path = '/w:settings/w:themeFontLang';
$this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file);

$this->assertEquals('en-US', $element->getAttribute('w:val'));
}

/**
* Test spelling
*/
public function testSpelling()
{
$phpWord = new PhpWord();
Settings::setSpellingErrorsHidden(true);

$doc = TestHelperDOCX::getDocument($phpWord);

$file = 'word/settings.xml';

$path = '/w:settings/w:hideSpellingErrors';
$this->assertTrue($doc->elementExists($path, $file));
$element = $doc->getElement($path, $file);

$this->assertEquals('true', $element->getAttribute('w:val'));
}

/**
* Test even and odd headers
*/
public function testEvenAndOddHeaders()
{
$phpWord = new PhpWord();
Settings::setEvenAndOddHeaders(true);

$doc = TestHelperDOCX::getDocument($phpWord);

$file = 'word/settings.xml';

$path = '/w:settings/w:evenAndOddHeaders';
$this->assertTrue($doc->elementExists($path, $file));

$element = $doc->getElement($path, $file);
$this->assertEquals('true', $element->getAttribute('w:val'));
}
Expand Down