5

phpExcel使单元格部分文字加粗、放大、添加颜色

 1 year ago
source link: http://abcdxyzk.github.io/blog/2022/12/29/lang-php-richtext/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

phpExcel使单元格部分文字加粗、放大、添加颜色

2022-12-29 16:43:00

可以使用phpExcel的富文本进行操作

$objPHPExcel = new \PHPExcel();

//创建一个富文本对象 
$objRichText = new \PHPExcel_RichText(); 
$objRichText->createText('啊啊啊啊'); 

//需要改变大小或颜色的文字内容 
$objPayable = $objRichText->createTextRun('不不不'); 

//设置加粗
$objPayable->getFont()->setBold(true);
//设置斜体
$objPayable->getFont()->setItalic(true);
//设置文字大小
$objPayable->getFont()->setSize(15);
//设置颜色
$objPayable->getFont()->setColor( new \PHPExcel_Style_Color(\PHPExcel_Style_Color::COLOR_DARKGREEN) );

$objRichText->createText('超超超超');

$objPHPExcel->getActiveSheet()->getCell('A1')->setValue($objRichText);

$PHPWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
$PHPWriter->save('a.xlsx'); 

Posted by kk

2022-12-29 16:43:00language, php

« PHPExcel设置打印区域 PHPExcel 页面边距设置 »

wx_ok.pngali_ok.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK