简体   繁体   中英

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?

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. 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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