Пример #1
0
 /**
  * Write Font
  *
  * @param     \PHPExcel\Shared\XMLWriter        $objWriter         XML Writer
  * @param     \PHPExcel\Style\Font                $pFont            Font style
  * @throws     \PHPExcel\Writer\Exception
  */
 private function writeFont(\PHPExcel\Shared\XMLWriter $objWriter = null, \PHPExcel\Style\Font $pFont = null)
 {
     // font
     $objWriter->startElement('font');
     //    Weird! The order of these elements actually makes a difference when opening Excel2007
     //        files in Excel2003 with the compatibility pack. It's not documented behaviour,
     //        and makes for a real WTF!
     // Bold. We explicitly write this element also when false (like MS Office Excel 2007 does
     // for conditional formatting). Otherwise it will apparently not be picked up in conditional
     // formatting style dialog
     if ($pFont->getBold() !== null) {
         $objWriter->startElement('b');
         $objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0');
         $objWriter->endElement();
     }
     // Italic
     if ($pFont->getItalic() !== null) {
         $objWriter->startElement('i');
         $objWriter->writeAttribute('val', $pFont->getItalic() ? '1' : '0');
         $objWriter->endElement();
     }
     // Strikethrough
     if ($pFont->getStrikethrough() !== null) {
         $objWriter->startElement('strike');
         $objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0');
         $objWriter->endElement();
     }
     // Underline
     if ($pFont->getUnderline() !== null) {
         $objWriter->startElement('u');
         $objWriter->writeAttribute('val', $pFont->getUnderline());
         $objWriter->endElement();
     }
     // Superscript / subscript
     if ($pFont->getSuperScript() === true || $pFont->getSubScript() === true) {
         $objWriter->startElement('vertAlign');
         if ($pFont->getSuperScript() === true) {
             $objWriter->writeAttribute('val', 'superscript');
         } elseif ($pFont->getSubScript() === true) {
             $objWriter->writeAttribute('val', 'subscript');
         }
         $objWriter->endElement();
     }
     // Size
     if ($pFont->getSize() !== null) {
         $objWriter->startElement('sz');
         $objWriter->writeAttribute('val', $pFont->getSize());
         $objWriter->endElement();
     }
     // Foreground color
     if ($pFont->getColor()->getARGB() !== null) {
         $objWriter->startElement('color');
         $objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB());
         $objWriter->endElement();
     }
     // Name
     if ($pFont->getName() !== null) {
         $objWriter->startElement('name');
         $objWriter->writeAttribute('val', $pFont->getName());
         $objWriter->endElement();
     }
     $objWriter->endElement();
 }
Пример #2
0
 /**
  * Add a font to added fonts
  *
  * @param \PHPExcel\Style\Font $font
  * @return int Index to FONT record
  */
 public function addFont(\PHPExcel\Style\Font $font)
 {
     $fontHashCode = $font->getHashCode();
     if (isset($this->addedFonts[$fontHashCode])) {
         $fontIndex = $this->addedFonts[$fontHashCode];
     } else {
         $countFonts = count($this->fontWriters);
         $fontIndex = $countFonts < 4 ? $countFonts : $countFonts + 1;
         $fontWriter = new \PHPExcel\Writer\Excel5\Font($font);
         $fontWriter->setColorIndex($this->addColor($font->getColor()->getRGB()));
         $this->fontWriters[] = $fontWriter;
         $this->addedFonts[$fontHashCode] = $fontIndex;
     }
     return $fontIndex;
 }
Пример #3
0
 /**
  * Create CSS style (\PHPExcel\Style\Font)
  *
  * @param    \PHPExcel\Style\Font        $pStyle            \PHPExcel\Style\Font
  * @return    array
  */
 private function createCSSStyleFont(\PHPExcel\Style\Font $pStyle)
 {
     // Construct CSS
     $css = array();
     // Create CSS
     if ($pStyle->getBold()) {
         $css['font-weight'] = 'bold';
     }
     if ($pStyle->getUnderline() != \PHPExcel\Style\Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) {
         $css['text-decoration'] = 'underline line-through';
     } elseif ($pStyle->getUnderline() != \PHPExcel\Style\Font::UNDERLINE_NONE) {
         $css['text-decoration'] = 'underline';
     } elseif ($pStyle->getStrikethrough()) {
         $css['text-decoration'] = 'line-through';
     }
     if ($pStyle->getItalic()) {
         $css['font-style'] = 'italic';
     }
     $css['color'] = '#' . $pStyle->getColor()->getRGB();
     $css['font-family'] = '\'' . $pStyle->getName() . '\'';
     $css['font-size'] = $pStyle->getSize() . 'pt';
     return $css;
 }