mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-30 09:16:03 +03:00
Fixes to rich text in charts
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@86842 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
ead33770d5
commit
fac2858b1d
@ -117,12 +117,19 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
$objWriter->startElement('c:title');
|
$objWriter->startElement('c:title');
|
||||||
$objWriter->startElement('c:tx');
|
$objWriter->startElement('c:tx');
|
||||||
$objWriter->startElement('c:rich');
|
$objWriter->startElement('c:rich');
|
||||||
|
|
||||||
|
$objWriter->startElement('a:bodyPr');
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->startElement('a:lstStyle');
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
$objWriter->startElement('a:p');
|
$objWriter->startElement('a:p');
|
||||||
|
|
||||||
$caption = $title->getCaption();
|
$caption = $title->getCaption();
|
||||||
if (is_array($caption))
|
if (is_array($caption))
|
||||||
$caption = $caption[0];
|
$caption = $caption[0];
|
||||||
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $caption, 'a');
|
$this->getParentWriter()->getWriterPart('stringtable')->writeRichTextForCharts($objWriter, $caption, 'a');
|
||||||
|
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
@ -214,14 +221,14 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
$this->_writeDataLbls($objWriter);
|
$this->_writeDataLbls($objWriter);
|
||||||
|
|
||||||
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_LINECHART) ||
|
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_LINECHART) ||
|
||||||
($groupType === PHPExcel_Chart_DataSeries::TYPE_LINECHART_3D) ||
|
($groupType === PHPExcel_Chart_DataSeries::TYPE_LINECHART_3D)) {
|
||||||
($groupType === PHPExcel_Chart_DataSeries::TYPE_AREACHART) ||
|
|
||||||
($groupType === PHPExcel_Chart_DataSeries::TYPE_AREACHART_3D)) {
|
|
||||||
$objWriter->startElement('c:smooth');
|
$objWriter->startElement('c:smooth');
|
||||||
$objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() );
|
$objWriter->writeAttribute('val', (integer) $plotGroup->getSmoothLine() );
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
} elseif (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
} elseif (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
||||||
($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
|
($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
|
||||||
|
|
||||||
$objWriter->startElement('c:gapWidth');
|
$objWriter->startElement('c:gapWidth');
|
||||||
$objWriter->writeAttribute('val', 150 );
|
$objWriter->writeAttribute('val', 150 );
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
@ -230,6 +237,7 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
||||||
($groupType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
($groupType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
||||||
($groupType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
($groupType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
||||||
|
|
||||||
// Generate 2 unique numbers to use for axId values
|
// Generate 2 unique numbers to use for axId values
|
||||||
$id1 = $id2 = rand(10000000,99999999);
|
$id1 = $id2 = rand(10000000,99999999);
|
||||||
do {
|
do {
|
||||||
@ -317,6 +325,44 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
$objWriter->writeAttribute('val', "b");
|
$objWriter->writeAttribute('val', "b");
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
if (!is_null($xAxisLabel)) {
|
||||||
|
$objWriter->startElement('c:title');
|
||||||
|
$objWriter->startElement('c:tx');
|
||||||
|
$objWriter->startElement('c:rich');
|
||||||
|
|
||||||
|
$objWriter->startElement('a:bodyPr');
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->startElement('a:lstStyle');
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->startElement('a:p');
|
||||||
|
$objWriter->startElement('a:r');
|
||||||
|
|
||||||
|
$caption = $xAxisLabel->getCaption();
|
||||||
|
if (is_array($caption))
|
||||||
|
$caption = $caption[0];
|
||||||
|
$objWriter->startElement('a:t');
|
||||||
|
$objWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->endElement();
|
||||||
|
$objWriter->endElement();
|
||||||
|
$objWriter->endElement();
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->startElement('c:overlay');
|
||||||
|
$objWriter->writeAttribute('val', 0);
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$layout = $xAxisLabel->getLayout();
|
||||||
|
$this->_writeLayout($layout, $objWriter);
|
||||||
|
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$objWriter->startElement('c:numFmt');
|
$objWriter->startElement('c:numFmt');
|
||||||
$objWriter->writeAttribute('formatCode', "General");
|
$objWriter->writeAttribute('formatCode', "General");
|
||||||
$objWriter->writeAttribute('sourceLinked', 1);
|
$objWriter->writeAttribute('sourceLinked', 1);
|
||||||
@ -334,31 +380,6 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
$objWriter->writeAttribute('val', "nextTo");
|
$objWriter->writeAttribute('val', "nextTo");
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
if (!is_null($xAxisLabel)) {
|
|
||||||
$objWriter->startElement('c:title');
|
|
||||||
$objWriter->startElement('c:tx');
|
|
||||||
$objWriter->startElement('c:rich');
|
|
||||||
$objWriter->startElement('a:p');
|
|
||||||
|
|
||||||
$caption = $xAxisLabel->getCaption();
|
|
||||||
if (is_array($caption))
|
|
||||||
$caption = $caption[0];
|
|
||||||
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $caption, 'a');
|
|
||||||
|
|
||||||
$objWriter->endElement();
|
|
||||||
$objWriter->endElement();
|
|
||||||
$objWriter->endElement();
|
|
||||||
$objWriter->endElement();
|
|
||||||
|
|
||||||
$objWriter->startElement('c:overlay');
|
|
||||||
$objWriter->writeAttribute('val', 0);
|
|
||||||
$objWriter->endElement();
|
|
||||||
|
|
||||||
$layout = $xAxisLabel->getLayout();
|
|
||||||
$this->_writeLayout($layout, $objWriter);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($id2 > 0) {
|
if ($id2 > 0) {
|
||||||
$objWriter->startElement('c:crossAx');
|
$objWriter->startElement('c:crossAx');
|
||||||
$objWriter->writeAttribute('val', $id2);
|
$objWriter->writeAttribute('val', $id2);
|
||||||
@ -418,6 +439,43 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
$objWriter->startElement('c:majorGridlines');
|
$objWriter->startElement('c:majorGridlines');
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
if (!is_null($yAxisLabel)) {
|
||||||
|
$objWriter->startElement('c:title');
|
||||||
|
$objWriter->startElement('c:tx');
|
||||||
|
$objWriter->startElement('c:rich');
|
||||||
|
|
||||||
|
$objWriter->startElement('a:bodyPr');
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->startElement('a:lstStyle');
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->startElement('a:p');
|
||||||
|
$objWriter->startElement('a:r');
|
||||||
|
|
||||||
|
$caption = $yAxisLabel->getCaption();
|
||||||
|
if (is_array($caption))
|
||||||
|
$caption = $caption[0];
|
||||||
|
$objWriter->startElement('a:t');
|
||||||
|
$objWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $caption ));
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->endElement();
|
||||||
|
$objWriter->endElement();
|
||||||
|
$objWriter->endElement();
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->startElement('c:overlay');
|
||||||
|
$objWriter->writeAttribute('val', 0);
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$layout = $yAxisLabel->getLayout();
|
||||||
|
$this->_writeLayout($layout, $objWriter);
|
||||||
|
|
||||||
|
$objWriter->endElement();
|
||||||
|
}
|
||||||
|
|
||||||
$objWriter->startElement('c:numFmt');
|
$objWriter->startElement('c:numFmt');
|
||||||
$objWriter->writeAttribute('formatCode', "General");
|
$objWriter->writeAttribute('formatCode', "General");
|
||||||
$objWriter->writeAttribute('sourceLinked', 1);
|
$objWriter->writeAttribute('sourceLinked', 1);
|
||||||
@ -435,31 +493,6 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
$objWriter->writeAttribute('val', "nextTo");
|
$objWriter->writeAttribute('val', "nextTo");
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
if (!is_null($yAxisLabel)) {
|
|
||||||
$objWriter->startElement('c:title');
|
|
||||||
$objWriter->startElement('c:tx');
|
|
||||||
$objWriter->startElement('c:rich');
|
|
||||||
$objWriter->startElement('a:p');
|
|
||||||
|
|
||||||
$caption = $yAxisLabel->getCaption();
|
|
||||||
if (is_array($caption))
|
|
||||||
$caption = $caption[0];
|
|
||||||
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $caption, 'a');
|
|
||||||
|
|
||||||
$objWriter->endElement();
|
|
||||||
$objWriter->endElement();
|
|
||||||
$objWriter->endElement();
|
|
||||||
|
|
||||||
$objWriter->startElement('c:overlay');
|
|
||||||
$objWriter->writeAttribute('val', 0);
|
|
||||||
$objWriter->endElement();
|
|
||||||
|
|
||||||
$layout = $yAxisLabel->getLayout();
|
|
||||||
$this->_writeLayout($layout, $objWriter);
|
|
||||||
|
|
||||||
$objWriter->endElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($id1 > 0) {
|
if ($id1 > 0) {
|
||||||
$objWriter->startElement('c:crossAx');
|
$objWriter->startElement('c:crossAx');
|
||||||
$objWriter->writeAttribute('val', $id2);
|
$objWriter->writeAttribute('val', $id2);
|
||||||
@ -581,9 +614,8 @@ class PHPExcel_Writer_Excel2007_Chart extends PHPExcel_Writer_Excel2007_WriterPa
|
|||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($groupType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART) &&
|
if (($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART) ||
|
||||||
($groupType !== PHPExcel_Chart_DataSeries::TYPE_PIECHART_3D) &&
|
($groupType === PHPExcel_Chart_DataSeries::TYPE_BARCHART_3D)) {
|
||||||
($groupType !== PHPExcel_Chart_DataSeries::TYPE_DONUTCHART)) {
|
|
||||||
|
|
||||||
$objWriter->startElement('c:invertIfNegative');
|
$objWriter->startElement('c:invertIfNegative');
|
||||||
$objWriter->writeAttribute('val', 0);
|
$objWriter->writeAttribute('val', 0);
|
||||||
|
@ -220,6 +220,72 @@ 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
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function writeRichTextForCharts(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_RichText $pRichText = null, $prefix=NULL)
|
||||||
|
{
|
||||||
|
if ($prefix !== NULL)
|
||||||
|
$prefix .= ':';
|
||||||
|
// Loop through rich text elements
|
||||||
|
$elements = $pRichText->getRichTextElements();
|
||||||
|
foreach ($elements as $element) {
|
||||||
|
// r
|
||||||
|
$objWriter->startElement($prefix.'r');
|
||||||
|
|
||||||
|
// rPr
|
||||||
|
$objWriter->startElement($prefix.'rPr');
|
||||||
|
|
||||||
|
// Bold
|
||||||
|
$objWriter->writeAttribute('b', ($element->getFont()->getBold() ? 1 : 0));
|
||||||
|
// Italic
|
||||||
|
$objWriter->writeAttribute('i', ($element->getFont()->getItalic() ? 1 : 0));
|
||||||
|
// Underline
|
||||||
|
$underlineType = $element->getFont()->getUnderline();
|
||||||
|
switch($underlineType) {
|
||||||
|
case 'single' :
|
||||||
|
$underlineType = 'sng';
|
||||||
|
break;
|
||||||
|
case 'double' :
|
||||||
|
$underlineType = 'dbl';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$objWriter->writeAttribute('u', $underlineType);
|
||||||
|
// Strikethrough
|
||||||
|
$objWriter->writeAttribute('strike', ($element->getFont()->getStrikethrough() ? 'sngStrike' : 'noStrike'));
|
||||||
|
|
||||||
|
// rFont
|
||||||
|
$objWriter->startElement($prefix.'latin');
|
||||||
|
$objWriter->writeAttribute('typeface', $element->getFont()->getName());
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
// Superscript / subscript
|
||||||
|
// if ($element->getFont()->getSuperScript() || $element->getFont()->getSubScript()) {
|
||||||
|
// $objWriter->startElement($prefix.'vertAlign');
|
||||||
|
// if ($element->getFont()->getSuperScript()) {
|
||||||
|
// $objWriter->writeAttribute('val', 'superscript');
|
||||||
|
// } else if ($element->getFont()->getSubScript()) {
|
||||||
|
// $objWriter->writeAttribute('val', 'subscript');
|
||||||
|
// }
|
||||||
|
// $objWriter->endElement();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
// t
|
||||||
|
$objWriter->startElement($prefix.'t');
|
||||||
|
$objWriter->writeAttribute('xml:space', 'preserve');
|
||||||
|
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $element->getText() ));
|
||||||
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
$objWriter->endElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flip string table (for index searching)
|
* Flip string table (for index searching)
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user