Ejemplo n.º 1
0
 private function _parseRichText($is = null)
 {
     $value = new RichText();
     if (isset($is->t)) {
         $value->createText(Shared_String::ControlCharacterOOXML2PHP((string) $is->t));
     } else {
         foreach ($is->r as $run) {
             if (!isset($run->rPr)) {
                 $objText = $value->createText(Shared_String::ControlCharacterOOXML2PHP((string) $run->t));
             } else {
                 $objText = $value->createTextRun(Shared_String::ControlCharacterOOXML2PHP((string) $run->t));
                 if (isset($run->rPr->rFont["val"])) {
                     $objText->getFont()->setName((string) $run->rPr->rFont["val"]);
                 }
                 if (isset($run->rPr->sz["val"])) {
                     $objText->getFont()->setSize((string) $run->rPr->sz["val"]);
                 }
                 if (isset($run->rPr->color)) {
                     $objText->getFont()->setColor(new Style_Color($this->_readColor($run->rPr->color)));
                 }
                 if (isset($run->rPr->b["val"]) && ((string) $run->rPr->b["val"] == 'true' || (string) $run->rPr->b["val"] == '1') || isset($run->rPr->b) && !isset($run->rPr->b["val"])) {
                     $objText->getFont()->setBold(true);
                 }
                 if (isset($run->rPr->i["val"]) && ((string) $run->rPr->i["val"] == 'true' || (string) $run->rPr->i["val"] == '1') || isset($run->rPr->i) && !isset($run->rPr->i["val"])) {
                     $objText->getFont()->setItalic(true);
                 }
                 if (isset($run->rPr->vertAlign) && isset($run->rPr->vertAlign["val"])) {
                     $vertAlign = strtolower((string) $run->rPr->vertAlign["val"]);
                     if ($vertAlign == 'superscript') {
                         $objText->getFont()->setSuperScript(true);
                     }
                     if ($vertAlign == 'subscript') {
                         $objText->getFont()->setSubScript(true);
                     }
                 }
                 if (isset($run->rPr->u) && !isset($run->rPr->u["val"])) {
                     $objText->getFont()->setUnderline(Style_Font::UNDERLINE_SINGLE);
                 } else {
                     if (isset($run->rPr->u) && isset($run->rPr->u["val"])) {
                         $objText->getFont()->setUnderline((string) $run->rPr->u["val"]);
                     }
                 }
                 if (isset($run->rPr->strike["val"]) && ((string) $run->rPr->strike["val"] == 'true' || (string) $run->rPr->strike["val"] == '1') || isset($run->rPr->strike) && !isset($run->rPr->strike["val"])) {
                     $objText->getFont()->setStrikethrough(true);
                 }
             }
         }
     }
     return $value;
 }
Ejemplo n.º 2
0
 /**
  * Read LABELSST record
  * This record represents a cell that contains a string. It
  * replaces the LABEL record and RSTRING record used in
  * BIFF2-BIFF5.
  *
  * --	"OpenOffice.org's Documentation of the Microsoft
  * 		Excel File Format"
  */
 private function _readLabelSst()
 {
     $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
     $recordData = substr($this->_data, $this->_pos + 4, $length);
     // move stream pointer to next record
     $this->_pos += 4 + $length;
     // offset: 0; size: 2; index to row
     $row = $this->_GetInt2d($recordData, 0);
     // offset: 2; size: 2; index to column
     $column = $this->_GetInt2d($recordData, 2);
     $columnString = Cell::stringFromColumnIndex($column);
     // Read cell?
     if (!is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle())) {
         // offset: 4; size: 2; index to XF record
         $xfIndex = $this->_GetInt2d($recordData, 4);
         // offset: 6; size: 4; index to SST record
         $index = $this->_GetInt4d($recordData, 6);
         // add cell
         if (($fmtRuns = $this->_sst[$index]['fmtRuns']) && !$this->_readDataOnly) {
             // then we should treat as rich text
             $richText = new RichText();
             $charPos = 0;
             for ($i = 0; $i <= count($this->_sst[$index]['fmtRuns']); ++$i) {
                 if (isset($fmtRuns[$i])) {
                     $text = Shared_String::Substring($this->_sst[$index]['value'], $charPos, $fmtRuns[$i]['charPos'] - $charPos);
                     $charPos = $fmtRuns[$i]['charPos'];
                 } else {
                     $text = Shared_String::Substring($this->_sst[$index]['value'], $charPos, Shared_String::CountCharacters($this->_sst[$index]['value']));
                 }
                 if (Shared_String::CountCharacters($text) > 0) {
                     if ($i == 0) {
                         // first text run, no style
                         $richText->createText($text);
                     } else {
                         $textRun = $richText->createTextRun($text);
                         if (isset($fmtRuns[$i - 1])) {
                             if ($fmtRuns[$i - 1]['fontIndex'] < 4) {
                                 $fontIndex = $fmtRuns[$i - 1]['fontIndex'];
                             } else {
                                 // this has to do with that index 4 is omitted in all BIFF versions for some strange reason
                                 // check the OpenOffice documentation of the FONT record
                                 $fontIndex = $fmtRuns[$i - 1]['fontIndex'] - 1;
                             }
                             $textRun->setFont(clone $this->_objFonts[$fontIndex]);
                         }
                     }
                 }
             }
             $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
             $cell->setValueExplicit($richText, Cell_DataType::TYPE_STRING);
         } else {
             $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
             $cell->setValueExplicit($this->_sst[$index]['value'], Cell_DataType::TYPE_STRING);
         }
         if (!$this->_readDataOnly) {
             // add style information
             $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
         }
     }
 }