本文整理汇总了PHP中Style::getNumberFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Style::getNumberFormat方法的具体用法?PHP Style::getNumberFormat怎么用?PHP Style::getNumberFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Style
的用法示例。
在下文中一共展示了Style::getNumberFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _readXf
/**
* XF - Extended Format
*
* This record contains formatting information for cells, rows, columns or styles.
* According to http://support.microsoft.com/kb/147732 there are always at least 15 cell style XF
* and 1 cell XF.
* Inspection of Excel files generated by MS Office Excel shows that XF records 0-14 are cell style XF
* and XF record 15 is a cell XF
* We only read the first cell style XF and skip the remaining cell style XF records
* We read all cell XF records.
*
* -- "OpenOffice.org's Documentation of the Microsoft
* Excel File Format"
*/
private function _readXf()
{
$length = $this->_GetInt2d($this->_data, $this->_pos + 2);
$recordData = substr($this->_data, $this->_pos + 4, $length);
// move stream pointer to next record
$this->_pos += 4 + $length;
$objStyle = new Style();
if (!$this->_readDataOnly) {
// offset: 0; size: 2; Index to FONT record
if ($this->_GetInt2d($recordData, 0) < 4) {
$fontIndex = $this->_GetInt2d($recordData, 0);
} else {
// this has to do with that index 4 is omitted in all BIFF versions for some strange reason
// check the OpenOffice documentation of the FONT record
$fontIndex = $this->_GetInt2d($recordData, 0) - 1;
}
$objStyle->setFont($this->_objFonts[$fontIndex]);
// offset: 2; size: 2; Index to FORMAT record
$numberFormatIndex = $this->_GetInt2d($recordData, 2);
if (isset($this->_formats[$numberFormatIndex])) {
// then we have user-defined format code
$numberformat = array('code' => $this->_formats[$numberFormatIndex]);
} elseif (($code = Style_NumberFormat::builtInFormatCode($numberFormatIndex)) !== '') {
// then we have built-in format code
$numberformat = array('code' => $code);
} else {
// we set the general format code
$numberformat = array('code' => 'General');
}
$objStyle->getNumberFormat()->setFormatCode($numberformat['code']);
// offset: 4; size: 2; XF type, cell protection, and parent style XF
// bit 2-0; mask 0x0007; XF_TYPE_PROT
$xfTypeProt = $this->_GetInt2d($recordData, 4);
// bit 0; mask 0x01; 1 = cell is locked
$isLocked = (0x1 & $xfTypeProt) >> 0;
$objStyle->getProtection()->setLocked($isLocked ? Style_Protection::PROTECTION_INHERIT : Style_Protection::PROTECTION_UNPROTECTED);
// bit 1; mask 0x02; 1 = Formula is hidden
$isHidden = (0x2 & $xfTypeProt) >> 1;
$objStyle->getProtection()->setHidden($isHidden ? Style_Protection::PROTECTION_PROTECTED : Style_Protection::PROTECTION_UNPROTECTED);
// bit 2; mask 0x04; 0 = Cell XF, 1 = Cell Style XF
$isCellStyleXf = (0x4 & $xfTypeProt) >> 2;
// offset: 6; size: 1; Alignment and text break
// bit 2-0, mask 0x07; horizontal alignment
$horAlign = (0x7 & ord($recordData[6])) >> 0;
switch ($horAlign) {
case 0:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_GENERAL);
break;
case 1:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_LEFT);
break;
case 2:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER);
break;
case 3:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_RIGHT);
break;
case 5:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_JUSTIFY);
break;
case 6:
$objStyle->getAlignment()->setHorizontal(Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS);
break;
}
// bit 3, mask 0x08; wrap text
$wrapText = (0x8 & ord($recordData[6])) >> 3;
switch ($wrapText) {
case 0:
$objStyle->getAlignment()->setWrapText(false);
break;
case 1:
$objStyle->getAlignment()->setWrapText(true);
break;
}
// bit 6-4, mask 0x70; vertical alignment
$vertAlign = (0x70 & ord($recordData[6])) >> 4;
switch ($vertAlign) {
case 0:
$objStyle->getAlignment()->setVertical(Style_Alignment::VERTICAL_TOP);
break;
case 1:
$objStyle->getAlignment()->setVertical(Style_Alignment::VERTICAL_CENTER);
break;
case 2:
$objStyle->getAlignment()->setVertical(Style_Alignment::VERTICAL_BOTTOM);
break;
//.........这里部分代码省略.........
示例2: _writeCellStyleDxf
/**
* Write Cell Style Dxf
*
* @param Shared_XMLWriter $objWriter XML Writer
* @param Style $pStyle Style
* @throws Exception
*/
private function _writeCellStyleDxf(Shared_XMLWriter $objWriter = null, Style $pStyle = null)
{
// dxf
$objWriter->startElement('dxf');
// font
$this->_writeFont($objWriter, $pStyle->getFont());
// numFmt
$this->_writeNumFmt($objWriter, $pStyle->getNumberFormat());
// fill
$this->_writeFill($objWriter, $pStyle->getFill());
// alignment
$objWriter->startElement('alignment');
$objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
$objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
$textRotation = 0;
if ($pStyle->getAlignment()->getTextRotation() >= 0) {
$textRotation = $pStyle->getAlignment()->getTextRotation();
} else {
if ($pStyle->getAlignment()->getTextRotation() < 0) {
$textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
}
}
$objWriter->writeAttribute('textRotation', $textRotation);
$objWriter->endElement();
// border
$this->_writeBorder($objWriter, $pStyle->getBorders());
// protection
if ($pStyle->getProtection()->getLocked() != Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != Style_Protection::PROTECTION_INHERIT) {
$objWriter->startElement('protection');
if ($pStyle->getProtection()->getLocked() != Style_Protection::PROTECTION_INHERIT) {
$objWriter->writeAttribute('locked', $pStyle->getProtection()->getLocked() == Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false');
}
if ($pStyle->getProtection()->getHidden() != Style_Protection::PROTECTION_INHERIT) {
$objWriter->writeAttribute('hidden', $pStyle->getProtection()->getHidden() == Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false');
}
$objWriter->endElement();
}
$objWriter->endElement();
}