Box\Spout\Writer\Common\Helper\CellHelper::isBoolean PHP Метод

isBoolean() публичный статический Метод

"true"/"false" and 0/1 are not booleans.
public static isBoolean ( $value ) : boolean
$value
Результат boolean Whether the given value is boolean
    public static function isBoolean($value)
    {
        return gettype($value) === 'boolean';
    }

Usage Example

Пример #1
0
 /**
  * Adds data to the worksheet.
  *
  * @param array $dataRow Array containing data to be written. Cannot be empty.
  *          Example $dataRow = ['data1', 1234, null, '', 'data5'];
  * @param \Box\Spout\Writer\Style\Style $style Style to be applied to the row. NULL means use default style.
  * @return void
  * @throws \Box\Spout\Common\Exception\IOException If the data cannot be written
  * @throws \Box\Spout\Common\Exception\InvalidArgumentException If a cell value's type is not supported
  */
 public function addRow($dataRow, $style)
 {
     $cellNumber = 0;
     $rowIndex = $this->lastWrittenRowIndex + 1;
     $numCells = count($dataRow);
     $rowXML = '<row r="' . $rowIndex . '" spans="1:' . $numCells . '">';
     foreach ($dataRow as $cellValue) {
         $columnIndex = CellHelper::getCellIndexFromColumnIndex($cellNumber);
         $cellXML = '<c r="' . $columnIndex . $rowIndex . '"';
         $cellXML .= ' s="' . $style->getId() . '"';
         if (CellHelper::isNonEmptyString($cellValue)) {
             // CFDB EDIT BEGIN: Special case added to handle HYPERLINK functions
             // this IF wrapping exiting code in ELSE
             $matches = array();
             if (preg_match('/=HYPERLINK\\("(.*)","(.*)"\\)/', $cellValue, $matches)) {
                 // Create a Formula
                 $url = $this->stringsEscaper->escape($matches[1]);
                 $text = $this->stringsEscaper->escape($matches[2]);
                 $formula = sprintf('HYPERLINK("%s","%s")', $url, $text);
                 $cellXML = sprintf('<c r="%s%s" t="str"><f>%s</f><v>%s</v></c>', $columnIndex, $rowIndex, $formula, $text);
             } else {
                 // CFDB EDIT END
                 if ($this->shouldUseInlineStrings) {
                     $cellXML .= ' t="inlineStr"><is><t>' . $this->stringsEscaper->escape($cellValue) . '</t></is></c>';
                 } else {
                     $sharedStringId = $this->sharedStringsHelper->writeString($cellValue);
                     $cellXML .= ' t="s"><v>' . $sharedStringId . '</v></c>';
                 }
             }
             // CFDB EDIT this line
         } else {
             if (CellHelper::isBoolean($cellValue)) {
                 $cellXML .= ' t="b"><v>' . $cellValue . '</v></c>';
             } else {
                 if (CellHelper::isNumeric($cellValue)) {
                     $cellXML .= '><v>' . $cellValue . '</v></c>';
                 } else {
                     if (empty($cellValue)) {
                         // don't write empty cells (not appending to $cellXML is the right behavior!)
                         $cellXML = '';
                     } else {
                         throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . gettype($cellValue));
                     }
                 }
             }
         }
         $rowXML .= $cellXML;
         $cellNumber++;
     }
     $rowXML .= '</row>';
     $wasWriteSuccessful = fwrite($this->sheetFilePointer, $rowXML);
     if ($wasWriteSuccessful === false) {
         throw new IOException("Unable to write data in {$this->worksheetFilePath}");
     }
     // only update the count if the write worked
     $this->lastWrittenRowIndex++;
 }
All Usage Examples Of Box\Spout\Writer\Common\Helper\CellHelper::isBoolean