Answer the question
In order to leave comments, you need to log in
How to make part of text bold in phpexcel?
Hello colleagues!
I've been fighting for two days, so I decided to write here.
There is a php script that generates an xlsx file. You need to insert text into one of the cells and highlight part of it in bold.
The text is formed according to the principle: Fixed text + variable $out->suggestions[0]->values
Did according to the textbook:
$objRichText = new PHPExcel_RichText();
$objRichText->createText(''); //может и не нужен
$objPayable = $objRichText->createTextRun('Фиксированный текст');
$objPayable->getFont()->setBold(true);
$objRichText->createText($out->suggestions[0]->values); //через переменную типа $test = $out->suggestions[0]->values; тоже не идет
Answer the question
In order to leave comments, you need to log in
In the end, I did everything through PHPExcel_RichText ().
I redid the output into a cell and everything worked as it should, I think this was the problem.
I made two createTextRun to be able to specify the font in the first and second parts forcibly, otherwise the font and size changed in an incomprehensible way.
$objKOMYrichText = new PHPExcel_RichText();
$objKOMY = $objKOMYrichText->createTextRun('Кому: ');
$objKOMY->getFont()->setBold(true);
$objKOMY->getFont()->setName('Times New Roman');
$objKOMY->getFont()->setSize(16);
$objKOMY2 = $objKOMYrichText->createTextRun($out->suggestions[0]->value);
$objKOMY2->getFont()->setName('Times New Roman');
$objKOMY2->getFont()->setSize(16);
$xls->getActiveSheet()->getCell("B{$num2}")->setValue($objKOMYrichText);
PHPExcel has been deprecated for a long time, but you can get examples from unit tests, there is one for rich text ( link ).
UPD. By the way, the example is quite in the subject, because there you can prepare html code and just in the template wrap only what you need with the <b> tag, and not all the text
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question