我正在使用PHPExcel创建电子表格...我想要在同一个单元格中创建14pt字体和10pt字体的文本。
我已经能够创建一个测试程序,但是它似乎比我想象中的要冗长得多。
有人可以向我展示如何简化设置这两个文本段的字体吗?
以下是我为测试创建的代码...
<?php
require_once './Classes/PHPExcel.php';
require_once './Classes/PHPExcel/IOFactory.php';
$objPHPExcel = new PHPExcel();
$phpColor = new PHPExcel_Style_Color();
$phpColor->setRGB("0070C0");
$objRichText = new PHPExcel_RichText();
$run1 = $objRichText->createTextRun('Main Part of the Title, ');
$run1->getFont()->setBold(true);
$run1->getFont()->setName("Calibri");
$run1->getFont()->setSize("14");
$run1->getFont()->setColor($phpColor);
$run2 = $objRichText->createTextRun(' and some extra');
$run2->getFont()->setBold(true);
$run2->getFont()->setName("Calibri");
$run2->getFont()->setSize("10");
$run2->getFont()->setColor($phpColor);
$objPHPExcel->getActiveSheet()->setCellValue("A1", $objRichText);
header ( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
header ( 'Content-Disposition: attachment;filename="sq_test.xlsx"' );
header ( 'Cache-Control: max-age=0' );
$objWriter = PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel2007' );
$objWriter->save ( 'php://output' );
?>
具体而言,我尝试使用以下内容代替所有的 $run2->getFont() 代码行...
$run2->getFont()->applyFromArray(array("font" => array( "bold" => true, "size" => 10, "name" => "Calibri", "color" => $phpColor)));
它并没有生成错误,但也没有调整字体到其默认设置之外……但如果可能的话,这种简化是我非常希望的。