当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPExcel_Shared_String类代码示例

本文整理汇总了PHP中PHPExcel_Shared_String的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Shared_String类的具体用法?PHP PHPExcel_Shared_String怎么用?PHP PHPExcel_Shared_String使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PHPExcel_Shared_String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 public function setUp()
 {
     if (!defined('PHPEXCEL_ROOT')) {
         define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
     }
     require_once PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php';
     PHPExcel_Shared_String::setDecimalSeparator('.');
     PHPExcel_Shared_String::setThousandsSeparator(',');
 }
开发者ID:iwillhappy1314,项目名称:laravel-admin,代码行数:9,代码来源:NumberFormatTest.php

示例2: bindValue

 /**
  * Bind value to a cell
  *
  * @param PHPExcel_Cell $cell	Cell to bind value to
  * @param mixed $value			Value to bind in cell
  * @return boolean
  */
 public function bindValue(PHPExcel_Cell $cell, $value = null)
 {
     // sanitize UTF-8 strings
     if (is_string($value)) {
         $value = PHPExcel_Shared_String::SanitizeUTF8($value);
     }
     // Find out data type
     $dataType = parent::dataTypeForValue($value);
     // Style logic - strings
     if ($dataType === PHPExcel_Cell_DataType::TYPE_STRING && !$value instanceof PHPExcel_RichText) {
         // Check for percentage
         if (preg_match('/^\\-?[0-9]*\\.?[0-9]*\\s?\\%$/', $value)) {
             // Convert value to number
             $cell->setValueExplicit((double) str_replace('%', '', $value) / 100, PHPExcel_Cell_DataType::TYPE_NUMERIC);
             // Set style
             $cell->getParent()->getStyle($cell->getCoordinate())->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
             return true;
         }
         // Check for time e.g. '9:45', '09:45'
         if (preg_match('/^(\\d|[0-1]\\d|2[0-3]):[0-5]\\d$/', $value)) {
             list($h, $m) = explode(':', $value);
             $days = $h / 24 + $m / 1440;
             // Convert value to number
             $cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
             // Set style
             $cell->getParent()->getStyle($cell->getCoordinate())->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3);
             return true;
         }
         // Check for date
         if (strtotime($value) !== false) {
             // make sure we have UTC for the sake of strtotime
             $saveTimeZone = date_default_timezone_get();
             date_default_timezone_set('UTC');
             // Convert value to Excel date
             $cell->setValueExplicit(PHPExcel_Shared_Date::PHPToExcel(strtotime($value)), PHPExcel_Cell_DataType::TYPE_NUMERIC);
             // Set style
             $cell->getParent()->getStyle($cell->getCoordinate())->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);
             // restore original value for timezone
             date_default_timezone_set($saveTimeZone);
             return true;
         }
     }
     // Style logic - Numbers
     if ($dataType === PHPExcel_Cell_DataType::TYPE_NUMERIC) {
         // Leading zeroes?
         if (preg_match('/^\\-?[0]+[0-9]*\\.?[0-9]*$/', $value)) {
             // Convert value to string
             $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
             // Set style
             $cell->getParent()->getStyle($cell->getCoordinate())->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
             return true;
         }
     }
     // Not bound yet? Use parent...
     return parent::bindValue($cell, $value);
 }
开发者ID:kolbermoorer,项目名称:edugame,代码行数:63,代码来源:AdvancedValueBinder.php

示例3: checkString

 /**
  * Check a string that it satisfies Excel requirements
  *
  * @param  mixed  Value to sanitize to an Excel string
  * @return mixed  Sanitized value
  */
 public static function checkString($pValue = null)
 {
     if ($pValue instanceof PHPExcel_RichText) {
         return $pValue;
     }
     // string must never be longer than 32,767 characters, truncate if necessary
     $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767);
     // we require that newline is represented as "\n" in core, not as "\r\n" or "\r"
     $pValue = str_replace(array("\r\n", "\r"), "\n", $pValue);
     return $pValue;
 }
开发者ID:enozoom,项目名称:es,代码行数:17,代码来源:DataType.php

示例4: bindValue

 /**
  * Bind value to a cell
  *
  * @param  PHPExcel_Cell  $cell   Cell to bind value to
  * @param  mixed          $value  Value to bind in cell
  * @return boolean
  */
 public function bindValue(PHPExcel_Cell $cell, $value = null)
 {
     // sanitize UTF-8 strings
     if (is_string($value)) {
         $value = PHPExcel_Shared_String::SanitizeUTF8($value);
     }
     // Set value explicit
     $cell->setValueExplicit($value, self::dataTypeForValue($value));
     // Done!
     return TRUE;
 }
开发者ID:fgaudenzi,项目名称:webERP-bootstrap,代码行数:18,代码来源:DefaultValueBinder.php

示例5: getImportExcelData

function getImportExcelData($data, $fields)
{
    global $total_records, $cCharset, $columnIndex;
    foreach ($data->getWorksheetIterator() as $worksheet) {
        $highestRow = $worksheet->getHighestRow();
        for ($row = 2; $row <= $highestRow; ++$row) {
            for ($col = 0; $col < $columnIndex; ++$col) {
                $cell = $worksheet->getCellByColumnAndRow($col, $row);
                if (PHPExcel_Shared_Date::isDateTime($cell)) {
                    $date_format = $cell->getParent()->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode();
                    $value = PHPExcel_Style_NumberFormat::ToFormattedString($cell->getValue(), $date_format);
                    if (is_a($value, 'PHPExcel_RichText')) {
                        $value = $value->getPlainText();
                    }
                    if ($value) {
                        $time = array();
                        if (strtotime($value)) {
                            $value = strtotime($value);
                        } else {
                            $d_format = "";
                            for ($i = 0; $i < strlen($date_format); $i++) {
                                $letter = substr(strtolower($date_format), $i, 1);
                                if ($letter == "d" || $letter == "m" || $letter == "y") {
                                    if (strpos($d_format, $letter) === false) {
                                        $d_format .= $letter;
                                    }
                                }
                            }
                            $value = strtotime(localdatetime2db($value, $d_format));
                        }
                        //							$value = PHPExcel_Shared_Date::ExcelToPHP($value);
                        $time = localtime($value, true);
                        $val = $time["tm_year"] + 1900 . "-" . ($time["tm_mon"] + 1) . "-" . $time["tm_mday"] . " " . $time["tm_hour"] . ":" . $time["tm_min"] . ":" . $time["tm_sec"];
                    } else {
                        $val = NULL;
                    }
                } else {
                    $error_handler = set_error_handler("empty_error_handler");
                    $val = PHPExcel_Shared_String::ConvertEncoding($cell->getValue(), $cCharset, 'UTF-8');
                    if (is_a($val, 'PHPExcel_RichText')) {
                        $val = $val->getPlainText();
                    }
                    if ($error_handler) {
                        set_error_handler($error_handler);
                    }
                }
                $arr[$fields[$col]] = $val;
            }
            $ret = InsertRecord($arr, $row - 2);
            $total_records++;
        }
        break;
    }
}
开发者ID:aagusti,项目名称:padl-tng,代码行数:54,代码来源:import_functions.php

示例6: testCurrency

 /**
  * @dataProvider provider
  */
 public function testCurrency($value, $valueBinded, $format, $thousandsSeparator, $decimalSeparator, $currencyCode)
 {
     $sheet = $this->getMock('PHPExcel_Worksheet', array('getStyle', 'getNumberFormat', 'setFormatCode'));
     $sheet->expects($this->once())->method('getStyle')->will($this->returnSelf());
     $sheet->expects($this->once())->method('getNumberFormat')->will($this->returnSelf());
     $sheet->expects($this->once())->method('setFormatCode')->with($format)->will($this->returnSelf());
     PHPExcel_Shared_String::setCurrencyCode($currencyCode);
     PHPExcel_Shared_String::setDecimalSeparator($decimalSeparator);
     PHPExcel_Shared_String::setThousandsSeparator($thousandsSeparator);
     $cell = new PHPExcel_Cell('A', 1, null, PHPExcel_Cell_DataType::TYPE_STRING, $sheet);
     $binder = new PHPExcel_Cell_AdvancedValueBinder();
     $binder->bindValue($cell, $value);
     $this->assertEquals($valueBinded, $cell->getValue());
 }
开发者ID:xVirusproj3ct,项目名称:site_web_phf,代码行数:17,代码来源:AdvancedValueBinderTest.php

示例7: bindValue

 /**
  * Bind value to a cell, preserving possible leading zeros
  * See http://stackoverflow.com/questions/12457610/reading-numbers-as-text-format-with-phpexcel
  *
  * @param  PHPExcel_Cell  $cell   Cell to bind value to
  * @param  mixed          $value  Value to bind in cell
  * @return boolean
  */
 public function bindValue(PHPExcel_Cell $cell, $value = null)
 {
     // sanitize UTF-8 strings
     if (is_string($value)) {
         $value = PHPExcel_Shared_String::SanitizeUTF8($value);
     }
     // Preserve numeric string, including leading zeros, if it is a text format
     $format = $cell->getStyle()->getNumberFormat()->getFormatCode();
     if ($format == PHPExcel_Style_NumberFormat::FORMAT_TEXT) {
         $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
         return true;
     }
     // Not bound yet? Use default value parent...
     return parent::bindValue($cell, $value);
 }
开发者ID:skyosev,项目名称:OpenCart-Overclocked,代码行数:23,代码来源:ExportImportValueBinder.php

示例8: testCurrency

 /**
  * @dataProvider provider
  */
 public function testCurrency($value, $valueBinded, $format, $thousandsSeparator, $decimalSeparator, $currencyCode)
 {
     $sheet = $this->getMock('PHPExcel_Worksheet', array('getStyle', 'getNumberFormat', 'setFormatCode', 'getCellCacheController'));
     $cache = $this->getMockBuilder('PHPExcel_CachedObjectStorage_Memory')->disableOriginalConstructor()->getMock();
     $cache->expects($this->any())->method('getParent')->will($this->returnValue($sheet));
     $sheet->expects($this->once())->method('getStyle')->will($this->returnSelf());
     $sheet->expects($this->once())->method('getNumberFormat')->will($this->returnSelf());
     $sheet->expects($this->once())->method('setFormatCode')->with($format)->will($this->returnSelf());
     $sheet->expects($this->any())->method('getCellCacheController')->will($this->returnValue($cache));
     PHPExcel_Shared_String::setCurrencyCode($currencyCode);
     PHPExcel_Shared_String::setDecimalSeparator($decimalSeparator);
     PHPExcel_Shared_String::setThousandsSeparator($thousandsSeparator);
     $cell = new PHPExcel_Cell(NULL, PHPExcel_Cell_DataType::TYPE_STRING, $sheet);
     $binder = new PHPExcel_Cell_AdvancedValueBinder();
     $binder->bindValue($cell, $value);
     $this->assertEquals($valueBinded, $cell->getValue());
 }
开发者ID:MyPHPTools,项目名称:PHPExcel,代码行数:20,代码来源:AdvancedValueBinderTest.php

示例9: bindValue

 /**
  * Bind value to a cell
  *
  * @param  PHPExcel_Cell  $cell   Cell to bind value to
  * @param  mixed          $value  Value to bind in cell
  * @return boolean
  */
 public function bindValue(PHPExcel_Cell $cell, $value = null)
 {
     // sanitize UTF-8 strings
     if (is_string($value)) {
         $value = PHPExcel_Shared_String::SanitizeUTF8($value);
     } elseif (is_object($value)) {
         // Handle any objects that might be injected
         if ($value instanceof DateTime) {
             $value = $value->format('Y-m-d H:i:s');
         } elseif (!$value instanceof PHPExcel_RichText) {
             $value = (string) $value;
         }
     }
     // Set value explicit
     $cell->setValueExplicit($value, self::dataTypeForValue($value));
     // Done!
     return true;
 }
开发者ID:jonpetersen,项目名称:PHTC,代码行数:25,代码来源:DefaultValueBinder.php

示例10: _setMargins

 private function _setMargins(PHPExcel_Worksheet $pSheet)
 {
     $htmlPage = '@page { ';
     $htmlBody = 'body { ';
     $left = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getLeft()) . 'in; ';
     $htmlPage .= 'left-margin: ' . $left;
     $htmlBody .= 'left-margin: ' . $left;
     $right = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getRight()) . 'in; ';
     $htmlPage .= 'right-margin: ' . $right;
     $htmlBody .= 'right-margin: ' . $right;
     $top = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getTop()) . 'in; ';
     $htmlPage .= 'top-margin: ' . $top;
     $htmlBody .= 'top-margin: ' . $top;
     $bottom = PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getBottom()) . 'in; ';
     $htmlPage .= 'bottom-margin: ' . $bottom;
     $htmlBody .= 'bottom-margin: ' . $bottom;
     $htmlPage .= "}\n";
     $htmlBody .= "}\n";
     return "<style>\n" . $htmlPage . $htmlBody . "</style>\n";
 }
开发者ID:adit-gudhel,项目名称:simpus-dev,代码行数:20,代码来源:HTML.php

示例11: _convertString

 /**
  * Convert a string token to ptgStr
  *
  * @access private
  * @param string $string A string for conversion to its ptg value.
  * @return mixed the converted token on success
  */
 function _convertString($string)
 {
     // chop away beggining and ending quotes
     $string = substr($string, 1, strlen($string) - 2);
     if (strlen($string) > 255) {
         throw new Exception("String is too long");
     }
     if ($this->_BIFF_version == 0x500) {
         return pack("CC", $this->ptg['ptgStr'], strlen($string)) . $string;
     } elseif ($this->_BIFF_version == 0x600) {
         return pack('C', $this->ptg['ptgStr']) . PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($string);
     }
 }
开发者ID:Arikito,项目名称:webking.xt,代码行数:20,代码来源:Parser.php

示例12: _writeDataValidity


//.........这里部分代码省略.........
                     break;
                 case PHPExcel_Cell_DataValidation::STYLE_INFORMATION:
                     $errorStyle = 0x2;
                     break;
             }
             $options |= $errorStyle << 4;
             // explicit formula?
             if ($type == 0x3 && preg_match('/^\\".*\\"$/', $dataValidation->getFormula1())) {
                 $options |= 0x1 << 7;
             }
             // empty cells allowed
             $options |= $dataValidation->getAllowBlank() << 8;
             // show drop down
             $options |= !$dataValidation->getShowDropDown() << 9;
             // show input message
             $options |= $dataValidation->getShowInputMessage() << 18;
             // show error message
             $options |= $dataValidation->getShowErrorMessage() << 19;
             // condition operator
             $operator = $dataValidation->getOperator();
             switch ($operator) {
                 case PHPExcel_Cell_DataValidation::OPERATOR_BETWEEN:
                     $operator = 0x0;
                     break;
                 case PHPExcel_Cell_DataValidation::OPERATOR_NOTBETWEEN:
                     $operator = 0x1;
                     break;
                 case PHPExcel_Cell_DataValidation::OPERATOR_EQUAL:
                     $operator = 0x2;
                     break;
                 case PHPExcel_Cell_DataValidation::OPERATOR_NOTEQUAL:
                     $operator = 0x3;
                     break;
                 case PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHAN:
                     $operator = 0x4;
                     break;
                 case PHPExcel_Cell_DataValidation::OPERATOR_LESSTHAN:
                     $operator = 0x5;
                     break;
                 case PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHANOREQUAL:
                     $operator = 0x6;
                     break;
                 case PHPExcel_Cell_DataValidation::OPERATOR_LESSTHANOREQUAL:
                     $operator = 0x7;
                     break;
             }
             $options |= $operator << 20;
             $data = pack('V', $options);
             // prompt title
             $promptTitle = $dataValidation->getPromptTitle() !== '' ? $dataValidation->getPromptTitle() : chr(0);
             $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($promptTitle);
             // error title
             $errorTitle = $dataValidation->getErrorTitle() !== '' ? $dataValidation->getErrorTitle() : chr(0);
             $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($errorTitle);
             // prompt text
             $prompt = $dataValidation->getPrompt() !== '' ? $dataValidation->getPrompt() : chr(0);
             $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($prompt);
             // error text
             $error = $dataValidation->getError() !== '' ? $dataValidation->getError() : chr(0);
             $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($error);
             // formula 1
             try {
                 $formula1 = $dataValidation->getFormula1();
                 if ($type == 0x3) {
                     // list type
                     $formula1 = str_replace(',', chr(0), $formula1);
                 }
                 $this->_parser->parse($formula1);
                 $formula1 = $this->_parser->toReversePolish();
                 $sz1 = strlen($formula1);
             } catch (Exception $e) {
                 $sz1 = 0;
                 $formula1 = '';
             }
             $data .= pack('vv', $sz1, 0x0);
             $data .= $formula1;
             // formula 2
             try {
                 $formula2 = $dataValidation->getFormula2();
                 if ($formula2 === '') {
                     throw new Exception('No formula2');
                 }
                 $this->_parser->parse($formula2);
                 $formula2 = $this->_parser->toReversePolish();
                 $sz2 = strlen($formula2);
             } catch (Exception $e) {
                 $sz2 = 0;
                 $formula2 = '';
             }
             $data .= pack('vv', $sz2, 0x0);
             $data .= $formula2;
             // cell range address list
             $data .= pack('v', 0x1);
             $data .= $this->_writeBIFF8CellRangeAddressFixed($cellCoordinate);
             $length = strlen($data);
             $header = pack("vv", $record, $length);
             $this->_append($header . $data);
         }
     }
 }
开发者ID:yunsite,项目名称:tp-coupon,代码行数:101,代码来源:Worksheet.php

示例13: _writeCell

 /**
  * Write Cell
  *
  * @param	PHPExcel_Shared_XMLWriter	$objWriter				XML Writer
  * @param	PHPExcel_Worksheet			$pSheet					Worksheet
  * @param	PHPExcel_Cell				$pCell					Cell
  * @param	string[]					$pStringTable			String table
  * @param	string[]					$pFlippedStringTable	String table (flipped), for faster index searching
  * @throws	Exception
  */
 private function _writeCell(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, PHPExcel_Cell $pCell = null, $pStringTable = null, $pFlippedStringTable = null)
 {
     if (is_array($pStringTable) && is_array($pFlippedStringTable)) {
         // Cell
         $objWriter->startElement('c');
         $objWriter->writeAttribute('r', $pCell->getCoordinate());
         // Sheet styles
         if ($pCell->getXfIndex() != '') {
             $objWriter->writeAttribute('s', $pCell->getXfIndex());
         }
         // If cell value is supplied, write cell value
         if (is_object($pCell->getValue()) || $pCell->getValue() !== '') {
             // Map type
             $mappedType = $pCell->getDataType();
             // Write data type depending on its type
             switch (strtolower($mappedType)) {
                 case 'inlinestr':
                     // Inline string
                     $objWriter->writeAttribute('t', $mappedType);
                     break;
                 case 's':
                     // String
                     $objWriter->writeAttribute('t', $mappedType);
                     break;
                 case 'b':
                     // Boolean
                     $objWriter->writeAttribute('t', $mappedType);
                     break;
                 case 'f':
                     // Formula
                     $calculatedValue = null;
                     if ($this->getParentWriter()->getPreCalculateFormulas()) {
                         $calculatedValue = $pCell->getCalculatedValue();
                     } else {
                         $calculatedValue = $pCell->getValue();
                     }
                     if (is_string($calculatedValue)) {
                         $objWriter->writeAttribute('t', 'str');
                     }
                     break;
                 case 'e':
                     // Error
                     $objWriter->writeAttribute('t', $mappedType);
             }
             // Write data depending on its type
             switch (strtolower($mappedType)) {
                 case 'inlinestr':
                     // Inline string
                     if (!$pCell->getValue() instanceof PHPExcel_RichText) {
                         $objWriter->writeElement('t', PHPExcel_Shared_String::ControlCharacterPHP2OOXML(htmlspecialchars($pCell->getValue())));
                     } else {
                         if ($pCell->getValue() instanceof PHPExcel_RichText) {
                             $objWriter->startElement('is');
                             $this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pCell->getValue());
                             $objWriter->endElement();
                         }
                     }
                     break;
                 case 's':
                     // String
                     if (!$pCell->getValue() instanceof PHPExcel_RichText) {
                         if (isset($pFlippedStringTable[$pCell->getValue()])) {
                             $objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()]);
                         }
                     } else {
                         if ($pCell->getValue() instanceof PHPExcel_RichText) {
                             $objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()->getHashCode()]);
                         }
                     }
                     break;
                 case 'f':
                     // Formula
                     $objWriter->writeElement('f', substr($pCell->getValue(), 1));
                     if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
                         if ($this->getParentWriter()->getPreCalculateFormulas()) {
                             $calculatedValue = $pCell->getCalculatedValue();
                             if (!is_array($calculatedValue) && substr($calculatedValue, 0, 1) != '#') {
                                 $v = PHPExcel_Shared_String::FormatNumber($calculatedValue);
                                 $objWriter->writeElement('v', $v);
                             } else {
                                 $objWriter->writeElement('v', '0');
                             }
                         } else {
                             $objWriter->writeElement('v', '0');
                         }
                     }
                     break;
                 case 'n':
                     // Numeric
                     // force point as decimal separator in case current locale uses comma
//.........这里部分代码省略.........
开发者ID:honj51,项目名称:taobaocrm,代码行数:101,代码来源:Worksheet.php

示例14: DATE

 /**
  * DATE
  *
  * The DATE function returns a value that represents a particular date.
  *
  * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
  * format of your regional settings. PHPExcel does not change cell formatting in this way.
  *
  * Excel Function:
  * 		DATE(year,month,day)
  *
  * @access	public
  * @category Date/Time Functions
  * @param	integer		$year	The value of the year argument can include one to four digits.
  * 								Excel interprets the year argument according to the configured
  * 								date system: 1900 or 1904.
  * 								If year is between 0 (zero) and 1899 (inclusive), Excel adds that
  * 								value to 1900 to calculate the year. For example, DATE(108,1,2)
  * 								returns January 2, 2008 (1900+108).
  * 								If year is between 1900 and 9999 (inclusive), Excel uses that
  * 								value as the year. For example, DATE(2008,1,2) returns January 2,
  * 								2008.
  * 								If year is less than 0 or is 10000 or greater, Excel returns the
  * 								#NUM! error value.
  * @param	integer		$month	A positive or negative integer representing the month of the year
  * 								from 1 to 12 (January to December).
  * 								If month is greater than 12, month adds that number of months to
  * 								the first month in the year specified. For example, DATE(2008,14,2)
  * 								returns the serial number representing February 2, 2009.
  * 								If month is less than 1, month subtracts the magnitude of that
  * 								number of months, plus 1, from the first month in the year
  * 								specified. For example, DATE(2008,-3,2) returns the serial number
  * 								representing September 2, 2007.
  * @param	integer		$day	A positive or negative integer representing the day of the month
  * 								from 1 to 31.
  * 								If day is greater than the number of days in the month specified,
  * 								day adds that number of days to the first day in the month. For
  * 								example, DATE(2008,1,35) returns the serial number representing
  * 								February 4, 2008.
  * 								If day is less than 1, day subtracts the magnitude that number of
  * 								days, plus one, from the first day of the month specified. For
  * 								example, DATE(2008,1,-15) returns the serial number representing
  * 								December 16, 2007.
  * @return	mixed	Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  * 						depending on the value of the ReturnDateType flag
  */
 public static function DATE($year = 0, $month = 1, $day = 1)
 {
     $year = PHPExcel_Calculation_Functions::flattenSingleValue($year);
     $month = PHPExcel_Calculation_Functions::flattenSingleValue($month);
     $day = PHPExcel_Calculation_Functions::flattenSingleValue($day);
     $year = $year !== NULL ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0;
     $month = $month !== NULL ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0;
     $day = $day !== NULL ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0;
     if (!is_numeric($year) || !is_numeric($month) || !is_numeric($day)) {
         return PHPExcel_Calculation_Functions::VALUE();
     }
     $year = (int) $year;
     $month = (int) $month;
     $day = (int) $day;
     $baseYear = PHPExcel_Shared_Date::getExcelCalendar();
     // Validate parameters
     if ($year < $baseYear - 1900) {
         return PHPExcel_Calculation_Functions::NaN();
     }
     if ($baseYear - 1900 != 0 && $year < $baseYear && $year >= 1900) {
         return PHPExcel_Calculation_Functions::NaN();
     }
     if ($year < $baseYear && $year >= $baseYear - 1900) {
         $year += 1900;
     }
     if ($month < 1) {
         //	Handle year/month adjustment if month < 1
         --$month;
         $year += ceil($month / 12) - 1;
         $month = 13 - abs($month % 12);
     } elseif ($month > 12) {
         //	Handle year/month adjustment if month > 12
         $year += floor($month / 12);
         $month = $month % 12;
     }
     // Re-validate the year parameter after adjustments
     if ($year < $baseYear || $year >= 10000) {
         return PHPExcel_Calculation_Functions::NaN();
     }
     // Execute function
     $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day);
     switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
         case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
             return (double) $excelDateValue;
         case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
             return (int) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
         case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
             return PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
     }
 }
开发者ID:uskumar33,项目名称:DeltaONE,代码行数:96,代码来源:DateTime.php

示例15: setTitle

 /**
  * Set title
  *
  * @param string $pValue                      String containing the dimension of this worksheet
  * @param string $updateFormulaCellReferences boolean Flag indicating whether cell references in formulae should
  *                                            be updated to reflect the new sheet name.
  *                                            This should be left as the default true, unless you are
  *                                            certain that no formula cells on any worksheet contain
  *                                            references to this worksheet
  *
  * @return PHPExcel_Worksheet
  */
 public function setTitle($pValue = 'Worksheet', $updateFormulaCellReferences = true)
 {
     // Is this a 'rename' or not?
     if ($this->getTitle() == $pValue) {
         return $this;
     }
     // Syntax check
     self::_checkSheetTitle($pValue);
     // Old title
     $oldTitle = $this->getTitle();
     if ($this->_parent) {
         // Is there already such sheet name?
         if ($this->_parent->sheetNameExists($pValue)) {
             // Use name, but append with lowest possible integer
             if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) {
                 $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 29);
             }
             $i = 1;
             while ($this->_parent->sheetNameExists($pValue . ' ' . $i)) {
                 ++$i;
                 if ($i == 10) {
                     if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) {
                         $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 28);
                     }
                 } elseif ($i == 100) {
                     if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) {
                         $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 27);
                     }
                 }
             }
             $altTitle = $pValue . ' ' . $i;
             return $this->setTitle($altTitle, $updateFormulaCellReferences);
         }
     }
     // Set title
     $this->_title = $pValue;
     $this->_dirty = true;
     if ($this->_parent) {
         // New title
         $newTitle = $this->getTitle();
         PHPExcel_Calculation::getInstance($this->_parent)->renameCalculationCacheForWorksheet($oldTitle, $newTitle);
         if ($updateFormulaCellReferences) {
             PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->_parent, $oldTitle, $newTitle);
         }
     }
     return $this;
 }
开发者ID:liu33851861,项目名称:CZD_Yaf_Extension,代码行数:59,代码来源:Worksheet.php


注:本文中的PHPExcel_Shared_String类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。