private function PHPExcel_Writer_Excel5_Worksheet::_writeFormula in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel5/Worksheet.php \PHPExcel_Writer_Excel5_Worksheet::_writeFormula()
* Write a formula to the specified row and column (zero indexed). * The textual representation of the formula is passed to the parser in * Parser.php which returns a packed binary string. * * Returns 0 : normal termination * -1 : formula errors (bad formula) * -2 : row or column out of range * *
Parameters
integer $row Zero indexed row: * @param integer $col Zero indexed column * @param string $formula The formula text string * @param mixed $xfIndex The XF format index * @param mixed $calculatedValue Calculated value * @return integer
1 call to PHPExcel_Writer_Excel5_Worksheet::_writeFormula()
- PHPExcel_Writer_Excel5_Worksheet::close in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Writer/ Excel5/ Worksheet.php - * Add data to the beginning of the workbook (note the reverse order) * and to the end of the workbook. * * @access public *
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Writer/ Excel5/ Worksheet.php, line 866
Class
- PHPExcel_Writer_Excel5_Worksheet
- PHPExcel_Writer_Excel5_Worksheet
Code
private function _writeFormula($row, $col, $formula, $xfIndex, $calculatedValue) {
$record = 0x6;
// Record identifier
// Initialize possible additional value for STRING record that should be written after the FORMULA record?
$stringValue = null;
// calculated value
if (isset($calculatedValue)) {
// Since we can't yet get the data type of the calculated value,
// we use best effort to determine data type
if (is_bool($calculatedValue)) {
// Boolean value
$num = pack('CCCvCv', 0x1, 0x0, (int) $calculatedValue, 0x0, 0x0, 0xffff);
}
elseif (is_int($calculatedValue) || is_float($calculatedValue)) {
// Numeric value
$num = pack('d', $calculatedValue);
}
elseif (is_string($calculatedValue)) {
if (array_key_exists($calculatedValue, PHPExcel_Cell_DataType::getErrorCodes())) {
// Error value
$num = pack('CCCvCv', 0x2, 0x0, self::_mapErrorCode($calculatedValue), 0x0, 0x0, 0xffff);
}
elseif ($calculatedValue === '') {
// Empty string (and BIFF8)
$num = pack('CCCvCv', 0x3, 0x0, 0x0, 0x0, 0x0, 0xffff);
}
else {
// Non-empty string value (or empty string BIFF5)
$stringValue = $calculatedValue;
$num = pack('CCCvCv', 0x0, 0x0, 0x0, 0x0, 0x0, 0xffff);
}
}
else {
// We are really not supposed to reach here
$num = pack('d', 0x0);
}
}
else {
$num = pack('d', 0x0);
}
$grbit = 0x3;
// Option flags
$unknown = 0x0;
// Must be zero
// Strip the '=' or '@' sign at the beginning of the formula string
if ($formula[0] == '=') {
$formula = substr($formula, 1);
}
else {
// Error handling
$this
->_writeString($row, $col, 'Unrecognised character for formula');
return -1;
}
// Parse the formula using the parser in Parser.php
try {
$error = $this->_parser
->parse($formula);
$formula = $this->_parser
->toReversePolish();
$formlen = strlen($formula);
// Length of the binary string
$length = 0x16 + $formlen;
// Length of the record data
$header = pack("vv", $record, $length);
$data = pack("vvv", $row, $col, $xfIndex) . $num . pack("vVv", $grbit, $unknown, $formlen);
$this
->_append($header . $data . $formula);
// Append also a STRING record if necessary
if ($stringValue !== null) {
$this
->_writeStringRecord($stringValue);
}
return 0;
} catch (PHPExcel_Exception $e) {
// do nothing
}
}