I am using a table with addHtml
method to export HTML to docx file in phpWord. But the font of text is Times New Roman (font-size 12), meanwhile, the font should be Arial (font-size 10) by default. I did not set anything in code. I also tried something but it seems not to work. Here is my code:
$templateProcessor = new PhpOfficePhpWordTemplateProcessor('modules/admin/views/customers/resume_tpl.docx');
$phpWord = new PhpOfficePhpWordPhpWord();
$phpWord->setDefaultFontName('Arial');
$phpWord->setDefaultFontSize(10);
$section = $phpWord->addSection();
$wordTable = $section->addTable();
$wordTable->addRow();
$cell = $wordTable->addCell();
PhpOfficePhpWordSharedHtml::addHtml($cell, str_replace("&","&", $model[self_assessment])); // $model[self_assessment] is the HTML text
// $templateProcessor->setDefaultFontName('Arial');
// $templateProcessor->setDefaultFontSize(10);
$templateProcessor->setComplexBlock('assess', $wordTable);
All I want is to set font to ‘Arial’ and font-size 10.
2
Answers
I kind of figured it out, although I don't like this way :v. Because my text is from CK Editor, so it has HTML format. I just add css style to HTML and it works. Something like this:
Thank you all.
I tested with the
addText()
method with your code and it does change the font-name and font-size of the table, by reference post here Formatting a text in a table cell with PHPWord e.g. bold, font, size e.t.cHope it helps!
And I think this sample might help out for you too
https://github.com/PHPOffice/PHPWord/blob/master/samples/Sample_40_TemplateSetComplexValue.php