Esempio n. 1
0
 /**
  * Parse CSS
  * @param  LaravelExcelWorksheet $sheet
  * @param  string                $column
  * @param  integer               $row
  * @param  string                $name
  * @param  string                $value
  * @return void
  */
 protected function parseCssProperties($sheet, $column, $row, $name, $value)
 {
     $cells = $sheet->getStyle($column . $row);
     switch ($name) {
         // Cell width
         case 'width':
             $this->parseWidth($sheet, $column, $row, $value);
             break;
             // Row height
         // Row height
         case 'height':
             $this->parseHeight($sheet, $column, $row, $value);
             break;
             // BACKGROUND
         // BACKGROUND
         case 'background':
         case 'background-color':
             $original = $value;
             $value = $this->getColor($value);
             $cells->getFill()->applyFromArray(array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $value)));
             break;
             // TEXT COLOR
         // TEXT COLOR
         case 'color':
             $value = $this->getColor($value);
             $cells->getFont()->getColor()->applyFromArray(array('rgb' => $value));
             break;
             // FONT SIZE
         // FONT SIZE
         case 'font-size':
             $cells->getFont()->setSize($value);
             break;
             // FONT WEIGHT
         // FONT WEIGHT
         case 'font-weight':
             if ($value == 'bold' || $value >= 500) {
                 $cells->getFont()->setBold(true);
             }
             break;
             // FONT STYLE
         // FONT STYLE
         case 'font-style':
             if ($value == 'italic') {
                 $cells->getFont()->setItalic(true);
             }
             break;
             // FONT FACE
         // FONT FACE
         case 'font-family':
             $cells->getFont()->applyFromArray(array('name' => $value));
             break;
             // TEXT DECORATION
         // TEXT DECORATION
         case 'text-decoration':
             switch ($value) {
                 case 'underline':
                     $cells->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
                     break;
                 case 'line-through':
                     $cells->getFont()->setStrikethrough(true);
                     break;
             }
             break;
             // Text align
         // Text align
         case 'text-align':
             $horizontal = false;
             switch ($value) {
                 case 'center':
                     $horizontal = PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
                     break;
                 case 'left':
                     $horizontal = PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
                     break;
                 case 'right':
                     $horizontal = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
                     break;
                 case 'justify':
                     $horizontal = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY;
                     break;
             }
             if ($horizontal) {
                 $cells->getAlignment()->applyFromArray(array('horizontal' => $horizontal));
             }
             break;
             // Vertical align
         // Vertical align
         case 'vertical-align':
             $vertical = false;
             switch ($value) {
                 case 'top':
                     $vertical = PHPExcel_Style_Alignment::VERTICAL_TOP;
                     break;
                 case 'middle':
                     $vertical = PHPExcel_Style_Alignment::VERTICAL_CENTER;
                     break;
                 case 'bottom':
                     $vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
                     break;
                 case 'justify':
                     $vertical = PHPExcel_Style_Alignment::VERTICAL_JUSTIFY;
                     break;
             }
             if ($vertical) {
                 $cells->getAlignment()->applyFromArray(array('vertical' => $vertical));
             }
             break;
             // Borders
         // Borders
         case 'border':
         case 'borders':
             $borders = explode(' ', $value);
             $style = $borders[1];
             $color = end($borders);
             $color = $this->getColor($color);
             $borderStyle = $this->borderStyle($style);
             $cells->getBorders()->applyFromArray(array('allborders' => array('style' => $borderStyle, 'color' => array('rgb' => $color))));
             break;
             // Border-top
         // Border-top
         case 'border-top':
             $borders = explode(' ', $value);
             $style = $borders[1];
             $color = end($borders);
             $color = $this->getColor($color);
             $borderStyle = $this->borderStyle($style);
             $cells->getBorders()->getTop()->applyFromArray(array('style' => $borderStyle, 'color' => array('rgb' => $color)));
             break;
             // Border-bottom
         // Border-bottom
         case 'border-bottom':
             $borders = explode(' ', $value);
             $style = $borders[1];
             $color = end($borders);
             $color = $this->getColor($color);
             $borderStyle = $this->borderStyle($style);
             $cells->getBorders()->getBottom()->applyFromArray(array('style' => $borderStyle, 'color' => array('rgb' => $color)));
             break;
             // Border-right
         // Border-right
         case 'border-right':
             $borders = explode(' ', $value);
             $style = $borders[1];
             $color = end($borders);
             $color = $this->getColor($color);
             $borderStyle = $this->borderStyle($style);
             $cells->getBorders()->getRight()->applyFromArray(array('style' => $borderStyle, 'color' => array('rgb' => $color)));
             break;
             // Border-left
         // Border-left
         case 'border-left':
             $borders = explode(' ', $value);
             $style = $borders[1];
             $color = end($borders);
             $color = $this->getColor($color);
             $borderStyle = $this->borderStyle($style);
             $cells->getBorders()->getLeft()->applyFromArray(array('style' => $borderStyle, 'color' => array('rgb' => $color)));
             break;
             // wrap-text
         // wrap-text
         case 'wrap-text':
             if ($value == 'true') {
                 $wrap = true;
             }
             if (!$value || $value == 'false') {
                 $wrap = false;
             }
             $cells->getAlignment()->setWrapText($wrap);
             break;
     }
 }
Esempio n. 2
0
 /**
  * Get the cell style
  * @return \PHPExcel_Style
  */
 protected function getCellStyle()
 {
     return $this->sheet->getStyle($this->cells);
 }