使用PHPExcel创建粗体文本/单元格 [英] creating bold text/cells with PHPExcel
问题描述
我试图加粗文本,但我没有这样做,出于我真的不知道的原因,我遵循了PHPExcel文档中的步骤,但没有结果,这是我的代码:
im trying to bold text but im failing to do so, for a reason i realy dont know, i have followed steps in the documentation of PHPExcel, but to no result, here is my code:
require_once './classes/PHPExcel.php';
Create new PHPExcel object
$objPHPExcel = new PHPExcel();
include('./classes/PHPExcel/Writer/Excel5.php');
$objPHPExcel->getActiveSheet()->mergeCells('A1:k1');
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(18);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(40);
$objPHPExcel->getActiveSheet()
->setcellValue('A25', "Answer")
->setcellValue('B25', "Surname")
->setcellValue('C25', "Name")
->setcellValue('D25', "Contact Number")
->setcellValue('E25', "Comment");
//some stuff in between...
//problem starts here...
$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);
推荐答案
从版本1.7.2升级到包含Excel5编写器中对RTF的支持的最新版本可能会有所帮助...版本1.7.2将近3岁. 1.7.7是当前的生产版本,1.7.8已经过期,但可以在github上找到.
Upgrading from release 1.7.2 to a more recent version that includes support for Rich Text in the Excel5 writer might help... version 1.7.2 is nearly 3-years old. 1.7.7 is the current production release, with 1.7.8 already overdue but available on github.
这是问题"列表上的工作"项目#8916,并且在生产版本1.7.7中添加了支持
This was Work item #8916 on the Issues list, and support was added in production release 1.7.7
这篇关于使用PHPExcel创建粗体文本/单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!