You are here

public function PHPExcel_Writer_Excel2007_StringTable::writeRichTextForCharts in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/StringTable.php \PHPExcel_Writer_Excel2007_StringTable::writeRichTextForCharts()

* Write Rich Text * *

Parameters

PHPExcel_Shared_XMLWriter $objWriter XML Writer: * @param string|PHPExcel_RichText $pRichText text string or Rich text * @param string $prefix Optional Namespace prefix * @throws PHPExcel_Writer_Exception

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007/StringTable.php, line 232

Class

PHPExcel_Writer_Excel2007_StringTable
PHPExcel_Writer_Excel2007_StringTable

Code

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
  $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');	//	Excel2010 accepts, Excel2007 complains
    $objWriter
      ->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML($element
      ->getText()));
    $objWriter
      ->endElement();
    $objWriter
      ->endElement();
  }
}