From d700807ed009e462391cea91b8a4da9d2d9a2ad3 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Mon, 18 Jun 2012 23:43:53 +0100 Subject: [PATCH] Convert string text to rich text for chart title and axis labels --- Classes/PHPExcel/Writer/Excel2007/StringTable.php | 14 ++++++++++---- Tests/33chartcreate.php | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Classes/PHPExcel/Writer/Excel2007/StringTable.php b/Classes/PHPExcel/Writer/Excel2007/StringTable.php index 67231fc6..5399ef94 100644 --- a/Classes/PHPExcel/Writer/Excel2007/StringTable.php +++ b/Classes/PHPExcel/Writer/Excel2007/StringTable.php @@ -52,7 +52,7 @@ class PHPExcel_Writer_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_Wr $aFlippedStringTable = null; // For faster lookup // Is an existing table given? - if (!is_null($pExistingTable) && is_array($pExistingTable)) { + if (($pExistingTable !== NULL) && is_array($pExistingTable)) { $aStringTable = $pExistingTable; } @@ -94,7 +94,7 @@ class PHPExcel_Writer_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_Wr */ public function writeStringTable($pStringTable = null) { - if (!is_null($pStringTable)) { + if ($pStringTable !== NULL) { // Create XML writer $objWriter = null; if ($this->getParentWriter()->getUseDiskCaching()) { @@ -225,12 +225,18 @@ class PHPExcel_Writer_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_Wr * Write Rich Text * * @param PHPExcel_Shared_XMLWriter $objWriter XML Writer - * @param PHPExcel_RichText $pRichText Rich text + * @param string|PHPExcel_RichText $pRichText text string or Rich text * @param string $prefix Optional Namespace prefix * @throws Exception */ - public function writeRichTextForCharts(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_RichText $pRichText = null, $prefix=NULL) + public function writeRichTextForCharts(PHPExcel_Shared_XMLWriter $objWriter = null, $pRichText = null, $prefix=NULL) { + if (!$pRichText instanceof PHPExcel_RichText) { + $textRun = $pRichText; + $pRichText = new PHPExcel_RichText(); + $pRichText->createTextRun($textRun); + } + if ($prefix !== NULL) $prefix .= ':'; // Loop through rich text elements diff --git a/Tests/33chartcreate.php b/Tests/33chartcreate.php index 15710d5e..978b9102 100644 --- a/Tests/33chartcreate.php +++ b/Tests/33chartcreate.php @@ -83,10 +83,13 @@ $plotarea = new PHPExcel_Chart_PlotArea(null, array($series)); // Set the chart legend $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, null, false); +$title = new PHPExcel_Chart_Title('Test Chart'); + + // Create the chart $chart = new PHPExcel_Chart( 'chart1', // name - null, // title + $title, // title $legend, // legend $plotarea, // plotArea true, // plotVisibleOnly