简体   繁体   English

如何更改phpword中的字体(名称,大小,行距)?

[英]How to change font (name, size, line spacing) in phpword?

Could you please tell me is it possible to - load docx document into phpword, then change font name, size, line spacing in that loaded document and then save it to another docx file? 您能否告诉我是否可以-将docx文档加载到phpword中,然后更改该加载的文档中的字体名称,大小,行距,然后将其保存到另一个docx文件中?

I'm reading phpword official docx right now, but as I see it's much more creating a new document (with some font name, size and line spacing trough setting of a paragraph for example) than for changes in loaded document. 我现在正在阅读phpword官方docx,但正如我所看到的,它比创建加载的文档要多得多,它可以创建一个新文档(例如,使用段落的某些字体名称,大小和行间距槽设置)。 Or maybe I'm wrong? 还是我错了?

So is it possible to change these "font settings" for loaded document? 因此,可以为加载的文档更改这些“字体设置”吗? Or maybe it is possible to some parsing of loaded document, like some foreach for all paragraphs and then change "font settings" for every paragraph of text? 或者,也许可以对已加载的文档进行一些解析,例如为所有段落添加一些foreach,然后为每个文本段落更改“字体设置”?

Thank you in advance for your help! 预先感谢您的帮助!

Sincerelly yours, 真诚的,

Alwesu 阿尔维苏

Yep, changing some of the document default settings is possible. 是的,可以更改某些文档默认设置。 For example changing the default font definitions: 例如,更改默认字体定义:

$phpWord = \PhpOffice\PhpWord\IOFactory::load('myfile.docx');
$phpWord->setDefaultFontSize(50);
$phpWord->setDefaultFontName('courier');

for line spacing you can check whether the default value can be modified with the setDefaultParagraphStyles method. 对于行间距,您可以检查是否可以使用setDefaultParagraphStyles方法修改默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM