diff options
author | h-hishida <h-hishida@quartetcom.co.jp> | 2015-04-28 09:45:00 +0900 |
---|---|---|
committer | h-hishida <h-hishida@quartetcom.co.jp> | 2015-04-28 09:45:00 +0900 |
commit | 373ae12ca5db9837f84fef44f3f7077e766aca08 (patch) | |
tree | c515f2cccceaa886282ac40f89785da072a3627e /src/Util/Sheet.php | |
download | PHPExcelFixer.StyleFixer-373ae12ca5db9837f84fef44f3f7077e766aca08.zip PHPExcelFixer.StyleFixer-373ae12ca5db9837f84fef44f3f7077e766aca08.tar.gz PHPExcelFixer.StyleFixer-373ae12ca5db9837f84fef44f3f7077e766aca08.tar.bz2 |
initial commit
Diffstat (limited to 'src/Util/Sheet.php')
-rw-r--r-- | src/Util/Sheet.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/Util/Sheet.php b/src/Util/Sheet.php new file mode 100644 index 0000000..6e11e1d --- /dev/null +++ b/src/Util/Sheet.php @@ -0,0 +1,70 @@ +<?php + + +namespace PHPExcel\StyleFixer\Util; + + +class Sheet +{ + + /** + * セル番地がExcel形式のセル範囲(コロン区切りのみ対応)に含まれるかどうか + * + * @param string $coordinate + * @param string $cellRange + * @return bool + */ + public function inRange($coordinate, $cellRange) + { + // 絶対参照の$を削除 + $cellRange = str_replace('$', '', $cellRange); + list($startCell, $endCell) = explode(':', $cellRange); + + // 行の範囲チェック + $rowNumber = $this->detectRowNumberFromCoordinate($coordinate); + if ($rowNumber < $this->detectRowNumberFromCoordinate($startCell) || $rowNumber > $this->detectRowNumberFromCoordinate($endCell)) { + return false; + } + + // 列の範囲チェック + $colNumber = $this->detectColNumberFromCoordinate($coordinate); + if ($colNumber < $this->detectColNumberFromCoordinate($startCell) || $colNumber > $this->detectColNumberFromCoordinate($endCell)) { + return false; + } + + return true; + } + + /** + * セル番地から行番号を取り出す + * + * @param string $coordinate + * @return int + */ + private function detectRowNumberFromCoordinate($coordinate) + { + return intval(preg_replace('/[A-Z]+/', '', $coordinate)); + } + + /** + * セル番地から列番号を取り出す + * + * @param string $coordinate + * @return int + */ + private function detectColNumberFromCoordinate($coordinate) + { + $char = preg_replace('/\d+/', '', $coordinate); + + $charA = 65; + + if (strlen($char) == 1) { + return ord($char) - $charA + 1; + } + + $quot = ord($char[0]) - $charA + 1; + $mod = ord($char[1]) - $charA + 1; + + return $quot * 26 + $mod; + } +} |