42 } elseif (
$format ==
'integer') {
44 } elseif (
$format ==
'boolean') {
54 private static function _readColor($color,$background=
false) {
55 if (isset($color[
"rgb"])) {
56 return (
string)$color[
"rgb"];
57 }
else if (isset($color[
"indexed"])) {
63 public static function readChart($chartElements,$chartName) {
64 $namespacesChartMeta = $chartElements->getNamespaces(
true);
65 $chartElementsC = $chartElements->children($namespacesChartMeta[
'c']);
68 $dispBlanksAs = $plotVisOnly = NULL;
70 foreach($chartElementsC as $chartElementKey => $chartElement) {
71 switch ($chartElementKey) {
73 foreach($chartElement as $chartDetailsKey => $chartDetails) {
74 $chartDetailsC = $chartDetails->children($namespacesChartMeta[
'c']);
75 switch ($chartDetailsKey) {
77 $plotAreaLayout = $XaxisLable = $YaxisLable = null;
78 $plotSeries = $plotAttributes =
array();
79 foreach($chartDetails as $chartDetailKey => $chartDetail) {
80 switch ($chartDetailKey) {
82 $plotAreaLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta,
'plotArea');
85 if (isset($chartDetail->title)) {
86 $XaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta[
'c']),$namespacesChartMeta,
'cat');
90 if (isset($chartDetail->title)) {
91 $XaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta[
'c']),$namespacesChartMeta,
'cat');
95 if (isset($chartDetail->title)) {
96 $YaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta[
'c']),$namespacesChartMeta,
'cat');
101 $barDirection = self::_getAttribute($chartDetail->barDir,
'val',
'string');
102 $plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
103 $plotSer->setPlotDirection($barDirection);
104 $plotSeries[] = $plotSer;
105 $plotAttributes = self::_readChartAttributes($chartDetail);
109 $plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
110 $plotAttributes = self::_readChartAttributes($chartDetail);
114 $plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
115 $plotAttributes = self::_readChartAttributes($chartDetail);
117 case "doughnutChart":
120 $explosion = isset($chartDetail->ser->explosion);
121 $plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
122 $plotSer->setPlotStyle($explosion);
123 $plotSeries[] = $plotSer;
124 $plotAttributes = self::_readChartAttributes($chartDetail);
127 $scatterStyle = self::_getAttribute($chartDetail->scatterStyle,
'val',
'string');
128 $plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
129 $plotSer->setPlotStyle($scatterStyle);
130 $plotSeries[] = $plotSer;
131 $plotAttributes = self::_readChartAttributes($chartDetail);
134 $bubbleScale = self::_getAttribute($chartDetail->bubbleScale,
'val',
'integer');
135 $plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
136 $plotSer->setPlotStyle($bubbleScale);
137 $plotSeries[] = $plotSer;
138 $plotAttributes = self::_readChartAttributes($chartDetail);
141 $radarStyle = self::_getAttribute($chartDetail->radarStyle,
'val',
'string');
142 $plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
143 $plotSer->setPlotStyle($radarStyle);
144 $plotSeries[] = $plotSer;
145 $plotAttributes = self::_readChartAttributes($chartDetail);
148 case "surface3DChart":
149 $wireFrame = self::_getAttribute($chartDetail->wireframe,
'val',
'boolean');
150 $plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
151 $plotSer->setPlotStyle($wireFrame);
152 $plotSeries[] = $plotSer;
153 $plotAttributes = self::_readChartAttributes($chartDetail);
156 $plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
157 $plotAttributes = self::_readChartAttributes($plotAreaLayout);
161 if ($plotAreaLayout == NULL) {
165 self::_setChartAttributes($plotAreaLayout,$plotAttributes);
168 $plotVisOnly = self::_getAttribute($chartDetails,
'val',
'string');
171 $dispBlanksAs = self::_getAttribute($chartDetails,
'val',
'string');
174 $title = self::_chartTitle($chartDetails,$namespacesChartMeta,
'title');
178 $legendLayout = null;
179 $legendOverlay =
false;
180 foreach($chartDetails as $chartDetailKey => $chartDetail) {
181 switch ($chartDetailKey) {
183 $legendPos = self::_getAttribute($chartDetail,
'val',
'string');
186 $legendOverlay = self::_getAttribute($chartDetail,
'val',
'boolean');
189 $legendLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta,
'legend');
208 foreach($titleDetails as $titleDetailKey => $chartDetail) {
209 switch ($titleDetailKey) {
211 $titleDetails = $chartDetail->rich->children($namespacesChartMeta[
'a']);
212 foreach($titleDetails as $titleKey => $titleDetail) {
215 $titleDetailPart = $titleDetail->children($namespacesChartMeta[
'a']);
216 $caption[] = self::_parseRichText($titleDetailPart);
221 $titleLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta);
231 if (!isset($chartDetail->manualLayout)) {
234 $details = $chartDetail->manualLayout->children($namespacesChartMeta[
'c']);
235 if (is_null($details)) {
239 foreach($details as $detailKey => $detail) {
241 $layout[$detailKey] = self::_getAttribute($detail,
'val',
'string');
248 $multiSeriesType = NULL;
250 $seriesLabel = $seriesCategory = $seriesValues = $plotOrder =
array();
252 $seriesDetailSet = $chartDetail->children($namespacesChartMeta[
'c']);
253 foreach($seriesDetailSet as $seriesDetailKey => $seriesDetails) {
254 switch ($seriesDetailKey) {
256 $multiSeriesType = self::_getAttribute($chartDetail->grouping,
'val',
'string');
260 foreach($seriesDetails as $seriesKey => $seriesDetail) {
261 switch ($seriesKey) {
263 $seriesIndex = self::_getAttribute($seriesDetail,
'val',
'integer');
266 $seriesOrder = self::_getAttribute($seriesDetail,
'val',
'integer');
267 $plotOrder[$seriesIndex] = $seriesOrder;
270 $seriesLabel[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta);
273 $marker = self::_getAttribute($seriesDetail->symbol,
'val',
'string');
276 $smoothLine = self::_getAttribute($seriesDetail,
'val',
'boolean');
279 $seriesCategory[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta);
282 $seriesValues[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker);
285 $seriesCategory[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker);
288 $seriesValues[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker);
294 return new PHPExcel_Chart_DataSeries($plotType,$multiSeriesType,$plotOrder,$seriesLabel,$seriesCategory,$seriesValues,$smoothLine);
299 if (isset($seriesDetail->strRef)) {
300 $seriesSource = (
string) $seriesDetail->strRef->f;
301 $seriesData = self::_chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta[
'c']),
's');
303 return new PHPExcel_Chart_DataSeriesValues(
'String',$seriesSource,$seriesData[
'formatCode'],$seriesData[
'pointCount'],$seriesData[
'dataValues'],$marker,$smoothLine);
304 } elseif (isset($seriesDetail->numRef)) {
305 $seriesSource = (
string) $seriesDetail->numRef->f;
306 $seriesData = self::_chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta[
'c']));
308 return new PHPExcel_Chart_DataSeriesValues(
'Number',$seriesSource,$seriesData[
'formatCode'],$seriesData[
'pointCount'],$seriesData[
'dataValues'],$marker,$smoothLine);
309 } elseif (isset($seriesDetail->multiLvlStrRef)) {
310 $seriesSource = (
string) $seriesDetail->multiLvlStrRef->f;
311 $seriesData = self::_chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta[
'c']),
's');
312 $seriesData[
'pointCount'] = count($seriesData[
'dataValues']);
314 return new PHPExcel_Chart_DataSeriesValues(
'String',$seriesSource,$seriesData[
'formatCode'],$seriesData[
'pointCount'],$seriesData[
'dataValues'],$marker,$smoothLine);
315 } elseif (isset($seriesDetail->multiLvlNumRef)) {
316 $seriesSource = (
string) $seriesDetail->multiLvlNumRef->f;
317 $seriesData = self::_chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta[
'c']),
's');
318 $seriesData[
'pointCount'] = count($seriesData[
'dataValues']);
320 return new PHPExcel_Chart_DataSeriesValues(
'String',$seriesSource,$seriesData[
'formatCode'],$seriesData[
'pointCount'],$seriesData[
'dataValues'],$marker,$smoothLine);
327 $seriesVal =
array();
331 foreach($seriesValueSet as $seriesValueIdx => $seriesValue) {
332 switch ($seriesValueIdx) {
334 $pointCount = self::_getAttribute($seriesValue,
'val',
'integer');
337 $formatCode = (
string) $seriesValue;
340 $pointVal = self::_getAttribute($seriesValue,
'idx',
'integer');
341 if ($dataType ==
's') {
342 $seriesVal[$pointVal] = (
string) $seriesValue->v;
344 $seriesVal[$pointVal] = (float) $seriesValue->v;
350 if (empty($seriesVal)) {
354 return array(
'formatCode' => $formatCode,
355 'pointCount' => $pointCount,
356 'dataValues' => $seriesVal
362 $seriesVal =
array();
366 foreach($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) {
367 foreach($seriesLevel as $seriesValueIdx => $seriesValue) {
368 switch ($seriesValueIdx) {
370 $pointCount = self::_getAttribute($seriesValue,
'val',
'integer');
373 $formatCode = (
string) $seriesValue;
376 $pointVal = self::_getAttribute($seriesValue,
'idx',
'integer');
377 if ($dataType ==
's') {
378 $seriesVal[$pointVal][] = (
string) $seriesValue->v;
380 $seriesVal[$pointVal][] = (float) $seriesValue->v;
387 return array(
'formatCode' => $formatCode,
388 'pointCount' => $pointCount,
389 'dataValues' => $seriesVal
396 foreach($titleDetailPart as $titleDetailElementKey => $titleDetailElement) {
397 if (isset($titleDetailElement->t)) {
398 $objText = $value->createTextRun( (
string) $titleDetailElement->t );
400 if (isset($titleDetailElement->rPr)) {
401 if (isset($titleDetailElement->rPr->rFont[
"val"])) {
402 $objText->getFont()->setName((
string) $titleDetailElement->rPr->rFont[
"val"]);
405 $fontSize = (self::_getAttribute($titleDetailElement->rPr,
'sz',
'integer'));
406 if (!is_null($fontSize)) {
407 $objText->getFont()->setSize(floor($fontSize / 100));
410 $fontColor = (self::_getAttribute($titleDetailElement->rPr,
'color',
'string'));
411 if (!is_null($fontColor)) {
415 $bold = self::_getAttribute($titleDetailElement->rPr,
'b',
'boolean');
416 if (!is_null($bold)) {
417 $objText->getFont()->setBold($bold);
420 $italic = self::_getAttribute($titleDetailElement->rPr,
'i',
'boolean');
421 if (!is_null($italic)) {
422 $objText->getFont()->setItalic($italic);
425 $baseline = self::_getAttribute($titleDetailElement->rPr,
'baseline',
'integer');
426 if (!is_null($baseline)) {
428 $objText->getFont()->setSuperScript(
true);
429 } elseif($baseline < 0) {
430 $objText->getFont()->setSubScript(
true);
434 $underscore = (self::_getAttribute($titleDetailElement->rPr,
'u',
'string'));
435 if (!is_null($underscore)) {
436 if ($underscore ==
'sng') {
438 } elseif($underscore ==
'dbl') {
445 $strikethrough = (self::_getAttribute($titleDetailElement->rPr,
's',
'string'));
446 if (!is_null($strikethrough)) {
447 if ($strikethrough ==
'noStrike') {
448 $objText->getFont()->setStrikethrough(
false);
450 $objText->getFont()->setStrikethrough(
true);
460 $plotAttributes =
array();
461 if (isset($chartDetail->dLbls)) {
462 if (isset($chartDetail->dLbls->howLegendKey)) {
463 $plotAttributes[
'showLegendKey'] = self::_getAttribute($chartDetail->dLbls->showLegendKey,
'val',
'string');
465 if (isset($chartDetail->dLbls->showVal)) {
466 $plotAttributes[
'showVal'] = self::_getAttribute($chartDetail->dLbls->showVal,
'val',
'string');
468 if (isset($chartDetail->dLbls->showCatName)) {
469 $plotAttributes[
'showCatName'] = self::_getAttribute($chartDetail->dLbls->showCatName,
'val',
'string');
471 if (isset($chartDetail->dLbls->showSerName)) {
472 $plotAttributes[
'showSerName'] = self::_getAttribute($chartDetail->dLbls->showSerName,
'val',
'string');
474 if (isset($chartDetail->dLbls->showPercent)) {
475 $plotAttributes[
'showPercent'] = self::_getAttribute($chartDetail->dLbls->showPercent,
'val',
'string');
477 if (isset($chartDetail->dLbls->showBubbleSize)) {
478 $plotAttributes[
'showBubbleSize'] = self::_getAttribute($chartDetail->dLbls->showBubbleSize,
'val',
'string');
480 if (isset($chartDetail->dLbls->showLeaderLines)) {
481 $plotAttributes[
'showLeaderLines'] = self::_getAttribute($chartDetail->dLbls->showLeaderLines,
'val',
'string');
485 return $plotAttributes;
490 foreach($plotAttributes as $plotAttributeKey => $plotAttributeValue) {
491 switch($plotAttributeKey) {
492 case 'showLegendKey' :
493 $plotArea->setShowLegendKey($plotAttributeValue);
496 $plotArea->setShowVal($plotAttributeValue);
499 $plotArea->setShowCatName($plotAttributeValue);
502 $plotArea->setShowSerName($plotAttributeValue);
505 $plotArea->setShowPercent($plotAttributeValue);
507 case 'showBubbleSize' :
508 $plotArea->setShowBubbleSize($plotAttributeValue);
510 case 'showLeaderLines' :
511 $plotArea->setShowLeaderLines($plotAttributeValue);
static _readColor($color, $background=false)
static _chartDataSeries($chartDetail, $namespacesChartMeta, $plotType)
static _readChartAttributes($chartDetail)
static _chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker=null, $smoothLine=false)
static _parseRichText($titleDetailPart=null)
static _chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType='n')
static _chartDataSeriesValues($seriesValueSet, $dataType='n')
static _chartLayoutDetails($chartDetail, $namespacesChartMeta)
static readChart($chartElements, $chartName)
static _chartTitle($titleDetails, $namespacesChartMeta, $type)
static _getAttribute($component, $name, $format)
Create styles array
The data for the language used.
static _setChartAttributes($plotArea, $plotAttributes)
static indexedColor($pIndex, $background=FALSE)
Get indexed color.