使用 PHPExcel 在 1 个单元格内设置不同的字体颜色
Set different font-color inside 1 cell using PHPExcel
我想使用 PHPExcel 使 1 个单元格内的文本具有不同的颜色,但我找不到相关信息。可能吗?
我相信它可以从 xls 中完成,但是可以使用编程在 PHPExcel 中完成吗?
是的,可以使用 Rich Text 对象在 PHPExcel 中完成。
它们在 PHPExcel documentation and there are examples provided
中有描述
$objRichText = new PHPExcel_RichText();
$objRichText->createText('This invoice is ');
$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
$objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor(
new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN )
);
$objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);
我想使用 PHPExcel 使 1 个单元格内的文本具有不同的颜色,但我找不到相关信息。可能吗?
我相信它可以从 xls 中完成,但是可以使用编程在 PHPExcel 中完成吗?
是的,可以使用 Rich Text 对象在 PHPExcel 中完成。
它们在 PHPExcel documentation and there are examples provided
中有描述$objRichText = new PHPExcel_RichText();
$objRichText->createText('This invoice is ');
$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
$objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor(
new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN )
);
$objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);