## 文檔設置[](https://phpword.readthedocs.io/en/latest/general.html#document-settings "永久鏈接到這個標題")
可以使用設置生成的文檔的設置`$phpWord->getSettings()`
### 放大設定[](https://phpword.readthedocs.io/en/latest/general.html#magnification-setting "永久鏈接到這個標題")
默認縮放值為100%。這可以更改為另一個百分比
~~~
$phpWord->getSettings()->setZoom(75);
~~~
或預定義的值`fullPage`,`bestFit`,`textFit`
~~~
$phpWord->getSettings()->setZoom(Zoom::BEST_FIT);
~~~
### 鏡像頁邊距[](https://phpword.readthedocs.io/en/latest/general.html#mirroring-the-page-margins "永久鏈接到這個標題")
使用鏡像邊距為雙面文檔(如書籍或雜志)設置對開頁面。
~~~
$phpWord->getSettings()->setMirrorMargins(true);
~~~
### 拼寫和語法檢查[](https://phpword.readthedocs.io/en/latest/general.html#spelling-and-grammatical-checks "永久鏈接到這個標題")
默認情況下,只要打開word文檔,就會顯示拼寫和語法錯誤。對于大文檔,這可能會減慢文檔的打開速度。您可以隱藏拼寫和/或語法錯誤:
~~~
$phpWord->getSettings()->setHideGrammaticalErrors(true);
$phpWord->getSettings()->setHideSpellingErrors(true);
~~~
您還可以指定拼寫和語法檢查的狀態,標記拼寫或語法,因為臟將在打開文檔時強制重新檢查。
~~~
$proofState = new ProofState();
$proofState->setGrammar(ProofState::CLEAN);
$proofState->setSpelling(ProofState::DIRTY);
$phpWord->getSettings()->setProofState(proofState);
~~~
### 跟蹤修訂[](https://phpword.readthedocs.io/en/latest/general.html#track-revisions "永久鏈接到這個標題")
可以使用激活跟蹤更改`setTrackRevisions`,您可以進一步指定
* 不使用移動語法,而是移動的項目將被視為在一個地方刪除并添加到另一個地方
* 不跟蹤格式修訂
~~~
$phpWord->getSettings()->setTrackRevisions(true);
$phpWord->getSettings()->setDoNotTrackMoves(true);
$phpWord->getSettings()->setDoNotTrackFormatting(true);
~~~
### 十進制符號[](https://phpword.readthedocs.io/en/latest/general.html#decimal-symbol "永久鏈接到這個標題")
表示小數的默認符號是`.`英文。在法語中,您可能希望將其更改`,`為例如。
~~~
$phpWord->getSettings()->setDecimalSymbol(',');
~~~
### 文件語言[](https://phpword.readthedocs.io/en/latest/general.html#document-language "永久鏈接到這個標題")
可以使用以下內容更改文檔的默認語言。
~~~
$phpWord->getSettings()->setThemeFontLang(new Language(Language::FR_BE));
~~~
`Language`有3個參數,一個用于拉丁語言,一個用于東亞語言,一個用于復雜(雙向)語言。`PhpOffice\PhpWord\ComplexType\Language`類中提供了幾種語言代碼,但可以使用任何有效的代碼/ ID。
如果您要生成RTF文檔,則需要以不同方式設置語言。
~~~
$lang = new Language();
$lang->setLangId(Language::EN_GB_ID);
$phpWord->getSettings()->setThemeFontLang($lang);
~~~
## 文件信息[](https://phpword.readthedocs.io/en/latest/general.html#document-information "永久鏈接到這個標題")
您可以設置文檔信息,例如標題,創建者和公司名稱。使用以下功能:
~~~
$properties = $phpWord->getDocInfo();
$properties->setCreator('My name');
$properties->setCompany('My factory');
$properties->setTitle('My title');
$properties->setDescription('My description');
$properties->setCategory('My category');
$properties->setLastModifiedBy('My name');
$properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
$properties->setSubject('My subject');
$properties->setKeywords('my, key, word');
~~~
## 測量單位[](https://phpword.readthedocs.io/en/latest/general.html#measurement-units "永久鏈接到這個標題")
Open Office XML中的基本長度單位是twip。緹意味著“英寸點的第二十”,即1緹= 1/1440英寸。
您可以使用PHPWord輔助函數將英寸,厘米或點轉換為twip。
~~~
// Paragraph with 6 points space after
$phpWord->addParagraphStyle('My Style', array(
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(6))
);
$section = $phpWord->addSection();
$sectionStyle = $section->getStyle();
// half inch left margin
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
~~~
## 文件保護[](https://phpword.readthedocs.io/en/latest/general.html#document-protection "永久鏈接到這個標題")
文檔(或其中的一部分)可以受密碼保護。
~~~
$documentProtection = $phpWord->getSettings()->getDocumentProtection();
$documentProtection->setEditing(DocProtect::READ_ONLY);
$documentProtection->setPassword('myPassword');
~~~
## 打開時自動重新計算字段[](https://phpword.readthedocs.io/en/latest/general.html#automatically-recalculate-fields-on-open "永久鏈接到這個標題")
要強制更新文檔中存在的字段,請將updateFields設置為true
~~~
$phpWord->getSettings()->setUpdateFields(true);
~~~
## 連字[](https://phpword.readthedocs.io/en/latest/general.html#hyphenation "永久鏈接到這個標題")
連字符描述了用連字符打破單詞的過程。有幾種控制連字符的選項。
### 自動連字[](https://phpword.readthedocs.io/en/latest/general.html#auto-hyphenation "永久鏈接到這個標題")
自動連接文本設置`autoHyphenation`為`true`。
~~~
$phpWord->getSettings()->setAutoHyphenation(true);
~~~
### 連續連字符限制[](https://phpword.readthedocs.io/en/latest/general.html#consecutive-hyphen-limit "永久鏈接到這個標題")
可以通過`consecutiveHyphenLimit`選項控制以連字符結尾的連續文本行的最大數量。如果未設置選項或提供的值,則沒有限制`0`。
~~~
$phpWord->getSettings()->setConsecutiveHyphenLimit(2);
~~~
### 連字區[](https://phpword.readthedocs.io/en/latest/general.html#hyphenation-zone "永久鏈接到這個標題")
連字符區域(以*twip為單位*)是在應用連字符之前允許的空白量。連字區越小,連字越多。或者換句話說,連字區域越寬,連詞越少。
~~~
$phpWord->getSettings()->setHyphenationZone(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
~~~
### 連字帽[](https://phpword.readthedocs.io/en/latest/general.html#hyphenate-caps "永久鏈接到這個標題")
要控制是否所有大寫字母的單詞都應使用連字符,請使用doNotHyphenateCaps選項。
~~~
$phpWord->getSettings()->setDoNotHyphenateCaps(true);
~~~