Example #1
1
 protected function writeCell($value, $column, $row, $config)
 {
     // auto type
     if (!isset($config['type']) || $config['type'] === null) {
         $this->sheet->setCellValueByColumnAndRow($column, $row, $value);
     } elseif ($config['type'] === 'date') {
         if (!is_int($value)) {
             $timestamp = strtotime($value);
         }
         $this->sheet->SetCellValueByColumnAndRow($column, $row, \PHPExcel_Shared_Date::PHPToExcel($timestamp));
         if (!isset($config['styles']['numberformat']['code'])) {
             $config['styles']['numberformat']['code'] = $this->defaultDateFormat;
         }
     } elseif ($config['type'] === 'url') {
         if (isset($config['label'])) {
             if ($config['label'] instanceof \Closure) {
                 // NOTE: calculate label on top level
                 $label = call_user_func($config['label']);
             } else {
                 $label = $config['label'];
             }
         } else {
             $label = $value;
         }
         $urlValid = filter_var($value, FILTER_VALIDATE_URL) !== false;
         if (!$urlValid) {
             $label = '';
         }
         $this->sheet->setCellValueByColumnAndRow($column, $row, $label);
         if ($urlValid) {
             $this->sheet->getCellByColumnAndRow($column, $row)->getHyperlink()->setUrl($value);
         }
     } else {
         $this->sheet->setCellValueExplicitByColumnAndRow($column, $row, $value, $config['type']);
     }
     if (isset($config['styles'])) {
         $this->sheet->getStyleByColumnAndRow($column, $row)->applyFromArray($config['styles']);
     }
 }
Example #2
0
 /**
  * Write one formula somewhere in the worksheet.
  *
  * @param integer $row    Zero indexed row
  * @param integer $col    Zero indexed column
  * @param string  $formula The formula to write
  * @param mixed   $format The XF format for the cell
  */
 public function write_formula($row, $col, $formula, $format = null)
 {
     $this->worksheet->setCellValueExplicitByColumnAndRow($col, $row + 1, $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
     $this->apply_format($row, $col, $format);
 }