企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 文件信息[](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); ~~~