/**
  * Create a new sheet
  * @param  string        $title
  * @param  callback|null $callback
  * @return  LaravelExcelWriter
  */
 public function sheet($title, $callback = null)
 {
     // Clone the active sheet
     $this->sheet = $this->excel->createSheet(null, $title);
     // If a parser was set, inject it
     if ($this->parser) {
         $this->sheet->setParser($this->parser);
     }
     // Set the sheet title
     $this->sheet->setTitle($title);
     // Set the default page setup
     $this->sheet->setDefaultPageSetup();
     // Do the callback
     if ($callback instanceof Closure) {
         call_user_func($callback, $this->sheet);
     }
     // Autosize columns when no user didn't change anything about column sizing
     if (!$this->sheet->hasFixedSizeColumns()) {
         $this->sheet->setAutosize(Config::get('excel.export.autosize', false));
     }
     // Parse the sheet
     $this->sheet->parsed();
     return $this;
 }
 /**
  * Get the cell style
  * @return \PHPExcel_Style
  */
 protected function getCellStyle()
 {
     return $this->sheet->getStyle($this->cells);
 }
 /**
  * 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;
     }
 }
Exemple #4
0
 /**
  * Sheet data row
  *
  * @param LaravelExcelWorksheet $sheet
  * @param int                   $index
  * @param Project\Issue         $issue
  *
  * @return void
  */
 protected function sheetRow(LaravelExcelWorksheet $sheet, $index, Project\Issue $issue)
 {
     // Setup row data
     array_walk($this->columns, function (&$column, $key, Project\Issue $issue) {
         $column = (string) $issue->{$key};
         if ($key === 'status') {
             $column = (int) $issue->status === Project\Issue::STATUS_OPEN ? 'open' : 'closed';
             $column = trans('tinyissue.' . $column);
         }
     }, $issue);
     // Write row
     $sheet->row($index, $this->columns);
     // Format last cell
     $sheet->cell('G' . $index, function (CellWriter $cell) use($issue) {
         $color = (int) $issue->status === Project\Issue::STATUS_CLOSED ? '#FF0000' : '#00FF00';
         $cell->setBackground($color);
     });
 }