Extract coordinate methods to `Coordinate` class

This commit is contained in:
Adrien Crivelli 2017-11-18 23:12:55 +09:00
parent 1cec980167
commit e0150fd43e
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
36 changed files with 859 additions and 845 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Style; use PhpOffice\PhpSpreadsheet\Style\Style;
@ -24,7 +24,7 @@ for ($col = 0; $col < 50; ++$col) {
for ($row = 0; $row < 100; ++$row) { for ($row = 0; $row < 100; ++$row) {
$str = ($row + $col); $str = ($row + $col);
$style = $styles[$row % 10]; $style = $styles[$row % 10];
$coord = Cell::stringFromColumnIndex($col) . ($row + 1); $coord = Coordinate::stringFromColumnIndex($col) . ($row + 1);
$worksheet->setCellValue($coord, $str); $worksheet->setCellValue($coord, $str);
$worksheet->duplicateStyle($style, $coord); $worksheet->duplicateStyle($style, $coord);
} }

View File

@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Engine\CyclicReferenceStack;
use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger; use PhpOffice\PhpSpreadsheet\Calculation\Engine\Logger;
use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack; use PhpOffice\PhpSpreadsheet\Calculation\Token\Stack;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Shared; use PhpOffice\PhpSpreadsheet\Shared;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -3491,11 +3492,11 @@ class Calculation
$oData = array_merge(explode(':', $operand1Data['reference']), explode(':', $operand2Data['reference'])); $oData = array_merge(explode(':', $operand1Data['reference']), explode(':', $operand2Data['reference']));
$oCol = $oRow = []; $oCol = $oRow = [];
foreach ($oData as $oDatum) { foreach ($oData as $oDatum) {
$oCR = Cell::coordinateFromString($oDatum); $oCR = Coordinate::coordinateFromString($oDatum);
$oCol[] = Cell::columnIndexFromString($oCR[0]) - 1; $oCol[] = Coordinate::columnIndexFromString($oCR[0]) - 1;
$oRow[] = $oCR[1]; $oRow[] = $oCR[1];
} }
$cellRef = Cell::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Cell::stringFromColumnIndex(max($oCol)) . max($oRow); $cellRef = Coordinate::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Coordinate::stringFromColumnIndex(max($oCol)) . max($oRow);
if ($pCellParent !== null) { if ($pCellParent !== null) {
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($sheet1), false); $cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($sheet1), false);
} else { } else {
@ -3564,11 +3565,11 @@ class Calculation
foreach (array_keys($rowIntersect) as $row) { foreach (array_keys($rowIntersect) as $row) {
$oRow[] = $row; $oRow[] = $row;
foreach ($rowIntersect[$row] as $col => $data) { foreach ($rowIntersect[$row] as $col => $data) {
$oCol[] = Cell::columnIndexFromString($col) - 1; $oCol[] = Coordinate::columnIndexFromString($col) - 1;
$cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]); $cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]);
} }
} }
$cellRef = Cell::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Cell::stringFromColumnIndex(max($oCol)) . max($oRow); $cellRef = Coordinate::stringFromColumnIndex(min($oCol)) . min($oRow) . ':' . Coordinate::stringFromColumnIndex(max($oCol)) . max($oRow);
$this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($cellIntersect)); $this->debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($cellIntersect));
$stack->push('Value', $cellIntersect, $cellRef); $stack->push('Value', $cellIntersect, $cellRef);
@ -4103,7 +4104,7 @@ class Calculation
} }
// Extract range // Extract range
$aReferences = Cell::extractAllCellReferencesInRange($pRange); $aReferences = Coordinate::extractAllCellReferencesInRange($pRange);
$pRange = $pSheetName . '!' . $pRange; $pRange = $pSheetName . '!' . $pRange;
if (!isset($aReferences[1])) { if (!isset($aReferences[1])) {
// Single cell in range // Single cell in range
@ -4158,7 +4159,7 @@ class Calculation
if ($namedRange !== null) { if ($namedRange !== null) {
$pSheet = $namedRange->getWorksheet(); $pSheet = $namedRange->getWorksheet();
$pRange = $namedRange->getRange(); $pRange = $namedRange->getRange();
$splitRange = Cell::splitRange($pRange); $splitRange = Coordinate::splitRange($pRange);
// Convert row and column references // Convert row and column references
if (ctype_alpha($splitRange[0][0])) { if (ctype_alpha($splitRange[0][0])) {
$pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow(); $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
@ -4170,10 +4171,10 @@ class Calculation
} }
// Extract range // Extract range
$aReferences = Cell::extractAllCellReferencesInRange($pRange); $aReferences = Coordinate::extractAllCellReferencesInRange($pRange);
if (!isset($aReferences[1])) { if (!isset($aReferences[1])) {
// Single cell (or single column or row) in range // Single cell (or single column or row) in range
list($currentCol, $currentRow) = Cell::coordinateFromString($aReferences[0]); list($currentCol, $currentRow) = Coordinate::coordinateFromString($aReferences[0]);
if ($pSheet->cellExists($aReferences[0])) { if ($pSheet->cellExists($aReferences[0])) {
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog); $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
} else { } else {
@ -4183,7 +4184,7 @@ class Calculation
// Extract cell data for all cells in the range // Extract cell data for all cells in the range
foreach ($aReferences as $reference) { foreach ($aReferences as $reference) {
// Extract range // Extract range
list($currentCol, $currentRow) = Cell::coordinateFromString($reference); list($currentCol, $currentRow) = Coordinate::coordinateFromString($reference);
if ($pSheet->cellExists($reference)) { if ($pSheet->cellExists($reference)) {
$returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog); $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
} else { } else {

View File

@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation; namespace PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
class LookupRef class LookupRef
{ {
@ -52,7 +53,7 @@ class LookupRef
} }
if ((!is_bool($referenceStyle)) || $referenceStyle) { if ((!is_bool($referenceStyle)) || $referenceStyle) {
$rowRelative = $columnRelative = '$'; $rowRelative = $columnRelative = '$';
$column = Cell::stringFromColumnIndex($column - 1); $column = Coordinate::stringFromColumnIndex($column - 1);
if (($relativity == 2) || ($relativity == 4)) { if (($relativity == 2) || ($relativity == 4)) {
$columnRelative = ''; $columnRelative = '';
} }
@ -98,7 +99,7 @@ class LookupRef
foreach ($cellAddress as $columnKey => $value) { foreach ($cellAddress as $columnKey => $value) {
$columnKey = preg_replace('/[^a-z]/i', '', $columnKey); $columnKey = preg_replace('/[^a-z]/i', '', $columnKey);
return (int) Cell::columnIndexFromString($columnKey); return (int) Coordinate::columnIndexFromString($columnKey);
} }
} else { } else {
if (strpos($cellAddress, '!') !== false) { if (strpos($cellAddress, '!') !== false) {
@ -110,14 +111,14 @@ class LookupRef
$endAddress = preg_replace('/[^a-z]/i', '', $endAddress); $endAddress = preg_replace('/[^a-z]/i', '', $endAddress);
$returnValue = []; $returnValue = [];
do { do {
$returnValue[] = (int) Cell::columnIndexFromString($startAddress); $returnValue[] = (int) Coordinate::columnIndexFromString($startAddress);
} while ($startAddress++ != $endAddress); } while ($startAddress++ != $endAddress);
return $returnValue; return $returnValue;
} }
$cellAddress = preg_replace('/[^a-z]/i', '', $cellAddress); $cellAddress = preg_replace('/[^a-z]/i', '', $cellAddress);
return (int) Cell::columnIndexFromString($cellAddress); return (int) Coordinate::columnIndexFromString($cellAddress);
} }
} }
@ -382,23 +383,23 @@ class LookupRef
} else { } else {
$startCell = $endCell = $cellAddress; $startCell = $endCell = $cellAddress;
} }
list($startCellColumn, $startCellRow) = Cell::coordinateFromString($startCell); list($startCellColumn, $startCellRow) = Coordinate::coordinateFromString($startCell);
list($endCellColumn, $endCellRow) = Cell::coordinateFromString($endCell); list($endCellColumn, $endCellRow) = Coordinate::coordinateFromString($endCell);
$startCellRow += $rows; $startCellRow += $rows;
$startCellColumn = Cell::columnIndexFromString($startCellColumn) - 1; $startCellColumn = Coordinate::columnIndexFromString($startCellColumn) - 1;
$startCellColumn += $columns; $startCellColumn += $columns;
if (($startCellRow <= 0) || ($startCellColumn < 0)) { if (($startCellRow <= 0) || ($startCellColumn < 0)) {
return Functions::REF(); return Functions::REF();
} }
$endCellColumn = Cell::columnIndexFromString($endCellColumn) - 1; $endCellColumn = Coordinate::columnIndexFromString($endCellColumn) - 1;
if (($width != null) && (!is_object($width))) { if (($width != null) && (!is_object($width))) {
$endCellColumn = $startCellColumn + $width - 1; $endCellColumn = $startCellColumn + $width - 1;
} else { } else {
$endCellColumn += $columns; $endCellColumn += $columns;
} }
$startCellColumn = Cell::stringFromColumnIndex($startCellColumn); $startCellColumn = Coordinate::stringFromColumnIndex($startCellColumn);
if (($height != null) && (!is_object($height))) { if (($height != null) && (!is_object($height))) {
$endCellRow = $startCellRow + $height - 1; $endCellRow = $startCellRow + $height - 1;
@ -409,7 +410,7 @@ class LookupRef
if (($endCellRow <= 0) || ($endCellColumn < 0)) { if (($endCellRow <= 0) || ($endCellColumn < 0)) {
return Functions::REF(); return Functions::REF();
} }
$endCellColumn = Cell::stringFromColumnIndex($endCellColumn); $endCellColumn = Coordinate::stringFromColumnIndex($endCellColumn);
$cellAddress = $startCellColumn . $startCellRow; $cellAddress = $startCellColumn . $startCellRow;
if (($startCellColumn != $endCellColumn) || ($startCellRow != $endCellRow)) { if (($startCellColumn != $endCellColumn) || ($startCellRow != $endCellRow)) {

View File

@ -12,13 +12,6 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class Cell class Cell
{ {
/**
* Default range variable constant.
*
* @var string
*/
const DEFAULT_RANGE = 'A1:A1';
/** /**
* Value binder to use. * Value binder to use.
* *
@ -516,7 +509,7 @@ class Cell
public function isMergeRangeValueCell() public function isMergeRangeValueCell()
{ {
if ($mergeRange = $this->getMergeRange()) { if ($mergeRange = $this->getMergeRange()) {
$mergeRange = self::splitRange($mergeRange); $mergeRange = Coordinate::splitRange($mergeRange);
list($startCell) = $mergeRange[0]; list($startCell) = $mergeRange[0];
if ($this->getCoordinate() === $startCell) { if ($this->getCoordinate() === $startCell) {
return true; return true;
@ -575,10 +568,10 @@ class Cell
*/ */
public function isInRange($pRange) public function isInRange($pRange)
{ {
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($pRange);
// Translate properties // Translate properties
$myColumn = self::columnIndexFromString($this->getColumn()); $myColumn = Coordinate::columnIndexFromString($this->getColumn());
$myRow = $this->getRow(); $myRow = $this->getRow();
// Verify if cell is in range // Verify if cell is in range
@ -586,447 +579,6 @@ class Cell
($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow); ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow);
} }
/**
* Coordinate from string.
*
* @param string $pCoordinateString eg: 'A1'
*
* @throws Exception
*
* @return string[] Array containing column and row (indexes 0 and 1)
*/
public static function coordinateFromString($pCoordinateString)
{
if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
return [$matches[1], $matches[2]];
} elseif ((strpos($pCoordinateString, ':') !== false) || (strpos($pCoordinateString, ',') !== false)) {
throw new Exception('Cell coordinate string can not be a range of cells');
} elseif ($pCoordinateString == '') {
throw new Exception('Cell coordinate can not be zero-length string');
}
throw new Exception('Invalid cell coordinate ' . $pCoordinateString);
}
/**
* Make string row, column or cell coordinate absolute.
*
* @param string $pCoordinateString e.g. 'A' or '1' or 'A1'
* Note that this value can be a row or column reference as well as a cell reference
*
* @throws Exception
*
* @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
*/
public static function absoluteReference($pCoordinateString)
{
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
// Split out any worksheet name from the reference
$worksheet = '';
$cellAddress = explode('!', $pCoordinateString);
if (count($cellAddress) > 1) {
list($worksheet, $pCoordinateString) = $cellAddress;
}
if ($worksheet > '') {
$worksheet .= '!';
}
// Create absolute coordinate
if (ctype_digit($pCoordinateString)) {
return $worksheet . '$' . $pCoordinateString;
} elseif (ctype_alpha($pCoordinateString)) {
return $worksheet . '$' . strtoupper($pCoordinateString);
}
return $worksheet . self::absoluteCoordinate($pCoordinateString);
}
throw new Exception('Cell coordinate string can not be a range of cells');
}
/**
* Make string coordinate absolute.
*
* @param string $pCoordinateString e.g. 'A1'
*
* @throws Exception
*
* @return string Absolute coordinate e.g. '$A$1'
*/
public static function absoluteCoordinate($pCoordinateString)
{
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
// Split out any worksheet name from the coordinate
$worksheet = '';
$cellAddress = explode('!', $pCoordinateString);
if (count($cellAddress) > 1) {
list($worksheet, $pCoordinateString) = $cellAddress;
}
if ($worksheet > '') {
$worksheet .= '!';
}
// Create absolute coordinate
list($column, $row) = self::coordinateFromString($pCoordinateString);
$column = ltrim($column, '$');
$row = ltrim($row, '$');
return $worksheet . '$' . $column . '$' . $row;
}
throw new Exception('Cell coordinate string can not be a range of cells');
}
/**
* Split range into coordinate strings.
*
* @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4'
*
* @return array Array containg one or more arrays containing one or two coordinate strings
* e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11'))
* or array('B4')
*/
public static function splitRange($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
$exploded = explode(',', $pRange);
$counter = count($exploded);
for ($i = 0; $i < $counter; ++$i) {
$exploded[$i] = explode(':', $exploded[$i]);
}
return $exploded;
}
/**
* Build range from coordinate strings.
*
* @param array $pRange Array containg one or more arrays containing one or two coordinate strings
*
* @throws Exception
*
* @return string String representation of $pRange
*/
public static function buildRange(array $pRange)
{
// Verify range
if (empty($pRange) || !is_array($pRange[0])) {
throw new Exception('Range does not contain any information');
}
// Build range
$imploded = [];
$counter = count($pRange);
for ($i = 0; $i < $counter; ++$i) {
$pRange[$i] = implode(':', $pRange[$i]);
}
$imploded = implode(',', $pRange);
return $imploded;
}
/**
* Calculate range boundaries.
*
* @param string $pRange Cell range (e.g. A1:A1)
*
* @return array Range coordinates array(Start Cell, End Cell)
* where Start Cell and End Cell are arrays (Column Number, Row Number)
*/
public static function rangeBoundaries($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
if (strpos($pRange, ':') === false) {
$rangeA = $rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
// Calculate range outer borders
$rangeStart = self::coordinateFromString($rangeA);
$rangeEnd = self::coordinateFromString($rangeB);
// Translate column into index
$rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
$rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
return [$rangeStart, $rangeEnd];
}
/**
* Calculate range dimension.
*
* @param string $pRange Cell range (e.g. A1:A1)
*
* @return array Range dimension (width, height)
*/
public static function rangeDimension($pRange)
{
// Calculate range outer borders
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
return [($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1)];
}
/**
* Calculate range boundaries.
*
* @param string $pRange Cell range (e.g. A1:A1)
*
* @return array Range coordinates array(Start Cell, End Cell)
* where Start Cell and End Cell are arrays (Column ID, Row Number)
*/
public static function getRangeBoundaries($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
if (strpos($pRange, ':') === false) {
$rangeA = $rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
return [self::coordinateFromString($rangeA), self::coordinateFromString($rangeB)];
}
/**
* Column index from string.
*
* @param string $pString eg 'A'
*
* @return int Column index (base 1 !!!)
*/
public static function columnIndexFromString($pString)
{
// Using a lookup cache adds a slight memory overhead, but boosts speed
// caching using a static within the method is faster than a class static,
// though it's additional memory overhead
static $indexCache = [];
if (isset($indexCache[$pString])) {
return $indexCache[$pString];
}
// It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
// and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
// memory overhead either
static $columnLookup = [
'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26,
'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13,
'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26,
];
// We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
// for improved performance
if (isset($pString[0])) {
if (!isset($pString[1])) {
$indexCache[$pString] = $columnLookup[$pString];
return $indexCache[$pString];
} elseif (!isset($pString[2])) {
$indexCache[$pString] = $columnLookup[$pString[0]] * 26 + $columnLookup[$pString[1]];
return $indexCache[$pString];
} elseif (!isset($pString[3])) {
$indexCache[$pString] = $columnLookup[$pString[0]] * 676 + $columnLookup[$pString[1]] * 26 + $columnLookup[$pString[2]];
return $indexCache[$pString];
}
}
throw new Exception('Column string index can not be ' . ((isset($pString[0])) ? 'longer than 3 characters' : 'empty'));
}
/**
* String from columnindex.
*
* @param int $columnIndex Column index (A = 0)
*
* @return string
*/
public static function stringFromColumnIndex($columnIndex)
{
static $indexCache = [];
if (!isset($indexCache[$columnIndex])) {
$indexValue = $columnIndex + 1;
$base26 = null;
do {
$characterValue = ($indexValue % 26) ?: 26;
$indexValue = ($indexValue - $characterValue) / 26;
$base26 = chr($characterValue + 64) . ($base26 ?: '');
} while ($indexValue > 0);
$indexCache[$columnIndex] = $base26;
}
return $indexCache[$columnIndex];
}
/**
* Extract all cell references in range.
*
* @param string $pRange Range (e.g. A1 or A1:C10 or A1:E10 A20:E25)
*
* @return array Array containing single cell references
*/
public static function extractAllCellReferencesInRange($pRange)
{
// Returnvalue
$returnValue = [];
// Explode spaces
$cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange)));
foreach ($cellBlocks as $cellBlock) {
// Single cell?
if (strpos($cellBlock, ':') === false && strpos($cellBlock, ',') === false) {
$returnValue[] = $cellBlock;
continue;
}
// Range...
$ranges = self::splitRange($cellBlock);
foreach ($ranges as $range) {
// Single cell?
if (!isset($range[1])) {
$returnValue[] = $range[0];
continue;
}
// Range...
list($rangeStart, $rangeEnd) = $range;
sscanf($rangeStart, '%[A-Z]%d', $startCol, $startRow);
sscanf($rangeEnd, '%[A-Z]%d', $endCol, $endRow);
++$endCol;
// Current data
$currentCol = $startCol;
$currentRow = $startRow;
// Loop cells
while ($currentCol != $endCol) {
while ($currentRow <= $endRow) {
$returnValue[] = $currentCol . $currentRow;
++$currentRow;
}
++$currentCol;
$currentRow = $startRow;
}
}
}
// Sort the result by column and row
$sortKeys = [];
foreach (array_unique($returnValue) as $coord) {
sscanf($coord, '%[A-Z]%d', $column, $row);
$sortKeys[sprintf('%3s%09d', $column, $row)] = $coord;
}
ksort($sortKeys);
// Return value
return array_values($sortKeys);
}
/**
* Convert an associative array of single cell coordinates to values to an associative array
* of cell ranges to values. Only adjacent cell coordinates with the same
* value will be merged. If the value is an object, it must implement the method getHashCode().
*
* For example, this function converts:
*
* [ 'A1' => 'x', 'A2' => 'x', 'A3' => 'x', 'A4' => 'y' ]
*
* to:
*
* [ 'A1:A3' => 'x', 'A4' => 'y' ]
*
* @param array $pCoordCollection associative array mapping coordinates to values
*
* @return array associative array mapping coordinate ranges to valuea
*/
public static function mergeRangesInCollection(array $pCoordCollection)
{
$hashedValues = [];
foreach ($pCoordCollection as $coord => $value) {
list($column, $row) = self::coordinateFromString($coord);
$row = (int) (ltrim($row, '$'));
$hashCode = $column . '-' . (is_object($value) ? $value->getHashCode() : $value);
if (!isset($hashedValues[$hashCode])) {
$hashedValues[$hashCode] = (object) [
'value' => $value,
'col' => $column,
'rows' => [$row],
];
} else {
$hashedValues[$hashCode]->rows[] = $row;
}
}
$mergedCoordCollection = [];
ksort($hashedValues);
foreach ($hashedValues as $hashedValue) {
sort($hashedValue->rows);
$rowStart = null;
$rowEnd = null;
$ranges = [];
foreach ($hashedValue->rows as $row) {
if ($rowStart === null) {
$rowStart = $row;
$rowEnd = $row;
} elseif ($rowEnd === $row - 1) {
$rowEnd = $row;
} else {
if ($rowStart == $rowEnd) {
$ranges[] = $hashedValue->col . $rowStart;
} else {
$ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd;
}
$rowStart = $row;
$rowEnd = $row;
}
}
if ($rowStart !== null) {
if ($rowStart == $rowEnd) {
$ranges[] = $hashedValue->col . $rowStart;
} else {
$ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd;
}
}
foreach ($ranges as $range) {
$mergedCoordCollection[$range] = $hashedValue->value;
}
}
return $mergedCoordCollection;
}
/** /**
* Compare 2 cells. * Compare 2 cells.
* *
@ -1041,7 +593,7 @@ class Cell
return -1; return -1;
} elseif ($a->getRow() > $b->getRow()) { } elseif ($a->getRow() > $b->getRow()) {
return 1; return 1;
} elseif (self::columnIndexFromString($a->getColumn()) < self::columnIndexFromString($b->getColumn())) { } elseif (Coordinate::columnIndexFromString($a->getColumn()) < Coordinate::columnIndexFromString($b->getColumn())) {
return -1; return -1;
} }

View File

@ -0,0 +1,456 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\Exception;
abstract class Coordinate
{
/**
* Default range variable constant.
*
* @var string
*/
const DEFAULT_RANGE = 'A1:A1';
/**
* Coordinate from string.
*
* @param string $pCoordinateString eg: 'A1'
*
* @throws Exception
*
* @return string[] Array containing column and row (indexes 0 and 1)
*/
public static function coordinateFromString($pCoordinateString)
{
if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
return [$matches[1], $matches[2]];
} elseif ((strpos($pCoordinateString, ':') !== false) || (strpos($pCoordinateString, ',') !== false)) {
throw new Exception('Cell coordinate string can not be a range of cells');
} elseif ($pCoordinateString == '') {
throw new Exception('Cell coordinate can not be zero-length string');
}
throw new Exception('Invalid cell coordinate ' . $pCoordinateString);
}
/**
* Make string row, column or cell coordinate absolute.
*
* @param string $pCoordinateString e.g. 'A' or '1' or 'A1'
* Note that this value can be a row or column reference as well as a cell reference
*
* @throws Exception
*
* @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
*/
public static function absoluteReference($pCoordinateString)
{
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
// Split out any worksheet name from the reference
$worksheet = '';
$cellAddress = explode('!', $pCoordinateString);
if (count($cellAddress) > 1) {
list($worksheet, $pCoordinateString) = $cellAddress;
}
if ($worksheet > '') {
$worksheet .= '!';
}
// Create absolute coordinate
if (ctype_digit($pCoordinateString)) {
return $worksheet . '$' . $pCoordinateString;
} elseif (ctype_alpha($pCoordinateString)) {
return $worksheet . '$' . strtoupper($pCoordinateString);
}
return $worksheet . self::absoluteCoordinate($pCoordinateString);
}
throw new Exception('Cell coordinate string can not be a range of cells');
}
/**
* Make string coordinate absolute.
*
* @param string $pCoordinateString e.g. 'A1'
*
* @throws Exception
*
* @return string Absolute coordinate e.g. '$A$1'
*/
public static function absoluteCoordinate($pCoordinateString)
{
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
// Split out any worksheet name from the coordinate
$worksheet = '';
$cellAddress = explode('!', $pCoordinateString);
if (count($cellAddress) > 1) {
list($worksheet, $pCoordinateString) = $cellAddress;
}
if ($worksheet > '') {
$worksheet .= '!';
}
// Create absolute coordinate
list($column, $row) = self::coordinateFromString($pCoordinateString);
$column = ltrim($column, '$');
$row = ltrim($row, '$');
return $worksheet . '$' . $column . '$' . $row;
}
throw new Exception('Cell coordinate string can not be a range of cells');
}
/**
* Split range into coordinate strings.
*
* @param string $pRange e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4'
*
* @return array Array containg one or more arrays containing one or two coordinate strings
* e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11'))
* or array('B4')
*/
public static function splitRange($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
$exploded = explode(',', $pRange);
$counter = count($exploded);
for ($i = 0; $i < $counter; ++$i) {
$exploded[$i] = explode(':', $exploded[$i]);
}
return $exploded;
}
/**
* Build range from coordinate strings.
*
* @param array $pRange Array containg one or more arrays containing one or two coordinate strings
*
* @throws Exception
*
* @return string String representation of $pRange
*/
public static function buildRange(array $pRange)
{
// Verify range
if (empty($pRange) || !is_array($pRange[0])) {
throw new Exception('Range does not contain any information');
}
// Build range
$imploded = [];
$counter = count($pRange);
for ($i = 0; $i < $counter; ++$i) {
$pRange[$i] = implode(':', $pRange[$i]);
}
$imploded = implode(',', $pRange);
return $imploded;
}
/**
* Calculate range boundaries.
*
* @param string $pRange Cell range (e.g. A1:A1)
*
* @return array Range coordinates array(Start Cell, End Cell)
* where Start Cell and End Cell are arrays (Column Number, Row Number)
*/
public static function rangeBoundaries($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
if (strpos($pRange, ':') === false) {
$rangeA = $rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
// Calculate range outer borders
$rangeStart = self::coordinateFromString($rangeA);
$rangeEnd = self::coordinateFromString($rangeB);
// Translate column into index
$rangeStart[0] = self::columnIndexFromString($rangeStart[0]);
$rangeEnd[0] = self::columnIndexFromString($rangeEnd[0]);
return [$rangeStart, $rangeEnd];
}
/**
* Calculate range dimension.
*
* @param string $pRange Cell range (e.g. A1:A1)
*
* @return array Range dimension (width, height)
*/
public static function rangeDimension($pRange)
{
// Calculate range outer borders
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
return [($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1)];
}
/**
* Calculate range boundaries.
*
* @param string $pRange Cell range (e.g. A1:A1)
*
* @return array Range coordinates array(Start Cell, End Cell)
* where Start Cell and End Cell are arrays (Column ID, Row Number)
*/
public static function getRangeBoundaries($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
$pRange = self::DEFAULT_RANGE;
}
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
if (strpos($pRange, ':') === false) {
$rangeA = $rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
return [self::coordinateFromString($rangeA), self::coordinateFromString($rangeB)];
}
/**
* Column index from string.
*
* @param string $pString eg 'A'
*
* @return int Column index (base 1 !!!)
*/
public static function columnIndexFromString($pString)
{
// Using a lookup cache adds a slight memory overhead, but boosts speed
// caching using a static within the method is faster than a class static,
// though it's additional memory overhead
static $indexCache = [];
if (isset($indexCache[$pString])) {
return $indexCache[$pString];
}
// It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
// and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
// memory overhead either
static $columnLookup = [
'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26,
'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13,
'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26,
];
// We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
// for improved performance
if (isset($pString[0])) {
if (!isset($pString[1])) {
$indexCache[$pString] = $columnLookup[$pString];
return $indexCache[$pString];
} elseif (!isset($pString[2])) {
$indexCache[$pString] = $columnLookup[$pString[0]] * 26 + $columnLookup[$pString[1]];
return $indexCache[$pString];
} elseif (!isset($pString[3])) {
$indexCache[$pString] = $columnLookup[$pString[0]] * 676 + $columnLookup[$pString[1]] * 26 + $columnLookup[$pString[2]];
return $indexCache[$pString];
}
}
throw new Exception('Column string index can not be ' . ((isset($pString[0])) ? 'longer than 3 characters' : 'empty'));
}
/**
* String from columnindex.
*
* @param int $columnIndex Column index (A = 0)
*
* @return string
*/
public static function stringFromColumnIndex($columnIndex)
{
static $indexCache = [];
if (!isset($indexCache[$columnIndex])) {
$indexValue = $columnIndex + 1;
$base26 = null;
do {
$characterValue = ($indexValue % 26) ?: 26;
$indexValue = ($indexValue - $characterValue) / 26;
$base26 = chr($characterValue + 64) . ($base26 ?: '');
} while ($indexValue > 0);
$indexCache[$columnIndex] = $base26;
}
return $indexCache[$columnIndex];
}
/**
* Extract all cell references in range.
*
* @param string $pRange Range (e.g. A1 or A1:C10 or A1:E10 A20:E25)
*
* @return array Array containing single cell references
*/
public static function extractAllCellReferencesInRange($pRange)
{
// Returnvalue
$returnValue = [];
// Explode spaces
$cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange)));
foreach ($cellBlocks as $cellBlock) {
// Single cell?
if (strpos($cellBlock, ':') === false && strpos($cellBlock, ',') === false) {
$returnValue[] = $cellBlock;
continue;
}
// Range...
$ranges = self::splitRange($cellBlock);
foreach ($ranges as $range) {
// Single cell?
if (!isset($range[1])) {
$returnValue[] = $range[0];
continue;
}
// Range...
list($rangeStart, $rangeEnd) = $range;
sscanf($rangeStart, '%[A-Z]%d', $startCol, $startRow);
sscanf($rangeEnd, '%[A-Z]%d', $endCol, $endRow);
++$endCol;
// Current data
$currentCol = $startCol;
$currentRow = $startRow;
// Loop cells
while ($currentCol != $endCol) {
while ($currentRow <= $endRow) {
$returnValue[] = $currentCol . $currentRow;
++$currentRow;
}
++$currentCol;
$currentRow = $startRow;
}
}
}
// Sort the result by column and row
$sortKeys = [];
foreach (array_unique($returnValue) as $coord) {
sscanf($coord, '%[A-Z]%d', $column, $row);
$sortKeys[sprintf('%3s%09d', $column, $row)] = $coord;
}
ksort($sortKeys);
// Return value
return array_values($sortKeys);
}
/**
* Convert an associative array of single cell coordinates to values to an associative array
* of cell ranges to values. Only adjacent cell coordinates with the same
* value will be merged. If the value is an object, it must implement the method getHashCode().
*
* For example, this function converts:
*
* [ 'A1' => 'x', 'A2' => 'x', 'A3' => 'x', 'A4' => 'y' ]
*
* to:
*
* [ 'A1:A3' => 'x', 'A4' => 'y' ]
*
* @param array $pCoordCollection associative array mapping coordinates to values
*
* @return array associative array mapping coordinate ranges to valuea
*/
public static function mergeRangesInCollection(array $pCoordCollection)
{
$hashedValues = [];
foreach ($pCoordCollection as $coord => $value) {
list($column, $row) = self::coordinateFromString($coord);
$row = (int) (ltrim($row, '$'));
$hashCode = $column . '-' . (is_object($value) ? $value->getHashCode() : $value);
if (!isset($hashedValues[$hashCode])) {
$hashedValues[$hashCode] = (object) [
'value' => $value,
'col' => $column,
'rows' => [$row],
];
} else {
$hashedValues[$hashCode]->rows[] = $row;
}
}
$mergedCoordCollection = [];
ksort($hashedValues);
foreach ($hashedValues as $hashedValue) {
sort($hashedValue->rows);
$rowStart = null;
$rowEnd = null;
$ranges = [];
foreach ($hashedValue->rows as $row) {
if ($rowStart === null) {
$rowStart = $row;
$rowEnd = $row;
} elseif ($rowEnd === $row - 1) {
$rowEnd = $row;
} else {
if ($rowStart == $rowEnd) {
$ranges[] = $hashedValue->col . $rowStart;
} else {
$ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd;
}
$rowStart = $row;
$rowEnd = $row;
}
}
if ($rowStart !== null) {
if ($rowStart == $rowEnd) {
$ranges[] = $hashedValue->col . $rowStart;
} else {
$ranges[] = $hashedValue->col . $rowStart . ':' . $hashedValue->col . $rowEnd;
}
}
foreach ($ranges as $range) {
$mergedCoordCollection[$range] = $hashedValue->value;
}
}
return $mergedCoordCollection;
}
}

View File

@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class DataSeriesValues class DataSeriesValues
@ -327,7 +327,7 @@ class DataSeriesValues
list(, $cellRange) = $cellRange; list(, $cellRange) = $cellRange;
} }
$dimensions = Cell::rangeDimension(str_replace('$', '', $cellRange)); $dimensions = Coordinate::rangeDimension(str_replace('$', '', $cellRange));
if (($dimensions[0] == 1) || ($dimensions[1] == 1)) { if (($dimensions[0] == 1) || ($dimensions[1] == 1)) {
$this->dataValues = Functions::flattenArray($newDataValues); $this->dataValues = Functions::flattenArray($newDataValues);
} else { } else {

View File

@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Collection; namespace PhpOffice\PhpSpreadsheet\Collection;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
@ -244,10 +245,10 @@ class Cells
if ($r != $row) { if ($r != $row) {
continue; continue;
} }
$columnList[] = Cell::columnIndexFromString($c); $columnList[] = Coordinate::columnIndexFromString($c);
} }
return Cell::stringFromColumnIndex(max($columnList) - 1); return Coordinate::stringFromColumnIndex(max($columnList) - 1);
} }
/** /**

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader; namespace PhpOffice\PhpSpreadsheet\Reader;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -251,7 +251,7 @@ class Csv extends BaseReader
$worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1); $worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1);
} }
$worksheetInfo[0]['lastColumnLetter'] = Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); $worksheetInfo[0]['lastColumnLetter'] = Coordinate::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']);
$worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1; $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;
// Close file // Close file

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader; namespace PhpOffice\PhpSpreadsheet\Reader;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\ReferenceHelper; use PhpOffice\PhpSpreadsheet\ReferenceHelper;
@ -138,7 +138,7 @@ class Gnumeric extends BaseReader
break; break;
} }
} }
$tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
$worksheetInfo[] = $tmpInfo; $worksheetInfo[] = $tmpInfo;
} }
} }
@ -394,7 +394,7 @@ class Gnumeric extends BaseReader
$maxCol = $column; $maxCol = $column;
} }
$column = Cell::stringFromColumnIndex($column); $column = Coordinate::stringFromColumnIndex($column);
// Read cell? // Read cell?
if ($this->getReadFilter() !== null) { if ($this->getReadFilter() !== null) {
@ -472,11 +472,11 @@ class Gnumeric extends BaseReader
$styleAttributes = $styleRegion->attributes(); $styleAttributes = $styleRegion->attributes();
if (($styleAttributes['startRow'] <= $maxRow) && if (($styleAttributes['startRow'] <= $maxRow) &&
($styleAttributes['startCol'] <= $maxCol)) { ($styleAttributes['startCol'] <= $maxCol)) {
$startColumn = Cell::stringFromColumnIndex((int) $styleAttributes['startCol']); $startColumn = Coordinate::stringFromColumnIndex((int) $styleAttributes['startCol']);
$startRow = $styleAttributes['startRow'] + 1; $startRow = $styleAttributes['startRow'] + 1;
$endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol']; $endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol'];
$endColumn = Cell::stringFromColumnIndex($endColumn); $endColumn = Coordinate::stringFromColumnIndex($endColumn);
$endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow']; $endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow'];
$endRow += 1; $endRow += 1;
$cellRange = $startColumn . $startRow . ':' . $endColumn . $endRow; $cellRange = $startColumn . $startRow . ':' . $endColumn . $endRow;
@ -718,19 +718,19 @@ class Gnumeric extends BaseReader
$hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false; $hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false;
$columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1; $columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1;
while ($c < $column) { while ($c < $column) {
$spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); $spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c))->setWidth($defaultWidth);
++$c; ++$c;
} }
while (($c < ($column + $columnCount)) && ($c <= $maxCol)) { while (($c < ($column + $columnCount)) && ($c <= $maxCol)) {
$spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setWidth($columnWidth); $spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c))->setWidth($columnWidth);
if ($hidden) { if ($hidden) {
$spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setVisible(false); $spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c))->setVisible(false);
} }
++$c; ++$c;
} }
} }
while ($c <= $maxCol) { while ($c <= $maxCol) {
$spreadsheet->getActiveSheet()->getColumnDimension(Cell::stringFromColumnIndex($c))->setWidth($defaultWidth); $spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c))->setWidth($defaultWidth);
++$c; ++$c;
} }
} }

View File

@ -6,7 +6,7 @@ use DOMDocument;
use DOMElement; use DOMElement;
use DOMNode; use DOMNode;
use DOMText; use DOMText;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Style\Color;
@ -448,7 +448,7 @@ class Html extends BaseReader
++$columnTo; ++$columnTo;
} }
$range = $column . $row . ':' . $columnTo . ($row + $attributeArray['rowspan'] - 1); $range = $column . $row . ':' . $columnTo . ($row + $attributeArray['rowspan'] - 1);
foreach (Cell::extractAllCellReferencesInRange($range) as $value) { foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) {
$this->rowspan[$value] = true; $this->rowspan[$value] = true;
} }
$sheet->mergeCells($range); $sheet->mergeCells($range);
@ -456,7 +456,7 @@ class Html extends BaseReader
} elseif (isset($attributeArray['rowspan'])) { } elseif (isset($attributeArray['rowspan'])) {
//create merging rowspan //create merging rowspan
$range = $column . $row . ':' . $column . ($row + $attributeArray['rowspan'] - 1); $range = $column . $row . ':' . $column . ($row + $attributeArray['rowspan'] - 1);
foreach (Cell::extractAllCellReferencesInRange($range) as $value) { foreach (Coordinate::extractAllCellReferencesInRange($range) as $value) {
$this->rowspan[$value] = true; $this->rowspan[$value] = true;
} }
$sheet->mergeCells($range); $sheet->mergeCells($range);

View File

@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader;
use DateTime; use DateTime;
use DateTimeZone; use DateTimeZone;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
@ -215,7 +215,7 @@ class Ods extends BaseReader
$tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'], $currCells); $tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'], $currCells);
$tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1; $tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1;
$tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
$worksheetInfo[] = $tmpInfo; $worksheetInfo[] = $tmpInfo;
} }
} }
@ -703,11 +703,11 @@ class Ods extends BaseReader
$columnTo = $columnID; $columnTo = $columnID;
if ($cellData->hasAttributeNS($tableNs, 'number-columns-spanned')) { if ($cellData->hasAttributeNS($tableNs, 'number-columns-spanned')) {
$columnIndex = Cell::columnIndexFromString($columnID); $columnIndex = Coordinate::columnIndexFromString($columnID);
$columnIndex += (int) $cellData->getAttributeNS($tableNs, 'number-columns-spanned'); $columnIndex += (int) $cellData->getAttributeNS($tableNs, 'number-columns-spanned');
$columnIndex -= 2; $columnIndex -= 2;
$columnTo = Cell::stringFromColumnIndex($columnIndex); $columnTo = Coordinate::stringFromColumnIndex($columnIndex);
} }
$rowTo = $rowID; $rowTo = $rowID;

View File

@ -3,7 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader; namespace PhpOffice\PhpSpreadsheet\Reader;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Border;
@ -161,7 +161,7 @@ class Slk extends BaseReader
} }
} }
$worksheetInfo[0]['lastColumnLetter'] = Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']); $worksheetInfo[0]['lastColumnLetter'] = Coordinate::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']);
$worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1; $worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;
// Close file // Close file
@ -337,7 +337,7 @@ class Slk extends BaseReader
if ($columnReference[0] == '[') { if ($columnReference[0] == '[') {
$columnReference = $column + trim($columnReference, '[]'); $columnReference = $column + trim($columnReference, '[]');
} }
$A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; $A1CellReference = Coordinate::stringFromColumnIndex($columnReference - 1) . $rowReference;
$value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0]));
} }
@ -351,7 +351,7 @@ class Slk extends BaseReader
break; break;
} }
} }
$columnLetter = Cell::stringFromColumnIndex($column - 1); $columnLetter = Coordinate::stringFromColumnIndex($column - 1);
$cellData = Calculation::unwrapResult($cellData); $cellData = Calculation::unwrapResult($cellData);
// Set cell value // Set cell value
@ -419,22 +419,22 @@ class Slk extends BaseReader
} }
} }
if (($formatStyle > '') && ($column > '') && ($row > '')) { if (($formatStyle > '') && ($column > '') && ($row > '')) {
$columnLetter = Cell::stringFromColumnIndex($column - 1); $columnLetter = Coordinate::stringFromColumnIndex($column - 1);
if (isset($this->formats[$formatStyle])) { if (isset($this->formats[$formatStyle])) {
$spreadsheet->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($this->formats[$formatStyle]); $spreadsheet->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($this->formats[$formatStyle]);
} }
} }
if ((!empty($styleData)) && ($column > '') && ($row > '')) { if ((!empty($styleData)) && ($column > '') && ($row > '')) {
$columnLetter = Cell::stringFromColumnIndex($column - 1); $columnLetter = Coordinate::stringFromColumnIndex($column - 1);
$spreadsheet->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($styleData); $spreadsheet->getActiveSheet()->getStyle($columnLetter . $row)->applyFromArray($styleData);
} }
if ($columnWidth > '') { if ($columnWidth > '') {
if ($startCol == $endCol) { if ($startCol == $endCol) {
$startCol = Cell::stringFromColumnIndex($startCol - 1); $startCol = Coordinate::stringFromColumnIndex($startCol - 1);
$spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
} else { } else {
$startCol = Cell::stringFromColumnIndex($startCol - 1); $startCol = Coordinate::stringFromColumnIndex($startCol - 1);
$endCol = Cell::stringFromColumnIndex($endCol - 1); $endCol = Coordinate::stringFromColumnIndex($endCol - 1);
$spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth); $spreadsheet->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
do { do {
$spreadsheet->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth); $spreadsheet->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth);

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader; namespace PhpOffice\PhpSpreadsheet\Reader;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation; use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
@ -602,7 +602,7 @@ class Xls extends BaseReader
} }
} }
$tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
$tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
$worksheetInfo[] = $tmpInfo; $worksheetInfo[] = $tmpInfo;
@ -1087,8 +1087,8 @@ class Xls extends BaseReader
} }
// calculate the width and height of the shape // calculate the width and height of the shape
list($startColumn, $startRow) = Cell::coordinateFromString($spContainer->getStartCoordinates()); list($startColumn, $startRow) = Coordinate::coordinateFromString($spContainer->getStartCoordinates());
list($endColumn, $endRow) = Cell::coordinateFromString($spContainer->getEndCoordinates()); list($endColumn, $endRow) = Coordinate::coordinateFromString($spContainer->getEndCoordinates());
$startOffsetX = $spContainer->getStartOffsetX(); $startOffsetX = $spContainer->getStartOffsetX();
$startOffsetY = $spContainer->getStartOffsetY(); $startOffsetY = $spContainer->getStartOffsetY();
@ -1173,7 +1173,7 @@ class Xls extends BaseReader
// treat SHAREDFMLA records // treat SHAREDFMLA records
if ($this->version == self::XLS_BIFF8) { if ($this->version == self::XLS_BIFF8) {
foreach ($this->sharedFormulaParts as $cell => $baseCell) { foreach ($this->sharedFormulaParts as $cell => $baseCell) {
list($column, $row) = Cell::coordinateFromString($cell); list($column, $row) = Coordinate::coordinateFromString($cell);
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($column, $row, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($column, $row, $this->phpSheet->getTitle())) {
$formula = $this->getFormulaFromStructure($this->sharedFormulas[$baseCell], $cell); $formula = $this->getFormulaFromStructure($this->sharedFormulas[$baseCell], $cell);
$this->phpSheet->getCell($cell)->setValueExplicit('=' . $formula, DataType::TYPE_FORMULA); $this->phpSheet->getCell($cell)->setValueExplicit('=' . $formula, DataType::TYPE_FORMULA);
@ -1249,8 +1249,8 @@ class Xls extends BaseReader
$coordinateStrings = explode(':', $extractedRange); $coordinateStrings = explode(':', $extractedRange);
if (count($coordinateStrings) == 2) { if (count($coordinateStrings) == 2) {
list($firstColumn, $firstRow) = Cell::coordinateFromString($coordinateStrings[0]); list($firstColumn, $firstRow) = Coordinate::coordinateFromString($coordinateStrings[0]);
list($lastColumn, $lastRow) = Cell::coordinateFromString($coordinateStrings[1]); list($lastColumn, $lastRow) = Coordinate::coordinateFromString($coordinateStrings[1]);
if ($firstColumn == 'A' and $lastColumn == 'IV') { if ($firstColumn == 'A' and $lastColumn == 'IV') {
// then we have repeating rows // then we have repeating rows
@ -3723,7 +3723,7 @@ class Xls extends BaseReader
// offset: 2; size: 2; index to column // offset: 2; size: 2; index to column
$column = self::getUInt2d($recordData, 2); $column = self::getUInt2d($recordData, 2);
$columnString = Cell::stringFromColumnIndex($column); $columnString = Coordinate::stringFromColumnIndex($column);
// Read cell? // Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
@ -3767,7 +3767,7 @@ class Xls extends BaseReader
// offset: 2; size: 2; index to column // offset: 2; size: 2; index to column
$column = self::getUInt2d($recordData, 2); $column = self::getUInt2d($recordData, 2);
$columnString = Cell::stringFromColumnIndex($column); $columnString = Coordinate::stringFromColumnIndex($column);
$emptyCell = true; $emptyCell = true;
// Read cell? // Read cell?
@ -3860,7 +3860,7 @@ class Xls extends BaseReader
$offset = 4; $offset = 4;
for ($i = 0; $i < $columns; ++$i) { for ($i = 0; $i < $columns; ++$i) {
$columnString = Cell::stringFromColumnIndex($colFirst + $i); $columnString = Coordinate::stringFromColumnIndex($colFirst + $i);
// Read cell? // Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
@ -3904,7 +3904,7 @@ class Xls extends BaseReader
// offset: 2; size 2; index to column // offset: 2; size 2; index to column
$column = self::getUInt2d($recordData, 2); $column = self::getUInt2d($recordData, 2);
$columnString = Cell::stringFromColumnIndex($column); $columnString = Coordinate::stringFromColumnIndex($column);
// Read cell? // Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
@ -3945,7 +3945,7 @@ class Xls extends BaseReader
// offset: 2; size: 2; col index // offset: 2; size: 2; col index
$column = self::getUInt2d($recordData, 2); $column = self::getUInt2d($recordData, 2);
$columnString = Cell::stringFromColumnIndex($column); $columnString = Coordinate::stringFromColumnIndex($column);
// offset: 20: size: variable; formula structure // offset: 20: size: variable; formula structure
$formulaStructure = substr($recordData, 20); $formulaStructure = substr($recordData, 20);
@ -3969,7 +3969,7 @@ class Xls extends BaseReader
// get the base cell, grab tExp token // get the base cell, grab tExp token
$baseRow = self::getUInt2d($formulaStructure, 3); $baseRow = self::getUInt2d($formulaStructure, 3);
$baseCol = self::getUInt2d($formulaStructure, 5); $baseCol = self::getUInt2d($formulaStructure, 5);
$this->baseCell = Cell::stringFromColumnIndex($baseCol) . ($baseRow + 1); $this->baseCell = Coordinate::stringFromColumnIndex($baseCol) . ($baseRow + 1);
} }
// Read cell? // Read cell?
@ -4129,7 +4129,7 @@ class Xls extends BaseReader
// offset: 2; size: 2; column index // offset: 2; size: 2; column index
$column = self::getUInt2d($recordData, 2); $column = self::getUInt2d($recordData, 2);
$columnString = Cell::stringFromColumnIndex($column); $columnString = Coordinate::stringFromColumnIndex($column);
// Read cell? // Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
@ -4193,7 +4193,7 @@ class Xls extends BaseReader
// add style information // add style information
if (!$this->readDataOnly && $this->readEmptyCells) { if (!$this->readDataOnly && $this->readEmptyCells) {
for ($i = 0; $i < $length / 2 - 3; ++$i) { for ($i = 0; $i < $length / 2 - 3; ++$i) {
$columnString = Cell::stringFromColumnIndex($fc + $i); $columnString = Coordinate::stringFromColumnIndex($fc + $i);
// Read cell? // Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
@ -4229,7 +4229,7 @@ class Xls extends BaseReader
// offset: 2; size: 2; index to column // offset: 2; size: 2; index to column
$column = self::getUInt2d($recordData, 2); $column = self::getUInt2d($recordData, 2);
$columnString = Cell::stringFromColumnIndex($column); $columnString = Coordinate::stringFromColumnIndex($column);
// Read cell? // Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
@ -4273,7 +4273,7 @@ class Xls extends BaseReader
// offset: 2; size: 2; col index // offset: 2; size: 2; col index
$col = self::getUInt2d($recordData, 2); $col = self::getUInt2d($recordData, 2);
$columnString = Cell::stringFromColumnIndex($col); $columnString = Coordinate::stringFromColumnIndex($col);
// Read cell? // Read cell?
if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->phpSheet->getTitle())) {
@ -4490,7 +4490,7 @@ class Xls extends BaseReader
if ($this->frozen) { if ($this->frozen) {
// frozen panes // frozen panes
$this->phpSheet->freezePane(Cell::stringFromColumnIndex($px) . ($py + 1)); $this->phpSheet->freezePane(Coordinate::stringFromColumnIndex($px) . ($py + 1));
} }
// unfrozen panes; split windows; not supported by PhpSpreadsheet core // unfrozen panes; split windows; not supported by PhpSpreadsheet core
} }
@ -4551,7 +4551,7 @@ class Xls extends BaseReader
$includeCellRange = true; $includeCellRange = true;
if ($this->getReadFilter() !== null) { if ($this->getReadFilter() !== null) {
$includeCellRange = false; $includeCellRange = false;
$rangeBoundaries = Cell::getRangeBoundaries($cellRangeAddress); $rangeBoundaries = Coordinate::getRangeBoundaries($cellRangeAddress);
++$rangeBoundaries[1][0]; ++$rangeBoundaries[1][0];
for ($row = $rangeBoundaries[0][1]; $row <= $rangeBoundaries[1][1]; ++$row) { for ($row = $rangeBoundaries[0][1]; $row <= $rangeBoundaries[1][1]; ++$row) {
for ($column = $rangeBoundaries[0][0]; $column != $rangeBoundaries[1][0]; ++$column) { for ($column = $rangeBoundaries[0][0]; $column != $rangeBoundaries[1][0]; ++$column) {
@ -4762,7 +4762,7 @@ class Xls extends BaseReader
} }
// apply the hyperlink to all the relevant cells // apply the hyperlink to all the relevant cells
foreach (Cell::extractAllCellReferencesInRange($cellRange) as $coordinate) { foreach (Coordinate::extractAllCellReferencesInRange($cellRange) as $coordinate) {
$this->phpSheet->getCell($coordinate)->getHyperLink()->setUrl($url); $this->phpSheet->getCell($coordinate)->getHyperLink()->setUrl($url);
} }
} }
@ -4971,7 +4971,7 @@ class Xls extends BaseReader
foreach ($cellRangeAddresses as $cellRange) { foreach ($cellRangeAddresses as $cellRange) {
$stRange = $this->phpSheet->shrinkRangeToFit($cellRange); $stRange = $this->phpSheet->shrinkRangeToFit($cellRange);
foreach (Cell::extractAllCellReferencesInRange($stRange) as $coordinate) { foreach (Coordinate::extractAllCellReferencesInRange($stRange) as $coordinate) {
$objValidation = $this->phpSheet->getCell($coordinate)->getDataValidation(); $objValidation = $this->phpSheet->getCell($coordinate)->getDataValidation();
$objValidation->setType($type); $objValidation->setType($type);
$objValidation->setErrorStyle($errorStyle); $objValidation->setErrorStyle($errorStyle);
@ -7103,7 +7103,7 @@ class Xls extends BaseReader
// offset: 2; size: 2; index to column or column offset + relative flags // offset: 2; size: 2; index to column or column offset + relative flags
// bit: 7-0; mask 0x00FF; column index // bit: 7-0; mask 0x00FF; column index
$column = Cell::stringFromColumnIndex(0x00FF & self::getUInt2d($cellAddressStructure, 2)); $column = Coordinate::stringFromColumnIndex(0x00FF & self::getUInt2d($cellAddressStructure, 2));
// bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
if (!(0x4000 & self::getUInt2d($cellAddressStructure, 2))) { if (!(0x4000 & self::getUInt2d($cellAddressStructure, 2))) {
@ -7129,8 +7129,8 @@ class Xls extends BaseReader
*/ */
private function readBIFF8CellAddressB($cellAddressStructure, $baseCell = 'A1') private function readBIFF8CellAddressB($cellAddressStructure, $baseCell = 'A1')
{ {
list($baseCol, $baseRow) = Cell::coordinateFromString($baseCell); list($baseCol, $baseRow) = Coordinate::coordinateFromString($baseCell);
$baseCol = Cell::columnIndexFromString($baseCol) - 1; $baseCol = Coordinate::columnIndexFromString($baseCol) - 1;
// offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767)) // offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767))
$rowIndex = self::getUInt2d($cellAddressStructure, 0); $rowIndex = self::getUInt2d($cellAddressStructure, 0);
@ -7142,7 +7142,7 @@ class Xls extends BaseReader
// bit: 7-0; mask 0x00FF; column index // bit: 7-0; mask 0x00FF; column index
$colIndex = 0x00FF & self::getUInt2d($cellAddressStructure, 2); $colIndex = 0x00FF & self::getUInt2d($cellAddressStructure, 2);
$column = Cell::stringFromColumnIndex($colIndex); $column = Coordinate::stringFromColumnIndex($colIndex);
$column = '$' . $column; $column = '$' . $column;
} else { } else {
// offset: 2; size: 2; index to column or column offset + relative flags // offset: 2; size: 2; index to column or column offset + relative flags
@ -7151,7 +7151,7 @@ class Xls extends BaseReader
$colIndex = $baseCol + $relativeColIndex; $colIndex = $baseCol + $relativeColIndex;
$colIndex = ($colIndex < 256) ? $colIndex : $colIndex - 256; $colIndex = ($colIndex < 256) ? $colIndex : $colIndex - 256;
$colIndex = ($colIndex >= 0) ? $colIndex : $colIndex + 256; $colIndex = ($colIndex >= 0) ? $colIndex : $colIndex + 256;
$column = Cell::stringFromColumnIndex($colIndex); $column = Coordinate::stringFromColumnIndex($colIndex);
} }
// bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
@ -7196,8 +7196,8 @@ class Xls extends BaseReader
} }
// column index to letter // column index to letter
$fc = Cell::stringFromColumnIndex($fc); $fc = Coordinate::stringFromColumnIndex($fc);
$lc = Cell::stringFromColumnIndex($lc); $lc = Coordinate::stringFromColumnIndex($lc);
if ($fr == $lr and $fc == $lc) { if ($fr == $lr and $fc == $lc) {
return "$fc$fr"; return "$fc$fr";
@ -7237,8 +7237,8 @@ class Xls extends BaseReader
} }
// column index to letter // column index to letter
$fc = Cell::stringFromColumnIndex($fc); $fc = Coordinate::stringFromColumnIndex($fc);
$lc = Cell::stringFromColumnIndex($lc); $lc = Coordinate::stringFromColumnIndex($lc);
if ($fr == $lr and $fc == $lc) { if ($fr == $lr and $fc == $lc) {
return "$fc$fr"; return "$fc$fr";
@ -7270,7 +7270,7 @@ class Xls extends BaseReader
// offset: 4; size: 2; index to first column or column offset + relative flags // offset: 4; size: 2; index to first column or column offset + relative flags
// bit: 7-0; mask 0x00FF; column index // bit: 7-0; mask 0x00FF; column index
$fc = Cell::stringFromColumnIndex(0x00FF & self::getUInt2d($subData, 4)); $fc = Coordinate::stringFromColumnIndex(0x00FF & self::getUInt2d($subData, 4));
// bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
if (!(0x4000 & self::getUInt2d($subData, 4))) { if (!(0x4000 & self::getUInt2d($subData, 4))) {
@ -7285,7 +7285,7 @@ class Xls extends BaseReader
// offset: 6; size: 2; index to last column or column offset + relative flags // offset: 6; size: 2; index to last column or column offset + relative flags
// bit: 7-0; mask 0x00FF; column index // bit: 7-0; mask 0x00FF; column index
$lc = Cell::stringFromColumnIndex(0x00FF & self::getUInt2d($subData, 6)); $lc = Coordinate::stringFromColumnIndex(0x00FF & self::getUInt2d($subData, 6));
// bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index) // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
if (!(0x4000 & self::getUInt2d($subData, 6))) { if (!(0x4000 & self::getUInt2d($subData, 6))) {
@ -7312,8 +7312,8 @@ class Xls extends BaseReader
*/ */
private function readBIFF8CellRangeAddressB($subData, $baseCell = 'A1') private function readBIFF8CellRangeAddressB($subData, $baseCell = 'A1')
{ {
list($baseCol, $baseRow) = Cell::coordinateFromString($baseCell); list($baseCol, $baseRow) = Coordinate::coordinateFromString($baseCell);
$baseCol = Cell::columnIndexFromString($baseCol) - 1; $baseCol = Coordinate::columnIndexFromString($baseCol) - 1;
// TODO: if cell range is just a single cell, should this funciton // TODO: if cell range is just a single cell, should this funciton
// not just return e.g. 'A1' and not 'A1:A1' ? // not just return e.g. 'A1' and not 'A1:A1' ?
@ -7330,7 +7330,7 @@ class Xls extends BaseReader
// offset: 4; size: 2; first column with relative/absolute flags // offset: 4; size: 2; first column with relative/absolute flags
// bit: 7-0; mask 0x00FF; column index // bit: 7-0; mask 0x00FF; column index
$fcIndex = 0x00FF & self::getUInt2d($subData, 4); $fcIndex = 0x00FF & self::getUInt2d($subData, 4);
$fc = Cell::stringFromColumnIndex($fcIndex); $fc = Coordinate::stringFromColumnIndex($fcIndex);
$fc = '$' . $fc; $fc = '$' . $fc;
} else { } else {
// column offset // column offset
@ -7340,7 +7340,7 @@ class Xls extends BaseReader
$fcIndex = $baseCol + $relativeFcIndex; $fcIndex = $baseCol + $relativeFcIndex;
$fcIndex = ($fcIndex < 256) ? $fcIndex : $fcIndex - 256; $fcIndex = ($fcIndex < 256) ? $fcIndex : $fcIndex - 256;
$fcIndex = ($fcIndex >= 0) ? $fcIndex : $fcIndex + 256; $fcIndex = ($fcIndex >= 0) ? $fcIndex : $fcIndex + 256;
$fc = Cell::stringFromColumnIndex($fcIndex); $fc = Coordinate::stringFromColumnIndex($fcIndex);
} }
// bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
@ -7360,7 +7360,7 @@ class Xls extends BaseReader
// offset: 6; size: 2; last column with relative/absolute flags // offset: 6; size: 2; last column with relative/absolute flags
// bit: 7-0; mask 0x00FF; column index // bit: 7-0; mask 0x00FF; column index
$lcIndex = 0x00FF & self::getUInt2d($subData, 6); $lcIndex = 0x00FF & self::getUInt2d($subData, 6);
$lc = Cell::stringFromColumnIndex($lcIndex); $lc = Coordinate::stringFromColumnIndex($lcIndex);
$lc = '$' . $lc; $lc = '$' . $lc;
} else { } else {
// column offset // column offset
@ -7370,7 +7370,7 @@ class Xls extends BaseReader
$lcIndex = $baseCol + $relativeLcIndex; $lcIndex = $baseCol + $relativeLcIndex;
$lcIndex = ($lcIndex < 256) ? $lcIndex : $lcIndex - 256; $lcIndex = ($lcIndex < 256) ? $lcIndex : $lcIndex - 256;
$lcIndex = ($lcIndex >= 0) ? $lcIndex : $lcIndex + 256; $lcIndex = ($lcIndex >= 0) ? $lcIndex : $lcIndex + 256;
$lc = Cell::stringFromColumnIndex($lcIndex); $lc = Coordinate::stringFromColumnIndex($lcIndex);
} }
// bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index) // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader\Xls; namespace PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Reader\Xls; use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer; use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer;
use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer;
@ -598,7 +598,7 @@ class Escher
$endOffsetY = Xls::getUInt2d($recordData, 16); $endOffsetY = Xls::getUInt2d($recordData, 16);
// set the start coordinates // set the start coordinates
$this->object->setStartCoordinates(Cell::stringFromColumnIndex($c1) . ($r1 + 1)); $this->object->setStartCoordinates(Coordinate::stringFromColumnIndex($c1) . ($r1 + 1));
// set the start offsetX // set the start offsetX
$this->object->setStartOffsetX($startOffsetX); $this->object->setStartOffsetX($startOffsetX);
@ -607,7 +607,7 @@ class Escher
$this->object->setStartOffsetY($startOffsetY); $this->object->setStartOffsetY($startOffsetY);
// set the end coordinates // set the end coordinates
$this->object->setEndCoordinates(Cell::stringFromColumnIndex($c2) . ($r2 + 1)); $this->object->setEndCoordinates(Coordinate::stringFromColumnIndex($c2) . ($r2 + 1));
// set the end offsetX // set the end offsetX
$this->object->setEndOffsetX($endOffsetX); $this->object->setEndOffsetX($endOffsetX);

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader; namespace PhpOffice\PhpSpreadsheet\Reader;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx\Chart;
@ -230,7 +230,7 @@ class Xlsx extends BaseReader
$xml->close(); $xml->close();
$tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1; $tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1;
$tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
$worksheetInfo[] = $tmpInfo; $worksheetInfo[] = $tmpInfo;
} }
@ -278,11 +278,11 @@ class Xlsx extends BaseReader
if (!isset($sharedFormulas[(string) $c->f['si']])) { if (!isset($sharedFormulas[(string) $c->f['si']])) {
$sharedFormulas[$instance] = ['master' => $r, 'formula' => $value]; $sharedFormulas[$instance] = ['master' => $r, 'formula' => $value];
} else { } else {
$master = Cell::coordinateFromString($sharedFormulas[$instance]['master']); $master = Coordinate::coordinateFromString($sharedFormulas[$instance]['master']);
$current = Cell::coordinateFromString($r); $current = Coordinate::coordinateFromString($r);
$difference = [0, 0]; $difference = [0, 0];
$difference[0] = Cell::columnIndexFromString($current[0]) - Cell::columnIndexFromString($master[0]); $difference[0] = Coordinate::columnIndexFromString($current[0]) - Coordinate::columnIndexFromString($master[0]);
$difference[1] = $current[1] - $master[1]; $difference[1] = $current[1] - $master[1];
$value = $this->referenceHelper->updateFormulaReferences($sharedFormulas[$instance]['formula'], 'A1', $difference[0], $difference[1]); $value = $this->referenceHelper->updateFormulaReferences($sharedFormulas[$instance]['formula'], 'A1', $difference[0], $difference[1]);
@ -800,18 +800,18 @@ class Xlsx extends BaseReader
foreach ($xmlSheet->cols->col as $col) { foreach ($xmlSheet->cols->col as $col) {
for ($i = (int) ($col['min']) - 1; $i < (int) ($col['max']); ++$i) { for ($i = (int) ($col['min']) - 1; $i < (int) ($col['max']); ++$i) {
if ($col['style'] && !$this->readDataOnly) { if ($col['style'] && !$this->readDataOnly) {
$docSheet->getColumnDimension(Cell::stringFromColumnIndex($i))->setXfIndex((int) ($col['style'])); $docSheet->getColumnDimension(Coordinate::stringFromColumnIndex($i))->setXfIndex((int) ($col['style']));
} }
if (self::boolean($col['hidden'])) { if (self::boolean($col['hidden'])) {
$docSheet->getColumnDimension(Cell::stringFromColumnIndex($i))->setVisible(false); $docSheet->getColumnDimension(Coordinate::stringFromColumnIndex($i))->setVisible(false);
} }
if (self::boolean($col['collapsed'])) { if (self::boolean($col['collapsed'])) {
$docSheet->getColumnDimension(Cell::stringFromColumnIndex($i))->setCollapsed(true); $docSheet->getColumnDimension(Coordinate::stringFromColumnIndex($i))->setCollapsed(true);
} }
if ($col['outlineLevel'] > 0) { if ($col['outlineLevel'] > 0) {
$docSheet->getColumnDimension(Cell::stringFromColumnIndex($i))->setOutlineLevel((int) ($col['outlineLevel'])); $docSheet->getColumnDimension(Coordinate::stringFromColumnIndex($i))->setOutlineLevel((int) ($col['outlineLevel']));
} }
$docSheet->getColumnDimension(Cell::stringFromColumnIndex($i))->setWidth((float) ($col['width'])); $docSheet->getColumnDimension(Coordinate::stringFromColumnIndex($i))->setWidth((float) ($col['width']));
if ((int) ($col['max']) == 16384) { if ((int) ($col['max']) == 16384) {
break; break;
@ -858,7 +858,7 @@ class Xlsx extends BaseReader
foreach ($row->c as $c) { foreach ($row->c as $c) {
$r = (string) $c['r']; $r = (string) $c['r'];
if ($r == '') { if ($r == '') {
$r = Cell::stringFromColumnIndex($rowIndex) . $cIndex; $r = Coordinate::stringFromColumnIndex($rowIndex) . $cIndex;
} }
$cellDataType = (string) $c['t']; $cellDataType = (string) $c['t'];
$value = null; $value = null;
@ -866,7 +866,7 @@ class Xlsx extends BaseReader
// Read cell? // Read cell?
if ($this->getReadFilter() !== null) { if ($this->getReadFilter() !== null) {
$coordinates = Cell::coordinateFromString($r); $coordinates = Coordinate::coordinateFromString($r);
if (!$this->getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) { if (!$this->getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) {
continue; continue;
@ -1214,7 +1214,7 @@ class Xlsx extends BaseReader
if ($xmlSheet && $xmlSheet->colBreaks && $xmlSheet->colBreaks->brk && !$this->readDataOnly) { if ($xmlSheet && $xmlSheet->colBreaks && $xmlSheet->colBreaks->brk && !$this->readDataOnly) {
foreach ($xmlSheet->colBreaks->brk as $brk) { foreach ($xmlSheet->colBreaks->brk as $brk) {
if ($brk['man']) { if ($brk['man']) {
$docSheet->setBreak(Cell::stringFromColumnIndex((string) $brk['id']) . '1', Worksheet::BREAK_COLUMN); $docSheet->setBreak(Coordinate::stringFromColumnIndex((string) $brk['id']) . '1', Worksheet::BREAK_COLUMN);
} }
} }
} }
@ -1228,7 +1228,7 @@ class Xlsx extends BaseReader
$stRange = $docSheet->shrinkRangeToFit($range); $stRange = $docSheet->shrinkRangeToFit($range);
// Extract all cell references in $range // Extract all cell references in $range
foreach (Cell::extractAllCellReferencesInRange($stRange) as $reference) { foreach (Coordinate::extractAllCellReferencesInRange($stRange) as $reference) {
// Create validation // Create validation
$docValidation = $docSheet->getCell($reference)->getDataValidation(); $docValidation = $docSheet->getCell($reference)->getDataValidation();
$docValidation->setType((string) $dataValidation['type']); $docValidation->setType((string) $dataValidation['type']);
@ -1276,7 +1276,7 @@ class Xlsx extends BaseReader
// Link url // Link url
$linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
foreach (Cell::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) { foreach (Coordinate::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) {
$cell = $docSheet->getCell($cellReference); $cell = $docSheet->getCell($cellReference);
if (isset($linkRel['id'])) { if (isset($linkRel['id'])) {
$hyperlinkUrl = $hyperlinks[(string) $linkRel['id']]; $hyperlinkUrl = $hyperlinks[(string) $linkRel['id']];
@ -1568,7 +1568,7 @@ class Xlsx extends BaseReader
)], )],
false false
); );
$objDrawing->setCoordinates(Cell::stringFromColumnIndex((string) $oneCellAnchor->from->col) . ($oneCellAnchor->from->row + 1)); $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex((string) $oneCellAnchor->from->col) . ($oneCellAnchor->from->row + 1));
$objDrawing->setOffsetX(Drawing::EMUToPixels($oneCellAnchor->from->colOff)); $objDrawing->setOffsetX(Drawing::EMUToPixels($oneCellAnchor->from->colOff));
$objDrawing->setOffsetY(Drawing::EMUToPixels($oneCellAnchor->from->rowOff)); $objDrawing->setOffsetY(Drawing::EMUToPixels($oneCellAnchor->from->rowOff));
$objDrawing->setResizeProportional(false); $objDrawing->setResizeProportional(false);
@ -1590,7 +1590,7 @@ class Xlsx extends BaseReader
$objDrawing->setWorksheet($docSheet); $objDrawing->setWorksheet($docSheet);
} else { } else {
// ? Can charts be positioned with a oneCellAnchor ? // ? Can charts be positioned with a oneCellAnchor ?
$coordinates = Cell::stringFromColumnIndex((string) $oneCellAnchor->from->col) . ($oneCellAnchor->from->row + 1); $coordinates = Coordinate::stringFromColumnIndex((string) $oneCellAnchor->from->col) . ($oneCellAnchor->from->row + 1);
$offsetX = Drawing::EMUToPixels($oneCellAnchor->from->colOff); $offsetX = Drawing::EMUToPixels($oneCellAnchor->from->colOff);
$offsetY = Drawing::EMUToPixels($oneCellAnchor->from->rowOff); $offsetY = Drawing::EMUToPixels($oneCellAnchor->from->rowOff);
$width = Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cx')); $width = Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cx'));
@ -1615,7 +1615,7 @@ class Xlsx extends BaseReader
)], )],
false false
); );
$objDrawing->setCoordinates(Cell::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1)); $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1));
$objDrawing->setOffsetX(Drawing::EMUToPixels($twoCellAnchor->from->colOff)); $objDrawing->setOffsetX(Drawing::EMUToPixels($twoCellAnchor->from->colOff));
$objDrawing->setOffsetY(Drawing::EMUToPixels($twoCellAnchor->from->rowOff)); $objDrawing->setOffsetY(Drawing::EMUToPixels($twoCellAnchor->from->rowOff));
$objDrawing->setResizeProportional(false); $objDrawing->setResizeProportional(false);
@ -1637,10 +1637,10 @@ class Xlsx extends BaseReader
} }
$objDrawing->setWorksheet($docSheet); $objDrawing->setWorksheet($docSheet);
} elseif (($this->includeCharts) && ($twoCellAnchor->graphicFrame)) { } elseif (($this->includeCharts) && ($twoCellAnchor->graphicFrame)) {
$fromCoordinate = Cell::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1); $fromCoordinate = Coordinate::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1);
$fromOffsetX = Drawing::EMUToPixels($twoCellAnchor->from->colOff); $fromOffsetX = Drawing::EMUToPixels($twoCellAnchor->from->colOff);
$fromOffsetY = Drawing::EMUToPixels($twoCellAnchor->from->rowOff); $fromOffsetY = Drawing::EMUToPixels($twoCellAnchor->from->rowOff);
$toCoordinate = Cell::stringFromColumnIndex((string) $twoCellAnchor->to->col) . ($twoCellAnchor->to->row + 1); $toCoordinate = Coordinate::stringFromColumnIndex((string) $twoCellAnchor->to->col) . ($twoCellAnchor->to->row + 1);
$toOffsetX = Drawing::EMUToPixels($twoCellAnchor->to->colOff); $toOffsetX = Drawing::EMUToPixels($twoCellAnchor->to->colOff);
$toOffsetY = Drawing::EMUToPixels($twoCellAnchor->to->rowOff); $toOffsetY = Drawing::EMUToPixels($twoCellAnchor->to->rowOff);
$graphic = $twoCellAnchor->graphicFrame->children('http://schemas.openxmlformats.org/drawingml/2006/main')->graphic; $graphic = $twoCellAnchor->graphicFrame->children('http://schemas.openxmlformats.org/drawingml/2006/main')->graphic;

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader; namespace PhpOffice\PhpSpreadsheet\Reader;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
@ -207,7 +207,7 @@ class Xml extends BaseReader
} }
} }
$tmpInfo['lastColumnLetter'] = Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); $tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
$tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
$worksheetInfo[] = $tmpInfo; $worksheetInfo[] = $tmpInfo;
@ -587,7 +587,7 @@ class Xml extends BaseReader
foreach ($worksheet->Table->Column as $columnData) { foreach ($worksheet->Table->Column as $columnData) {
$columnData_ss = $columnData->attributes($namespaces['ss']); $columnData_ss = $columnData->attributes($namespaces['ss']);
if (isset($columnData_ss['Index'])) { if (isset($columnData_ss['Index'])) {
$columnID = Cell::stringFromColumnIndex($columnData_ss['Index'] - 1); $columnID = Coordinate::stringFromColumnIndex($columnData_ss['Index'] - 1);
} }
if (isset($columnData_ss['Width'])) { if (isset($columnData_ss['Width'])) {
$columnWidth = $columnData_ss['Width']; $columnWidth = $columnData_ss['Width'];
@ -611,7 +611,7 @@ class Xml extends BaseReader
foreach ($rowData->Cell as $cell) { foreach ($rowData->Cell as $cell) {
$cell_ss = $cell->attributes($namespaces['ss']); $cell_ss = $cell->attributes($namespaces['ss']);
if (isset($cell_ss['Index'])) { if (isset($cell_ss['Index'])) {
$columnID = Cell::stringFromColumnIndex($cell_ss['Index'] - 1); $columnID = Coordinate::stringFromColumnIndex($cell_ss['Index'] - 1);
} }
$cellRange = $columnID . $rowID; $cellRange = $columnID . $rowID;
@ -631,7 +631,7 @@ class Xml extends BaseReader
$columnTo = $columnID; $columnTo = $columnID;
if (isset($cell_ss['MergeAcross'])) { if (isset($cell_ss['MergeAcross'])) {
$additionalMergedCells += (int) $cell_ss['MergeAcross']; $additionalMergedCells += (int) $cell_ss['MergeAcross'];
$columnTo = Cell::stringFromColumnIndex(Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] - 1); $columnTo = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] - 1);
} }
$rowTo = $rowID; $rowTo = $rowID;
if (isset($cell_ss['MergeDown'])) { if (isset($cell_ss['MergeDown'])) {
@ -695,7 +695,7 @@ class Xml extends BaseReader
if ($hasCalculatedValue) { if ($hasCalculatedValue) {
$type = DataType::TYPE_FORMULA; $type = DataType::TYPE_FORMULA;
$columnNumber = Cell::columnIndexFromString($columnID); $columnNumber = Coordinate::columnIndexFromString($columnID);
if (substr($cellDataFormula, 0, 3) == 'of:') { if (substr($cellDataFormula, 0, 3) == 'of:') {
$cellDataFormula = substr($cellDataFormula, 3); $cellDataFormula = substr($cellDataFormula, 3);
$temp = explode('"', $cellDataFormula); $temp = explode('"', $cellDataFormula);
@ -739,7 +739,7 @@ class Xml extends BaseReader
if ($columnReference[0] == '[') { if ($columnReference[0] == '[') {
$columnReference = $columnNumber + trim($columnReference, '[]'); $columnReference = $columnNumber + trim($columnReference, '[]');
} }
$A1CellReference = Cell::stringFromColumnIndex($columnReference - 1) . $rowReference; $A1CellReference = Coordinate::stringFromColumnIndex($columnReference - 1) . $rowReference;
$value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0])); $value = substr_replace($value, $A1CellReference, $cellReference[0][1], strlen($cellReference[0][0]));
} }
} }

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet; namespace PhpOffice\PhpSpreadsheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
@ -126,8 +126,8 @@ class ReferenceHelper
*/ */
private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols) private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)
{ {
list($cellColumn, $cellRow) = Cell::coordinateFromString($cellAddress); list($cellColumn, $cellRow) = Coordinate::coordinateFromString($cellAddress);
$cellColumnIndex = Cell::columnIndexFromString($cellColumn); $cellColumnIndex = Coordinate::columnIndexFromString($cellColumn);
// Is cell within the range of rows/columns if we're deleting // Is cell within the range of rows/columns if we're deleting
if ($pNumRows < 0 && if ($pNumRows < 0 &&
($cellRow >= ($beforeRow + $pNumRows)) && ($cellRow >= ($beforeRow + $pNumRows)) &&
@ -313,7 +313,7 @@ class ReferenceHelper
if (!empty($aColumnDimensions)) { if (!empty($aColumnDimensions)) {
foreach ($aColumnDimensions as $objColumnDimension) { foreach ($aColumnDimensions as $objColumnDimension) {
$newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $pBefore, $pNumCols, $pNumRows); $newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $pBefore, $pNumCols, $pNumRows);
list($newReference) = Cell::coordinateFromString($newReference); list($newReference) = Coordinate::coordinateFromString($newReference);
if ($objColumnDimension->getColumnIndex() != $newReference) { if ($objColumnDimension->getColumnIndex() != $newReference) {
$objColumnDimension->setColumnIndex($newReference); $objColumnDimension->setColumnIndex($newReference);
} }
@ -338,7 +338,7 @@ class ReferenceHelper
if (!empty($aRowDimensions)) { if (!empty($aRowDimensions)) {
foreach ($aRowDimensions as $objRowDimension) { foreach ($aRowDimensions as $objRowDimension) {
$newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows); $newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows);
list(, $newReference) = Cell::coordinateFromString($newReference); list(, $newReference) = Coordinate::coordinateFromString($newReference);
if ($objRowDimension->getRowIndex() != $newReference) { if ($objRowDimension->getRowIndex() != $newReference) {
$objRowDimension->setRowIndex($newReference); $objRowDimension->setRowIndex($newReference);
} }
@ -374,8 +374,8 @@ class ReferenceHelper
// Get coordinate of $pBefore // Get coordinate of $pBefore
$beforeColumn = 'A'; $beforeColumn = 'A';
$beforeRow = 1; $beforeRow = 1;
list($beforeColumn, $beforeRow) = Cell::coordinateFromString($pBefore); list($beforeColumn, $beforeRow) = Coordinate::coordinateFromString($pBefore);
$beforeColumnIndex = Cell::columnIndexFromString($beforeColumn); $beforeColumnIndex = Coordinate::columnIndexFromString($beforeColumn);
// Clear cells if we are removing columns or rows // Clear cells if we are removing columns or rows
$highestColumn = $pSheet->getHighestColumn(); $highestColumn = $pSheet->getHighestColumn();
@ -385,7 +385,7 @@ class ReferenceHelper
if ($pNumCols < 0 && $beforeColumnIndex - 2 + $pNumCols > 0) { if ($pNumCols < 0 && $beforeColumnIndex - 2 + $pNumCols > 0) {
for ($i = 1; $i <= $highestRow - 1; ++$i) { for ($i = 1; $i <= $highestRow - 1; ++$i) {
for ($j = $beforeColumnIndex - 1 + $pNumCols; $j <= $beforeColumnIndex - 2; ++$j) { for ($j = $beforeColumnIndex - 1 + $pNumCols; $j <= $beforeColumnIndex - 2; ++$j) {
$coordinate = Cell::stringFromColumnIndex($j) . $i; $coordinate = Coordinate::stringFromColumnIndex($j) . $i;
$pSheet->removeConditionalStyles($coordinate); $pSheet->removeConditionalStyles($coordinate);
if ($pSheet->cellExists($coordinate)) { if ($pSheet->cellExists($coordinate)) {
$pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); $pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL);
@ -397,9 +397,9 @@ class ReferenceHelper
// 2. Clear row strips if we are removing rows // 2. Clear row strips if we are removing rows
if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) { if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) {
for ($i = $beforeColumnIndex - 1; $i <= Cell::columnIndexFromString($highestColumn) - 1; ++$i) { for ($i = $beforeColumnIndex - 1; $i <= Coordinate::columnIndexFromString($highestColumn) - 1; ++$i) {
for ($j = $beforeRow + $pNumRows; $j <= $beforeRow - 1; ++$j) { for ($j = $beforeRow + $pNumRows; $j <= $beforeRow - 1; ++$j) {
$coordinate = Cell::stringFromColumnIndex($i) . $j; $coordinate = Coordinate::stringFromColumnIndex($i) . $j;
$pSheet->removeConditionalStyles($coordinate); $pSheet->removeConditionalStyles($coordinate);
if ($pSheet->cellExists($coordinate)) { if ($pSheet->cellExists($coordinate)) {
$pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL); $pSheet->getCell($coordinate)->setValueExplicit('', DataType::TYPE_NULL);
@ -416,14 +416,14 @@ class ReferenceHelper
} }
while ($coordinate = array_pop($allCoordinates)) { while ($coordinate = array_pop($allCoordinates)) {
$cell = $pSheet->getCell($coordinate); $cell = $pSheet->getCell($coordinate);
$cellIndex = Cell::columnIndexFromString($cell->getColumn()); $cellIndex = Coordinate::columnIndexFromString($cell->getColumn());
if ($cellIndex - 1 + $pNumCols < 0) { if ($cellIndex - 1 + $pNumCols < 0) {
continue; continue;
} }
// New coordinate // New coordinate
$newCoordinate = Cell::stringFromColumnIndex($cellIndex - 1 + $pNumCols) . ($cell->getRow() + $pNumRows); $newCoordinate = Coordinate::stringFromColumnIndex($cellIndex - 1 + $pNumCols) . ($cell->getRow() + $pNumRows);
// Should the cell be updated? Move value and cellXf index from one cell to another. // Should the cell be updated? Move value and cellXf index from one cell to another.
if (($cellIndex >= $beforeColumnIndex) && ($cell->getRow() >= $beforeRow)) { if (($cellIndex >= $beforeColumnIndex) && ($cell->getRow() >= $beforeRow)) {
@ -459,7 +459,7 @@ class ReferenceHelper
if ($pNumCols > 0 && $beforeColumnIndex - 2 > 0) { if ($pNumCols > 0 && $beforeColumnIndex - 2 > 0) {
for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) { for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) {
// Style // Style
$coordinate = Cell::stringFromColumnIndex($beforeColumnIndex - 2) . $i; $coordinate = Coordinate::stringFromColumnIndex($beforeColumnIndex - 2) . $i;
if ($pSheet->cellExists($coordinate)) { if ($pSheet->cellExists($coordinate)) {
$xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); $xfIndex = $pSheet->getCell($coordinate)->getXfIndex();
$conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ?
@ -471,7 +471,7 @@ class ReferenceHelper
foreach ($conditionalStyles as $conditionalStyle) { foreach ($conditionalStyles as $conditionalStyle) {
$cloned[] = clone $conditionalStyle; $cloned[] = clone $conditionalStyle;
} }
$pSheet->setConditionalStyles(Cell::stringFromColumnIndex($j) . $i, $cloned); $pSheet->setConditionalStyles(Coordinate::stringFromColumnIndex($j) . $i, $cloned);
} }
} }
} }
@ -479,21 +479,21 @@ class ReferenceHelper
} }
if ($pNumRows > 0 && $beforeRow - 1 > 0) { if ($pNumRows > 0 && $beforeRow - 1 > 0) {
for ($i = $beforeColumnIndex - 1; $i <= Cell::columnIndexFromString($highestColumn) - 1; ++$i) { for ($i = $beforeColumnIndex - 1; $i <= Coordinate::columnIndexFromString($highestColumn) - 1; ++$i) {
// Style // Style
$coordinate = Cell::stringFromColumnIndex($i) . ($beforeRow - 1); $coordinate = Coordinate::stringFromColumnIndex($i) . ($beforeRow - 1);
if ($pSheet->cellExists($coordinate)) { if ($pSheet->cellExists($coordinate)) {
$xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); $xfIndex = $pSheet->getCell($coordinate)->getXfIndex();
$conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? $conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ?
$pSheet->getConditionalStyles($coordinate) : false; $pSheet->getConditionalStyles($coordinate) : false;
for ($j = $beforeRow; $j <= $beforeRow - 1 + $pNumRows; ++$j) { for ($j = $beforeRow; $j <= $beforeRow - 1 + $pNumRows; ++$j) {
$pSheet->getCell(Cell::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex); $pSheet->getCell(Coordinate::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex);
if ($conditionalStyles) { if ($conditionalStyles) {
$cloned = []; $cloned = [];
foreach ($conditionalStyles as $conditionalStyle) { foreach ($conditionalStyles as $conditionalStyle) {
$cloned[] = clone $conditionalStyle; $cloned[] = clone $conditionalStyle;
} }
$pSheet->setConditionalStyles(Cell::stringFromColumnIndex($i) . $j, $cloned); $pSheet->setConditionalStyles(Coordinate::stringFromColumnIndex($i) . $j, $cloned);
} }
} }
} }
@ -532,8 +532,8 @@ class ReferenceHelper
$autoFilterColumns = $autoFilter->getColumns(); $autoFilterColumns = $autoFilter->getColumns();
if (count($autoFilterColumns) > 0) { if (count($autoFilterColumns) > 0) {
sscanf($pBefore, '%[A-Z]%d', $column, $row); sscanf($pBefore, '%[A-Z]%d', $column, $row);
$columnIndex = Cell::columnIndexFromString($column); $columnIndex = Coordinate::columnIndexFromString($column);
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($autoFilterRange); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($autoFilterRange);
if ($columnIndex <= $rangeEnd[0]) { if ($columnIndex <= $rangeEnd[0]) {
if ($pNumCols < 0) { if ($pNumCols < 0) {
// If we're actually deleting any columns that fall within the autofilter range, // If we're actually deleting any columns that fall within the autofilter range,
@ -541,8 +541,8 @@ class ReferenceHelper
$deleteColumn = $columnIndex + $pNumCols - 1; $deleteColumn = $columnIndex + $pNumCols - 1;
$deleteCount = abs($pNumCols); $deleteCount = abs($pNumCols);
for ($i = 1; $i <= $deleteCount; ++$i) { for ($i = 1; $i <= $deleteCount; ++$i) {
if (isset($autoFilterColumns[Cell::stringFromColumnIndex($deleteColumn)])) { if (isset($autoFilterColumns[Coordinate::stringFromColumnIndex($deleteColumn)])) {
$autoFilter->clearColumn(Cell::stringFromColumnIndex($deleteColumn)); $autoFilter->clearColumn(Coordinate::stringFromColumnIndex($deleteColumn));
} }
++$deleteColumn; ++$deleteColumn;
} }
@ -552,24 +552,24 @@ class ReferenceHelper
// Shuffle columns in autofilter range // Shuffle columns in autofilter range
if ($pNumCols > 0) { if ($pNumCols > 0) {
// For insert, we shuffle from end to beginning to avoid overwriting // For insert, we shuffle from end to beginning to avoid overwriting
$startColID = Cell::stringFromColumnIndex($startCol - 1); $startColID = Coordinate::stringFromColumnIndex($startCol - 1);
$toColID = Cell::stringFromColumnIndex($startCol + $pNumCols - 1); $toColID = Coordinate::stringFromColumnIndex($startCol + $pNumCols - 1);
$endColID = Cell::stringFromColumnIndex($rangeEnd[0]); $endColID = Coordinate::stringFromColumnIndex($rangeEnd[0]);
$startColRef = $startCol; $startColRef = $startCol;
$endColRef = $rangeEnd[0]; $endColRef = $rangeEnd[0];
$toColRef = $rangeEnd[0] + $pNumCols; $toColRef = $rangeEnd[0] + $pNumCols;
do { do {
$autoFilter->shiftColumn(Cell::stringFromColumnIndex($endColRef - 1), Cell::stringFromColumnIndex($toColRef - 1)); $autoFilter->shiftColumn(Coordinate::stringFromColumnIndex($endColRef - 1), Coordinate::stringFromColumnIndex($toColRef - 1));
--$endColRef; --$endColRef;
--$toColRef; --$toColRef;
} while ($startColRef <= $endColRef); } while ($startColRef <= $endColRef);
} else { } else {
// For delete, we shuffle from beginning to end to avoid overwriting // For delete, we shuffle from beginning to end to avoid overwriting
$startColID = Cell::stringFromColumnIndex($startCol - 1); $startColID = Coordinate::stringFromColumnIndex($startCol - 1);
$toColID = Cell::stringFromColumnIndex($startCol + $pNumCols - 1); $toColID = Coordinate::stringFromColumnIndex($startCol + $pNumCols - 1);
$endColID = Cell::stringFromColumnIndex($rangeEnd[0]); $endColID = Coordinate::stringFromColumnIndex($rangeEnd[0]);
do { do {
$autoFilter->shiftColumn($startColID, $toColID); $autoFilter->shiftColumn($startColID, $toColID);
++$startColID; ++$startColID;
@ -676,7 +676,7 @@ class ReferenceHelper
$toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString = ($match[2] > '') ? $match[2] . '!' : '';
$toString .= $modified3 . ':' . $modified4; $toString .= $modified3 . ':' . $modified4;
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
$column = Cell::columnIndexFromString(trim($match[3], '$')) + 100000; $column = Coordinate::columnIndexFromString(trim($match[3], '$')) + 100000;
$row = 10000000; $row = 10000000;
$cellIndex = $column . $row; $cellIndex = $column . $row;
@ -700,9 +700,9 @@ class ReferenceHelper
if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) {
$toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString = ($match[2] > '') ? $match[2] . '!' : '';
$toString .= $modified3 . ':' . $modified4; $toString .= $modified3 . ':' . $modified4;
list($column, $row) = Cell::coordinateFromString($match[3]); list($column, $row) = Coordinate::coordinateFromString($match[3]);
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
$column = Cell::columnIndexFromString(trim($column, '$')) + 100000; $column = Coordinate::columnIndexFromString(trim($column, '$')) + 100000;
$row = trim($row, '$') + 10000000; $row = trim($row, '$') + 10000000;
$cellIndex = $column . $row; $cellIndex = $column . $row;
@ -726,9 +726,9 @@ class ReferenceHelper
if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) {
$toString = ($match[2] > '') ? $match[2] . '!' : ''; $toString = ($match[2] > '') ? $match[2] . '!' : '';
$toString .= $modified3; $toString .= $modified3;
list($column, $row) = Cell::coordinateFromString($match[3]); list($column, $row) = Coordinate::coordinateFromString($match[3]);
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
$column = Cell::columnIndexFromString(trim($column, '$')) + 100000; $column = Coordinate::columnIndexFromString(trim($column, '$')) + 100000;
$row = trim($row, '$') + 10000000; $row = trim($row, '$') + 10000000;
$cellIndex = $row . $column; $cellIndex = $row . $column;
@ -830,16 +830,16 @@ class ReferenceHelper
{ {
if (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) { if (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) {
// Update range // Update range
$range = Cell::splitRange($pCellRange); $range = Coordinate::splitRange($pCellRange);
$ic = count($range); $ic = count($range);
for ($i = 0; $i < $ic; ++$i) { for ($i = 0; $i < $ic; ++$i) {
$jc = count($range[$i]); $jc = count($range[$i]);
for ($j = 0; $j < $jc; ++$j) { for ($j = 0; $j < $jc; ++$j) {
if (ctype_alpha($range[$i][$j])) { if (ctype_alpha($range[$i][$j])) {
$r = Cell::coordinateFromString($this->updateSingleCellReference($range[$i][$j] . '1', $pBefore, $pNumCols, $pNumRows)); $r = Coordinate::coordinateFromString($this->updateSingleCellReference($range[$i][$j] . '1', $pBefore, $pNumCols, $pNumRows));
$range[$i][$j] = $r[0]; $range[$i][$j] = $r[0];
} elseif (ctype_digit($range[$i][$j])) { } elseif (ctype_digit($range[$i][$j])) {
$r = Cell::coordinateFromString($this->updateSingleCellReference('A' . $range[$i][$j], $pBefore, $pNumCols, $pNumRows)); $r = Coordinate::coordinateFromString($this->updateSingleCellReference('A' . $range[$i][$j], $pBefore, $pNumCols, $pNumRows));
$range[$i][$j] = $r[1]; $range[$i][$j] = $r[1];
} else { } else {
$range[$i][$j] = $this->updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); $range[$i][$j] = $this->updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows);
@ -848,7 +848,7 @@ class ReferenceHelper
} }
// Recreate range string // Recreate range string
return Cell::buildRange($range); return Coordinate::buildRange($range);
} }
throw new Exception('Only cell ranges may be passed to this method.'); throw new Exception('Only cell ranges may be passed to this method.');
@ -870,18 +870,18 @@ class ReferenceHelper
{ {
if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) { if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) {
// Get coordinate of $pBefore // Get coordinate of $pBefore
list($beforeColumn, $beforeRow) = Cell::coordinateFromString($pBefore); list($beforeColumn, $beforeRow) = Coordinate::coordinateFromString($pBefore);
// Get coordinate of $pCellReference // Get coordinate of $pCellReference
list($newColumn, $newRow) = Cell::coordinateFromString($pCellReference); list($newColumn, $newRow) = Coordinate::coordinateFromString($pCellReference);
// Verify which parts should be updated // Verify which parts should be updated
$updateColumn = (($newColumn[0] != '$') && ($beforeColumn[0] != '$') && (Cell::columnIndexFromString($newColumn) >= Cell::columnIndexFromString($beforeColumn))); $updateColumn = (($newColumn[0] != '$') && ($beforeColumn[0] != '$') && (Coordinate::columnIndexFromString($newColumn) >= Coordinate::columnIndexFromString($beforeColumn)));
$updateRow = (($newRow[0] != '$') && ($beforeRow[0] != '$') && $newRow >= $beforeRow); $updateRow = (($newRow[0] != '$') && ($beforeRow[0] != '$') && $newRow >= $beforeRow);
// Create new column reference // Create new column reference
if ($updateColumn) { if ($updateColumn) {
$newColumn = Cell::stringFromColumnIndex(Cell::columnIndexFromString($newColumn) - 1 + $pNumCols); $newColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($newColumn) - 1 + $pNumCols);
} }
// Create new row reference // Create new row reference

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Shared; namespace PhpOffice\PhpSpreadsheet\Shared;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class Xls class Xls
@ -111,10 +111,10 @@ class Xls
$distanceX = 0; $distanceX = 0;
// add the widths of the spanning columns // add the widths of the spanning columns
$startColumnIndex = Cell::columnIndexFromString($startColumn) - 1; // 1-based $startColumnIndex = Coordinate::columnIndexFromString($startColumn) - 1; // 1-based
$endColumnIndex = Cell::columnIndexFromString($endColumn) - 1; // 1-based $endColumnIndex = Coordinate::columnIndexFromString($endColumn) - 1; // 1-based
for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) { for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) {
$distanceX += self::sizeCol($sheet, Cell::stringFromColumnIndex($i)); $distanceX += self::sizeCol($sheet, Coordinate::stringFromColumnIndex($i));
} }
// correct for offsetX in startcell // correct for offsetX in startcell
@ -211,8 +211,8 @@ class Xls
*/ */
public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height) public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height)
{ {
list($column, $row) = Cell::coordinateFromString($coordinates); list($column, $row) = Coordinate::coordinateFromString($coordinates);
$col_start = Cell::columnIndexFromString($column) - 1; $col_start = Coordinate::columnIndexFromString($column) - 1;
$row_start = $row - 1; $row_start = $row - 1;
$x1 = $offsetX; $x1 = $offsetX;
@ -223,7 +223,7 @@ class Xls
$row_end = $row_start; // Row containing bottom right corner of object $row_end = $row_start; // Row containing bottom right corner of object
// Zero the specified offset if greater than the cell dimensions // Zero the specified offset if greater than the cell dimensions
if ($x1 >= self::sizeCol($sheet, Cell::stringFromColumnIndex($col_start))) { if ($x1 >= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start))) {
$x1 = 0; $x1 = 0;
} }
if ($y1 >= self::sizeRow($sheet, $row_start + 1)) { if ($y1 >= self::sizeRow($sheet, $row_start + 1)) {
@ -234,8 +234,8 @@ class Xls
$height = $height + $y1 - 1; $height = $height + $y1 - 1;
// Subtract the underlying cell widths to find the end cell of the image // Subtract the underlying cell widths to find the end cell of the image
while ($width >= self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end))) { while ($width >= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end))) {
$width -= self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end)); $width -= self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end));
++$col_end; ++$col_end;
} }
@ -247,10 +247,10 @@ class Xls
// Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
// with zero height or width. // with zero height or width.
if (self::sizeCol($sheet, Cell::stringFromColumnIndex($col_start)) == 0) { if (self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start)) == 0) {
return; return;
} }
if (self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end)) == 0) { if (self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end)) == 0) {
return; return;
} }
if (self::sizeRow($sheet, $row_start + 1) == 0) { if (self::sizeRow($sheet, $row_start + 1) == 0) {
@ -261,13 +261,13 @@ class Xls
} }
// Convert the pixel values to the percentage value expected by Excel // Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / self::sizeCol($sheet, Cell::stringFromColumnIndex($col_start)) * 1024; $x1 = $x1 / self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256; $y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
$x2 = ($width + 1) / self::sizeCol($sheet, Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object $x2 = ($width + 1) / self::sizeCol($sheet, Coordinate::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object $y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
$startCoordinates = Cell::stringFromColumnIndex($col_start) . ($row_start + 1); $startCoordinates = Coordinate::stringFromColumnIndex($col_start) . ($row_start + 1);
$endCoordinates = Cell::stringFromColumnIndex($col_end) . ($row_end + 1); $endCoordinates = Coordinate::stringFromColumnIndex($col_end) . ($row_end + 1);
$twoAnchor = [ $twoAnchor = [
'startCoordinates' => $startCoordinates, 'startCoordinates' => $startCoordinates,

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Style; namespace PhpOffice\PhpSpreadsheet\Style;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
class Style extends Supervisor class Style extends Supervisor
@ -206,12 +206,12 @@ class Style extends Supervisor
} }
// Calculate range outer borders // Calculate range outer borders
$rangeStart = Cell::coordinateFromString($rangeA); $rangeStart = Coordinate::coordinateFromString($rangeA);
$rangeEnd = Cell::coordinateFromString($rangeB); $rangeEnd = Coordinate::coordinateFromString($rangeB);
// Translate column into index // Translate column into index
$rangeStart[0] = Cell::columnIndexFromString($rangeStart[0]) - 1; $rangeStart[0] = Coordinate::columnIndexFromString($rangeStart[0]) - 1;
$rangeEnd[0] = Cell::columnIndexFromString($rangeEnd[0]) - 1; $rangeEnd[0] = Coordinate::columnIndexFromString($rangeEnd[0]) - 1;
// Make sure we can loop upwards on rows and columns // Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
@ -260,12 +260,12 @@ class Style extends Supervisor
for ($x = 1; $x <= $xMax; ++$x) { for ($x = 1; $x <= $xMax; ++$x) {
// start column index for region // start column index for region
$colStart = ($x == 3) ? $colStart = ($x == 3) ?
Cell::stringFromColumnIndex($rangeEnd[0]) Coordinate::stringFromColumnIndex($rangeEnd[0])
: Cell::stringFromColumnIndex($rangeStart[0] + $x - 1); : Coordinate::stringFromColumnIndex($rangeStart[0] + $x - 1);
// end column index for region // end column index for region
$colEnd = ($x == 1) ? $colEnd = ($x == 1) ?
Cell::stringFromColumnIndex($rangeStart[0]) Coordinate::stringFromColumnIndex($rangeStart[0])
: Cell::stringFromColumnIndex($rangeEnd[0] - $xMax + $x); : Coordinate::stringFromColumnIndex($rangeEnd[0] - $xMax + $x);
for ($y = 1; $y <= $yMax; ++$y) { for ($y = 1; $y <= $yMax; ++$y) {
// which edges are touching the region // which edges are touching the region

View File

@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTime; use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
@ -108,9 +108,9 @@ class AutoFilter
$this->columns = []; $this->columns = [];
} else { } else {
// Discard any column rules that are no longer valid within this range // Discard any column rules that are no longer valid within this range
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($this->range);
foreach ($this->columns as $key => $value) { foreach ($this->columns as $key => $value) {
$colIndex = Cell::columnIndexFromString($key); $colIndex = Coordinate::columnIndexFromString($key);
if (($rangeStart[0] > $colIndex) || ($rangeEnd[0] < $colIndex)) { if (($rangeStart[0] > $colIndex) || ($rangeEnd[0] < $colIndex)) {
unset($this->columns[$key]); unset($this->columns[$key]);
} }
@ -147,8 +147,8 @@ class AutoFilter
throw new PhpSpreadsheetException('No autofilter range is defined.'); throw new PhpSpreadsheetException('No autofilter range is defined.');
} }
$columnIndex = Cell::columnIndexFromString($column); $columnIndex = Coordinate::columnIndexFromString($column);
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($this->range);
if (($rangeStart[0] > $columnIndex) || ($rangeEnd[0] < $columnIndex)) { if (($rangeStart[0] > $columnIndex) || ($rangeEnd[0] < $columnIndex)) {
throw new PhpSpreadsheetException('Column is outside of current autofilter range.'); throw new PhpSpreadsheetException('Column is outside of current autofilter range.');
} }
@ -201,8 +201,8 @@ class AutoFilter
*/ */
public function getColumnByOffset($pColumnOffset) public function getColumnByOffset($pColumnOffset)
{ {
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($this->range);
$pColumn = Cell::stringFromColumnIndex($rangeStart[0] + $pColumnOffset - 1); $pColumn = Coordinate::stringFromColumnIndex($rangeStart[0] + $pColumnOffset - 1);
return $this->getColumn($pColumn); return $this->getColumn($pColumn);
} }
@ -623,7 +623,7 @@ class AutoFilter
*/ */
public function showHideRows() public function showHideRows()
{ {
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($this->range); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($this->range);
// The heading row should always be visible // The heading row should always be visible
$this->workSheet->getRowDimension($rangeStart[1])->setVisible(true); $this->workSheet->getRowDimension($rangeStart[1])->setVisible(true);

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
class ColumnCellIterator extends CellIterator class ColumnCellIterator extends CellIterator
@ -40,7 +40,7 @@ class ColumnCellIterator extends CellIterator
{ {
// Set subject // Set subject
$this->subject = $subject; $this->subject = $subject;
$this->columnIndex = Cell::columnIndexFromString($columnIndex) - 1; $this->columnIndex = Coordinate::columnIndexFromString($columnIndex) - 1;
$this->resetEnd($endRow); $this->resetEnd($endRow);
$this->resetStart($startRow); $this->resetStart($startRow);
} }

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
@ -70,8 +70,8 @@ class ColumnIterator implements \Iterator
*/ */
public function resetStart($startColumn = 'A') public function resetStart($startColumn = 'A')
{ {
$startColumnIndex = Cell::columnIndexFromString($startColumn) - 1; $startColumnIndex = Coordinate::columnIndexFromString($startColumn) - 1;
if ($startColumnIndex > Cell::columnIndexFromString($this->subject->getHighestColumn()) - 1) { if ($startColumnIndex > Coordinate::columnIndexFromString($this->subject->getHighestColumn()) - 1) {
throw new Exception("Start column ({$startColumn}) is beyond highest column ({$this->subject->getHighestColumn()})"); throw new Exception("Start column ({$startColumn}) is beyond highest column ({$this->subject->getHighestColumn()})");
} }
@ -94,7 +94,7 @@ class ColumnIterator implements \Iterator
public function resetEnd($endColumn = null) public function resetEnd($endColumn = null)
{ {
$endColumn = ($endColumn) ? $endColumn : $this->subject->getHighestColumn(); $endColumn = ($endColumn) ? $endColumn : $this->subject->getHighestColumn();
$this->endColumn = Cell::columnIndexFromString($endColumn) - 1; $this->endColumn = Coordinate::columnIndexFromString($endColumn) - 1;
return $this; return $this;
} }
@ -110,7 +110,7 @@ class ColumnIterator implements \Iterator
*/ */
public function seek($column = 'A') public function seek($column = 'A')
{ {
$column = Cell::columnIndexFromString($column) - 1; $column = Coordinate::columnIndexFromString($column) - 1;
if (($column < $this->startColumn) || ($column > $this->endColumn)) { if (($column < $this->startColumn) || ($column > $this->endColumn)) {
throw new PhpSpreadsheetException("Column $column is out of range ({$this->startColumn} - {$this->endColumn})"); throw new PhpSpreadsheetException("Column $column is out of range ({$this->startColumn} - {$this->endColumn})");
} }
@ -134,7 +134,7 @@ class ColumnIterator implements \Iterator
*/ */
public function current() public function current()
{ {
return new Column($this->subject, Cell::stringFromColumnIndex($this->position)); return new Column($this->subject, Coordinate::stringFromColumnIndex($this->position));
} }
/** /**
@ -144,7 +144,7 @@ class ColumnIterator implements \Iterator
*/ */
public function key() public function key()
{ {
return Cell::stringFromColumnIndex($this->position); return Coordinate::stringFromColumnIndex($this->position);
} }
/** /**
@ -163,7 +163,7 @@ class ColumnIterator implements \Iterator
public function prev() public function prev()
{ {
if ($this->position <= $this->startColumn) { if ($this->position <= $this->startColumn) {
throw new PhpSpreadsheetException('Column is already at the beginning of range (' . Cell::stringFromColumnIndex($this->endColumn) . ' - ' . Cell::stringFromColumnIndex($this->endColumn) . ')'); throw new PhpSpreadsheetException('Column is already at the beginning of range (' . Coordinate::stringFromColumnIndex($this->endColumn) . ' - ' . Coordinate::stringFromColumnIndex($this->endColumn) . ')');
} }
--$this->position; --$this->position;
} }

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
/** /**
@ -767,7 +767,7 @@ class PageSetup
public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
{ {
return $this->setPrintArea( return $this->setPrintArea(
Cell::stringFromColumnIndex($column1) . $row1 . ':' . Cell::stringFromColumnIndex($column2) . $row2, Coordinate::stringFromColumnIndex($column1) . $row1 . ':' . Coordinate::stringFromColumnIndex($column2) . $row2,
$index, $index,
$method $method
); );
@ -794,7 +794,7 @@ class PageSetup
public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1) public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1)
{ {
return $this->setPrintArea( return $this->setPrintArea(
Cell::stringFromColumnIndex($column1) . $row1 . ':' . Cell::stringFromColumnIndex($column2) . $row2, Coordinate::stringFromColumnIndex($column1) . $row1 . ':' . Coordinate::stringFromColumnIndex($column2) . $row2,
$index, $index,
self::SETPRINTRANGE_INSERT self::SETPRINTRANGE_INSERT
); );

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
class RowCellIterator extends CellIterator class RowCellIterator extends CellIterator
@ -64,10 +64,10 @@ class RowCellIterator extends CellIterator
*/ */
public function resetStart($startColumn = 'A') public function resetStart($startColumn = 'A')
{ {
$startColumnIndex = Cell::columnIndexFromString($startColumn) - 1; $startColumnIndex = Coordinate::columnIndexFromString($startColumn) - 1;
$this->startColumn = $startColumnIndex; $this->startColumn = $startColumnIndex;
$this->adjustForExistingOnlyRange(); $this->adjustForExistingOnlyRange();
$this->seek(Cell::stringFromColumnIndex($this->startColumn)); $this->seek(Coordinate::stringFromColumnIndex($this->startColumn));
return $this; return $this;
} }
@ -84,7 +84,7 @@ class RowCellIterator extends CellIterator
public function resetEnd($endColumn = null) public function resetEnd($endColumn = null)
{ {
$endColumn = ($endColumn) ? $endColumn : $this->subject->getHighestColumn(); $endColumn = ($endColumn) ? $endColumn : $this->subject->getHighestColumn();
$this->endColumn = Cell::columnIndexFromString($endColumn) - 1; $this->endColumn = Coordinate::columnIndexFromString($endColumn) - 1;
$this->adjustForExistingOnlyRange(); $this->adjustForExistingOnlyRange();
return $this; return $this;
@ -101,7 +101,7 @@ class RowCellIterator extends CellIterator
*/ */
public function seek($column = 'A') public function seek($column = 'A')
{ {
$column = Cell::columnIndexFromString($column) - 1; $column = Coordinate::columnIndexFromString($column) - 1;
if (($column < $this->startColumn) || ($column > $this->endColumn)) { if (($column < $this->startColumn) || ($column > $this->endColumn)) {
throw new PhpSpreadsheetException("Column $column is out of range ({$this->startColumn} - {$this->endColumn})"); throw new PhpSpreadsheetException("Column $column is out of range ({$this->startColumn} - {$this->endColumn})");
} elseif ($this->onlyExistingCells && !($this->subject->cellExistsByColumnAndRow($column, $this->rowIndex))) { } elseif ($this->onlyExistingCells && !($this->subject->cellExistsByColumnAndRow($column, $this->rowIndex))) {
@ -137,7 +137,7 @@ class RowCellIterator extends CellIterator
*/ */
public function key() public function key()
{ {
return Cell::stringFromColumnIndex($this->position); return Coordinate::stringFromColumnIndex($this->position);
} }
/** /**
@ -158,7 +158,7 @@ class RowCellIterator extends CellIterator
public function prev() public function prev()
{ {
if ($this->position <= $this->startColumn) { if ($this->position <= $this->startColumn) {
throw new PhpSpreadsheetException('Column is already at the beginning of range (' . Cell::stringFromColumnIndex($this->endColumn) . ' - ' . Cell::stringFromColumnIndex($this->endColumn) . ')'); throw new PhpSpreadsheetException('Column is already at the beginning of range (' . Coordinate::stringFromColumnIndex($this->endColumn) . ' - ' . Coordinate::stringFromColumnIndex($this->endColumn) . ')');
} }
do { do {
--$this->position; --$this->position;

View File

@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet;
use ArrayObject; use ArrayObject;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation; use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Cell\Hyperlink; use PhpOffice\PhpSpreadsheet\Cell\Hyperlink;
@ -715,7 +716,7 @@ class Worksheet implements IComparable
// build list of cells references that participate in a merge // build list of cells references that participate in a merge
$isMergeCell = []; $isMergeCell = [];
foreach ($this->getMergeCells() as $cells) { foreach ($this->getMergeCells() as $cells) {
foreach (Cell::extractAllCellReferencesInRange($cells) as $cellReference) { foreach (Coordinate::extractAllCellReferencesInRange($cells) as $cellReference) {
$isMergeCell[$cellReference] = true; $isMergeCell[$cellReference] = true;
} }
} }
@ -733,7 +734,7 @@ class Worksheet implements IComparable
//The only exception is if it's a merge range value cell of a 'vertical' randge (1 column wide) //The only exception is if it's a merge range value cell of a 'vertical' randge (1 column wide)
if ($isMerged && $cell->isMergeRangeValueCell()) { if ($isMerged && $cell->isMergeRangeValueCell()) {
$range = $cell->getMergeRange(); $range = $cell->getMergeRange();
$rangeBoundaries = Cell::rangeDimension($range); $rangeBoundaries = Coordinate::rangeDimension($range);
if ($rangeBoundaries[0] == 1) { if ($rangeBoundaries[0] == 1) {
$isMergedButProceed = true; $isMergedButProceed = true;
} }
@ -1230,7 +1231,7 @@ class Worksheet implements IComparable
*/ */
public function getCellByColumnAndRow($pColumn, $pRow, $createIfNotExists = true) public function getCellByColumnAndRow($pColumn, $pRow, $createIfNotExists = true)
{ {
$columnLetter = Cell::stringFromColumnIndex($pColumn); $columnLetter = Coordinate::stringFromColumnIndex($pColumn);
$coordinate = $columnLetter . $pRow; $coordinate = $columnLetter . $pRow;
if ($this->cellCollection->has($coordinate)) { if ($this->cellCollection->has($coordinate)) {
@ -1255,8 +1256,8 @@ class Worksheet implements IComparable
$this->cellCollectionIsSorted = false; $this->cellCollectionIsSorted = false;
// Coordinates // Coordinates
$aCoordinates = Cell::coordinateFromString($pCoordinate); $aCoordinates = Coordinate::coordinateFromString($pCoordinate);
if (Cell::columnIndexFromString($this->cachedHighestColumn) < Cell::columnIndexFromString($aCoordinates[0])) { if (Coordinate::columnIndexFromString($this->cachedHighestColumn) < Coordinate::columnIndexFromString($aCoordinates[0])) {
$this->cachedHighestColumn = $aCoordinates[0]; $this->cachedHighestColumn = $aCoordinates[0];
} }
$this->cachedHighestRow = max($this->cachedHighestRow, $aCoordinates[1]); $this->cachedHighestRow = max($this->cachedHighestRow, $aCoordinates[1]);
@ -1336,7 +1337,7 @@ class Worksheet implements IComparable
*/ */
public function cellExistsByColumnAndRow($pColumn, $pRow) public function cellExistsByColumnAndRow($pColumn, $pRow)
{ {
return $this->cellExists(Cell::stringFromColumnIndex($pColumn) . $pRow); return $this->cellExists(Coordinate::stringFromColumnIndex($pColumn) . $pRow);
} }
/** /**
@ -1385,7 +1386,7 @@ class Worksheet implements IComparable
} }
$this->columnDimensions[$pColumn] = new ColumnDimension($pColumn); $this->columnDimensions[$pColumn] = new ColumnDimension($pColumn);
if (Cell::columnIndexFromString($this->cachedHighestColumn) < Cell::columnIndexFromString($pColumn)) { if (Coordinate::columnIndexFromString($this->cachedHighestColumn) < Coordinate::columnIndexFromString($pColumn)) {
$this->cachedHighestColumn = $pColumn; $this->cachedHighestColumn = $pColumn;
} }
} }
@ -1402,7 +1403,7 @@ class Worksheet implements IComparable
*/ */
public function getColumnDimensionByColumn($pColumn) public function getColumnDimensionByColumn($pColumn)
{ {
return $this->getColumnDimension(Cell::stringFromColumnIndex($pColumn)); return $this->getColumnDimension(Coordinate::stringFromColumnIndex($pColumn));
} }
/** /**
@ -1522,12 +1523,12 @@ class Worksheet implements IComparable
public function getStyleByColumnAndRow($pColumn, $pRow, $pColumn2 = null, $pRow2 = null) public function getStyleByColumnAndRow($pColumn, $pRow, $pColumn2 = null, $pRow2 = null)
{ {
if ($pColumn2 !== null && $pRow2 !== null) { if ($pColumn2 !== null && $pRow2 !== null) {
$cellRange = Cell::stringFromColumnIndex($pColumn) . $pRow . ':' . Cell::stringFromColumnIndex($pColumn2) . $pRow2; $cellRange = Coordinate::stringFromColumnIndex($pColumn) . $pRow . ':' . Coordinate::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->getStyle($cellRange); return $this->getStyle($cellRange);
} }
return $this->getStyle(Cell::stringFromColumnIndex($pColumn) . $pRow); return $this->getStyle(Coordinate::stringFromColumnIndex($pColumn) . $pRow);
} }
/** /**
@ -1556,7 +1557,7 @@ class Worksheet implements IComparable
} }
// Calculate range outer borders // Calculate range outer borders
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($pRange . ':' . $pRange); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($pRange . ':' . $pRange);
// Make sure we can loop upwards on rows and columns // Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
@ -1568,7 +1569,7 @@ class Worksheet implements IComparable
// Loop through cells and apply styles // Loop through cells and apply styles
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$this->getCell(Cell::stringFromColumnIndex($col - 1) . $row)->setXfIndex($xfIndex); $this->getCell(Coordinate::stringFromColumnIndex($col - 1) . $row)->setXfIndex($xfIndex);
} }
} }
@ -1596,7 +1597,7 @@ class Worksheet implements IComparable
} }
// Calculate range outer borders // Calculate range outer borders
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($pRange . ':' . $pRange); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($pRange . ':' . $pRange);
// Make sure we can loop upwards on rows and columns // Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
@ -1608,7 +1609,7 @@ class Worksheet implements IComparable
// Loop through cells and apply styles // Loop through cells and apply styles
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$this->setConditionalStyles(Cell::stringFromColumnIndex($col - 1) . $row, $pCellStyle); $this->setConditionalStyles(Coordinate::stringFromColumnIndex($col - 1) . $row, $pCellStyle);
} }
} }
@ -1656,7 +1657,7 @@ class Worksheet implements IComparable
*/ */
public function setBreakByColumnAndRow($pColumn, $pRow, $pBreak) public function setBreakByColumnAndRow($pColumn, $pRow, $pBreak)
{ {
return $this->setBreak(Cell::stringFromColumnIndex($pColumn) . $pRow, $pBreak); return $this->setBreak(Coordinate::stringFromColumnIndex($pColumn) . $pRow, $pBreak);
} }
/** /**
@ -1689,7 +1690,7 @@ class Worksheet implements IComparable
// make sure cells are created // make sure cells are created
// get the cells in the range // get the cells in the range
$aReferences = Cell::extractAllCellReferencesInRange($pRange); $aReferences = Coordinate::extractAllCellReferencesInRange($pRange);
// create upper left cell if it does not already exist // create upper left cell if it does not already exist
$upperLeft = $aReferences[0]; $upperLeft = $aReferences[0];
@ -1725,7 +1726,7 @@ class Worksheet implements IComparable
*/ */
public function mergeCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2) public function mergeCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2)
{ {
$cellRange = Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Cell::stringFromColumnIndex($pColumn2) . $pRow2; $cellRange = Coordinate::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Coordinate::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->mergeCells($cellRange); return $this->mergeCells($cellRange);
} }
@ -1771,7 +1772,7 @@ class Worksheet implements IComparable
*/ */
public function unmergeCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2) public function unmergeCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2)
{ {
$cellRange = Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Cell::stringFromColumnIndex($pColumn2) . $pRow2; $cellRange = Coordinate::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Coordinate::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->unmergeCells($cellRange); return $this->unmergeCells($cellRange);
} }
@ -1840,7 +1841,7 @@ class Worksheet implements IComparable
*/ */
public function protectCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2, $pPassword, $pAlreadyHashed = false) public function protectCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2, $pPassword, $pAlreadyHashed = false)
{ {
$cellRange = Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Cell::stringFromColumnIndex($pColumn2) . $pRow2; $cellRange = Coordinate::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Coordinate::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed); return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed);
} }
@ -1882,7 +1883,7 @@ class Worksheet implements IComparable
*/ */
public function unprotectCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2) public function unprotectCellsByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2)
{ {
$cellRange = Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Cell::stringFromColumnIndex($pColumn2) . $pRow2; $cellRange = Coordinate::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . Coordinate::stringFromColumnIndex($pColumn2) . $pRow2;
return $this->unprotectCells($cellRange); return $this->unprotectCells($cellRange);
} }
@ -1943,9 +1944,9 @@ class Worksheet implements IComparable
public function setAutoFilterByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2) public function setAutoFilterByColumnAndRow($pColumn1, $pRow1, $pColumn2, $pRow2)
{ {
return $this->setAutoFilter( return $this->setAutoFilter(
Cell::stringFromColumnIndex($pColumn1) . $pRow1 Coordinate::stringFromColumnIndex($pColumn1) . $pRow1
. ':' . . ':' .
Cell::stringFromColumnIndex($pColumn2) . $pRow2 Coordinate::stringFromColumnIndex($pColumn2) . $pRow2
); );
} }
@ -2010,7 +2011,7 @@ class Worksheet implements IComparable
*/ */
public function freezePaneByColumnAndRow($pColumn, $pRow) public function freezePaneByColumnAndRow($pColumn, $pRow)
{ {
return $this->freezePane(Cell::stringFromColumnIndex($pColumn) . $pRow); return $this->freezePane(Coordinate::stringFromColumnIndex($pColumn) . $pRow);
} }
/** /**
@ -2080,7 +2081,7 @@ class Worksheet implements IComparable
public function insertNewColumnBeforeByIndex($pBefore, $pNumCols = 1) public function insertNewColumnBeforeByIndex($pBefore, $pNumCols = 1)
{ {
if ($pBefore >= 0) { if ($pBefore >= 0) {
return $this->insertNewColumnBefore(Cell::stringFromColumnIndex($pBefore), $pNumCols); return $this->insertNewColumnBefore(Coordinate::stringFromColumnIndex($pBefore), $pNumCols);
} }
throw new Exception('Columns can only be inserted before at least column A (0).'); throw new Exception('Columns can only be inserted before at least column A (0).');
@ -2127,12 +2128,12 @@ class Worksheet implements IComparable
{ {
if (!is_numeric($pColumn)) { if (!is_numeric($pColumn)) {
$highestColumn = $this->getHighestDataColumn(); $highestColumn = $this->getHighestDataColumn();
$pColumn = Cell::stringFromColumnIndex(Cell::columnIndexFromString($pColumn) - 1 + $pNumCols); $pColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($pColumn) - 1 + $pNumCols);
$objReferenceHelper = ReferenceHelper::getInstance(); $objReferenceHelper = ReferenceHelper::getInstance();
$objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this); $objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
for ($c = 0; $c < $pNumCols; ++$c) { for ($c = 0; $c < $pNumCols; ++$c) {
$this->getCellCollection()->removeColumn($highestColumn); $this->getCellCollection()->removeColumn($highestColumn);
$highestColumn = Cell::stringFromColumnIndex(Cell::columnIndexFromString($highestColumn) - 2); $highestColumn = Coordinate::stringFromColumnIndex(Coordinate::columnIndexFromString($highestColumn) - 2);
} }
} else { } else {
throw new Exception('Column references should not be numeric.'); throw new Exception('Column references should not be numeric.');
@ -2154,7 +2155,7 @@ class Worksheet implements IComparable
public function removeColumnByIndex($pColumn, $pNumCols = 1) public function removeColumnByIndex($pColumn, $pNumCols = 1)
{ {
if ($pColumn >= 0) { if ($pColumn >= 0) {
return $this->removeColumn(Cell::stringFromColumnIndex($pColumn), $pNumCols); return $this->removeColumn(Coordinate::stringFromColumnIndex($pColumn), $pNumCols);
} }
throw new Exception('Columns to be deleted should at least start from column 0'); throw new Exception('Columns to be deleted should at least start from column 0');
@ -2349,7 +2350,7 @@ class Worksheet implements IComparable
*/ */
public function getCommentByColumnAndRow($pColumn, $pRow) public function getCommentByColumnAndRow($pColumn, $pRow)
{ {
return $this->getComment(Cell::stringFromColumnIndex($pColumn) . $pRow); return $this->getComment(Coordinate::stringFromColumnIndex($pColumn) . $pRow);
} }
/** /**
@ -2411,7 +2412,7 @@ class Worksheet implements IComparable
$pCoordinate = preg_replace('/^([0-9]+):([0-9]+)$/', 'A${1}:XFD${2}', $pCoordinate); $pCoordinate = preg_replace('/^([0-9]+):([0-9]+)$/', 'A${1}:XFD${2}', $pCoordinate);
if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) { if (strpos($pCoordinate, ':') !== false || strpos($pCoordinate, ',') !== false) {
list($first) = Cell::splitRange($pCoordinate); list($first) = Coordinate::splitRange($pCoordinate);
$this->activeCell = $first[0]; $this->activeCell = $first[0];
} else { } else {
$this->activeCell = $pCoordinate; $this->activeCell = $pCoordinate;
@ -2433,7 +2434,7 @@ class Worksheet implements IComparable
*/ */
public function setSelectedCellByColumnAndRow($pColumn, $pRow) public function setSelectedCellByColumnAndRow($pColumn, $pRow)
{ {
return $this->setSelectedCells(Cell::stringFromColumnIndex($pColumn) . $pRow); return $this->setSelectedCells(Coordinate::stringFromColumnIndex($pColumn) . $pRow);
} }
/** /**
@ -2480,7 +2481,7 @@ class Worksheet implements IComparable
} }
// start coordinate // start coordinate
list($startColumn, $startRow) = Cell::coordinateFromString($startCell); list($startColumn, $startRow) = Coordinate::coordinateFromString($startCell);
// Loop through $source // Loop through $source
foreach ($source as $rowData) { foreach ($source as $rowData) {
@ -2522,10 +2523,10 @@ class Worksheet implements IComparable
// Returnvalue // Returnvalue
$returnValue = []; $returnValue = [];
// Identify the range that we need to extract from the worksheet // Identify the range that we need to extract from the worksheet
list($rangeStart, $rangeEnd) = Cell::rangeBoundaries($pRange); list($rangeStart, $rangeEnd) = Coordinate::rangeBoundaries($pRange);
$minCol = Cell::stringFromColumnIndex($rangeStart[0] - 1); $minCol = Coordinate::stringFromColumnIndex($rangeStart[0] - 1);
$minRow = $rangeStart[1]; $minRow = $rangeStart[1];
$maxCol = Cell::stringFromColumnIndex($rangeEnd[0] - 1); $maxCol = Coordinate::stringFromColumnIndex($rangeEnd[0] - 1);
$maxRow = $rangeEnd[1]; $maxRow = $rangeEnd[1];
++$maxCol; ++$maxCol;
@ -2664,11 +2665,11 @@ class Worksheet implements IComparable
// Lookup highest column and highest row if cells are cleaned // Lookup highest column and highest row if cells are cleaned
$colRow = $this->cellCollection->getHighestRowAndColumn(); $colRow = $this->cellCollection->getHighestRowAndColumn();
$highestRow = $colRow['row']; $highestRow = $colRow['row'];
$highestColumn = Cell::columnIndexFromString($colRow['column']); $highestColumn = Coordinate::columnIndexFromString($colRow['column']);
// Loop through column dimensions // Loop through column dimensions
foreach ($this->columnDimensions as $dimension) { foreach ($this->columnDimensions as $dimension) {
$highestColumn = max($highestColumn, Cell::columnIndexFromString($dimension->getColumnIndex())); $highestColumn = max($highestColumn, Coordinate::columnIndexFromString($dimension->getColumnIndex()));
} }
// Loop through row dimensions // Loop through row dimensions
@ -2680,7 +2681,7 @@ class Worksheet implements IComparable
if ($highestColumn < 0) { if ($highestColumn < 0) {
$this->cachedHighestColumn = 'A'; $this->cachedHighestColumn = 'A';
} else { } else {
$this->cachedHighestColumn = Cell::stringFromColumnIndex(--$highestColumn); $this->cachedHighestColumn = Coordinate::stringFromColumnIndex(--$highestColumn);
} }
$this->cachedHighestRow = $highestRow; $this->cachedHighestRow = $highestRow;
@ -2857,20 +2858,20 @@ class Worksheet implements IComparable
{ {
$maxCol = $this->getHighestColumn(); $maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow(); $maxRow = $this->getHighestRow();
$maxCol = Cell::columnIndexFromString($maxCol); $maxCol = Coordinate::columnIndexFromString($maxCol);
$rangeBlocks = explode(' ', $range); $rangeBlocks = explode(' ', $range);
foreach ($rangeBlocks as &$rangeSet) { foreach ($rangeBlocks as &$rangeSet) {
$rangeBoundaries = Cell::getRangeBoundaries($rangeSet); $rangeBoundaries = Coordinate::getRangeBoundaries($rangeSet);
if (Cell::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) { if (Coordinate::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) {
$rangeBoundaries[0][0] = Cell::stringFromColumnIndex($maxCol); $rangeBoundaries[0][0] = Coordinate::stringFromColumnIndex($maxCol);
} }
if ($rangeBoundaries[0][1] > $maxRow) { if ($rangeBoundaries[0][1] > $maxRow) {
$rangeBoundaries[0][1] = $maxRow; $rangeBoundaries[0][1] = $maxRow;
} }
if (Cell::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) { if (Coordinate::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) {
$rangeBoundaries[1][0] = Cell::stringFromColumnIndex($maxCol); $rangeBoundaries[1][0] = Coordinate::stringFromColumnIndex($maxCol);
} }
if ($rangeBoundaries[1][1] > $maxRow) { if ($rangeBoundaries[1][1] > $maxRow) {
$rangeBoundaries[1][1] = $maxRow; $rangeBoundaries[1][1] = $maxRow;

View File

@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\RichText\Run; use PhpOffice\PhpSpreadsheet\RichText\Run;
@ -432,10 +433,10 @@ class Html extends BaseWriter
// Get worksheet dimension // Get worksheet dimension
$dimension = explode(':', $sheet->calculateWorksheetDimension()); $dimension = explode(':', $sheet->calculateWorksheetDimension());
$dimension[0] = Cell::coordinateFromString($dimension[0]); $dimension[0] = Coordinate::coordinateFromString($dimension[0]);
$dimension[0][0] = Cell::columnIndexFromString($dimension[0][0]) - 1; $dimension[0][0] = Coordinate::columnIndexFromString($dimension[0][0]) - 1;
$dimension[1] = Cell::coordinateFromString($dimension[1]); $dimension[1] = Coordinate::coordinateFromString($dimension[1]);
$dimension[1][0] = Cell::columnIndexFromString($dimension[1][0]) - 1; $dimension[1][0] = Coordinate::columnIndexFromString($dimension[1][0]) - 1;
// row min,max // row min,max
$rowMin = $dimension[0][1]; $rowMin = $dimension[0][1];
@ -479,7 +480,7 @@ class Html extends BaseWriter
while ($column++ < $dimension[1][0]) { while ($column++ < $dimension[1][0]) {
// Cell exists? // Cell exists?
if ($sheet->cellExistsByColumnAndRow($column, $row)) { if ($sheet->cellExistsByColumnAndRow($column, $row)) {
$rowData[$column] = Cell::stringFromColumnIndex($column) . $row; $rowData[$column] = Coordinate::stringFromColumnIndex($column) . $row;
} else { } else {
$rowData[$column] = ''; $rowData[$column] = '';
} }
@ -565,11 +566,11 @@ class Html extends BaseWriter
foreach ($pSheet->getChartCollection() as $chart) { foreach ($pSheet->getChartCollection() as $chart) {
if ($chart instanceof Chart) { if ($chart instanceof Chart) {
$chartCoordinates = $chart->getTopLeftPosition(); $chartCoordinates = $chart->getTopLeftPosition();
$chartTL = Cell::coordinateFromString($chartCoordinates['cell']); $chartTL = Coordinate::coordinateFromString($chartCoordinates['cell']);
$chartCol = Cell::columnIndexFromString($chartTL[0]); $chartCol = Coordinate::columnIndexFromString($chartTL[0]);
if ($chartTL[1] > $rowMax) { if ($chartTL[1] > $rowMax) {
$rowMax = $chartTL[1]; $rowMax = $chartTL[1];
if ($chartCol > Cell::columnIndexFromString($colMax)) { if ($chartCol > Coordinate::columnIndexFromString($colMax)) {
$colMax = $chartTL[0]; $colMax = $chartTL[0];
} }
} }
@ -579,11 +580,11 @@ class Html extends BaseWriter
foreach ($pSheet->getDrawingCollection() as $drawing) { foreach ($pSheet->getDrawingCollection() as $drawing) {
if ($drawing instanceof Drawing) { if ($drawing instanceof Drawing) {
$imageTL = Cell::coordinateFromString($drawing->getCoordinates()); $imageTL = Coordinate::coordinateFromString($drawing->getCoordinates());
$imageCol = Cell::columnIndexFromString($imageTL[0]); $imageCol = Coordinate::columnIndexFromString($imageTL[0]);
if ($imageTL[1] > $rowMax) { if ($imageTL[1] > $rowMax) {
$rowMax = $imageTL[1]; $rowMax = $imageTL[1];
if ($imageCol > Cell::columnIndexFromString($colMax)) { if ($imageCol > Coordinate::columnIndexFromString($colMax)) {
$colMax = $imageTL[0]; $colMax = $imageTL[0];
} }
} }
@ -880,7 +881,7 @@ class Html extends BaseWriter
$sheet->calculateColumnWidths(); $sheet->calculateColumnWidths();
// col elements, initialize // col elements, initialize
$highestColumnIndex = Cell::columnIndexFromString($sheet->getHighestColumn()) - 1; $highestColumnIndex = Coordinate::columnIndexFromString($sheet->getHighestColumn()) - 1;
$column = -1; $column = -1;
while ($column++ < $highestColumnIndex) { while ($column++ < $highestColumnIndex) {
$this->columnWidths[$sheetIndex][$column] = 42; // approximation $this->columnWidths[$sheetIndex][$column] = 42; // approximation
@ -891,7 +892,7 @@ class Html extends BaseWriter
foreach ($sheet->getColumnDimensions() as $columnDimension) { foreach ($sheet->getColumnDimensions() as $columnDimension) {
if (($width = SharedDrawing::cellDimensionToPixels($columnDimension->getWidth(), $this->defaultFont)) >= 0) { if (($width = SharedDrawing::cellDimensionToPixels($columnDimension->getWidth(), $this->defaultFont)) >= 0) {
$width = SharedDrawing::pixelsToPoints($width); $width = SharedDrawing::pixelsToPoints($width);
$column = Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1; $column = Coordinate::columnIndexFromString($columnDimension->getColumnIndex()) - 1;
$this->columnWidths[$sheetIndex][$column] = $width; $this->columnWidths[$sheetIndex][$column] = $width;
$css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt'; $css['table.sheet' . $sheetIndex . ' col.col' . $column]['width'] = $width . 'pt';
@ -1129,7 +1130,7 @@ class Html extends BaseWriter
} }
// Write <col> elements // Write <col> elements
$highestColumnIndex = Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1; $highestColumnIndex = Coordinate::columnIndexFromString($pSheet->getHighestColumn()) - 1;
$i = -1; $i = -1;
while ($i++ < $highestColumnIndex) { while ($i++ < $highestColumnIndex) {
if (!$this->isPdf) { if (!$this->isPdf) {
@ -1209,7 +1210,7 @@ class Html extends BaseWriter
$colNum = 0; $colNum = 0;
foreach ($pValues as $cellAddress) { foreach ($pValues as $cellAddress) {
$cell = ($cellAddress > '') ? $pSheet->getCell($cellAddress) : ''; $cell = ($cellAddress > '') ? $pSheet->getCell($cellAddress) : '';
$coordinate = Cell::stringFromColumnIndex($colNum) . ($pRow + 1); $coordinate = Coordinate::stringFromColumnIndex($colNum) . ($pRow + 1);
if (!$this->useInlineCss) { if (!$this->useInlineCss) {
$cssClass = 'column' . $colNum; $cssClass = 'column' . $colNum;
} else { } else {
@ -1339,7 +1340,7 @@ class Html extends BaseWriter
// Also apply style from last cell in merge to fix borders - // Also apply style from last cell in merge to fix borders -
// relies on !important for non-none border declarations in createCSSStyleBorder // relies on !important for non-none border declarations in createCSSStyleBorder
$endCellCoord = Cell::stringFromColumnIndex($colNum + $colSpan - 1) . ($pRow + $rowSpan); $endCellCoord = Coordinate::stringFromColumnIndex($colNum + $colSpan - 1) . ($pRow + $rowSpan);
if (!$this->useInlineCss) { if (!$this->useInlineCss) {
$cssClass .= ' style' . $pSheet->getCell($endCellCoord)->getXfIndex(); $cssClass .= ' style' . $pSheet->getCell($endCellCoord)->getXfIndex();
} }
@ -1549,15 +1550,15 @@ class Html extends BaseWriter
// loop through all Excel merged cells // loop through all Excel merged cells
foreach ($sheet->getMergeCells() as $cells) { foreach ($sheet->getMergeCells() as $cells) {
list($cells) = Cell::splitRange($cells); list($cells) = Coordinate::splitRange($cells);
$first = $cells[0]; $first = $cells[0];
$last = $cells[1]; $last = $cells[1];
list($fc, $fr) = Cell::coordinateFromString($first); list($fc, $fr) = Coordinate::coordinateFromString($first);
$fc = Cell::columnIndexFromString($fc) - 1; $fc = Coordinate::columnIndexFromString($fc) - 1;
list($lc, $lr) = Cell::coordinateFromString($last); list($lc, $lr) = Coordinate::coordinateFromString($last);
$lc = Cell::columnIndexFromString($lc) - 1; $lc = Coordinate::columnIndexFromString($lc) - 1;
// loop through the individual cells in the individual merge // loop through the individual cells in the individual merge
$r = $fr - 1; $r = $fr - 1;
@ -1587,7 +1588,7 @@ class Html extends BaseWriter
// Identify which rows should be omitted in HTML. These are the rows where all the cells // Identify which rows should be omitted in HTML. These are the rows where all the cells
// participate in a merge and the where base cells are somewhere above. // participate in a merge and the where base cells are somewhere above.
$countColumns = Cell::columnIndexFromString($sheet->getHighestColumn()); $countColumns = Coordinate::columnIndexFromString($sheet->getHighestColumn());
foreach ($candidateSpannedRow as $rowIndex) { foreach ($candidateSpannedRow as $rowIndex) {
if (isset($this->isSpannedCell[$sheetIndex][$rowIndex])) { if (isset($this->isSpannedCell[$sheetIndex][$rowIndex])) {
if (count($this->isSpannedCell[$sheetIndex][$rowIndex]) == $countColumns) { if (count($this->isSpannedCell[$sheetIndex][$rowIndex]) == $countColumns) {

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Ods; namespace PhpOffice\PhpSpreadsheet\Writer\Ods;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
@ -179,7 +179,7 @@ class Content extends WriterPart
while ($cells->valid()) { while ($cells->valid()) {
/** @var \PhpOffice\PhpSpreadsheet\Cell\Cell $cell */ /** @var \PhpOffice\PhpSpreadsheet\Cell\Cell $cell */
$cell = $cells->current(); $cell = $cells->current();
$column = Cell::columnIndexFromString($cell->getColumn()) - 1; $column = Coordinate::columnIndexFromString($cell->getColumn()) - 1;
$this->writeCellSpan($objWriter, $column, $prevColumn); $this->writeCellSpan($objWriter, $column, $prevColumn);
$objWriter->startElement('table:table-cell'); $objWriter->startElement('table:table-cell');

View File

@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\RichText\Run; use PhpOffice\PhpSpreadsheet\RichText\Run;
use PhpOffice\PhpSpreadsheet\Shared\Drawing as SharedDrawing; use PhpOffice\PhpSpreadsheet\Shared\Drawing as SharedDrawing;
@ -323,7 +323,7 @@ class Xls extends BaseWriter
// AutoFilters // AutoFilters
if (!empty($filterRange)) { if (!empty($filterRange)) {
$rangeBounds = Cell::rangeBoundaries($filterRange); $rangeBounds = Coordinate::rangeBoundaries($filterRange);
$iNumColStart = $rangeBounds[0][0]; $iNumColStart = $rangeBounds[0][0];
$iNumColEnd = $rangeBounds[1][0]; $iNumColEnd = $rangeBounds[1][0];
@ -334,7 +334,7 @@ class Xls extends BaseWriter
// create an Drawing Object for the dropdown // create an Drawing Object for the dropdown
$oDrawing = new BaseDrawing(); $oDrawing = new BaseDrawing();
// get the coordinates of drawing // get the coordinates of drawing
$cDrawing = Cell::stringFromColumnIndex($iInc - 1) . $rangeBounds[0][1]; $cDrawing = Coordinate::stringFromColumnIndex($iInc - 1) . $rangeBounds[0][1];
$oDrawing->setCoordinates($cDrawing); $oDrawing->setCoordinates($cDrawing);
$oDrawing->setWorksheet($sheet); $oDrawing->setWorksheet($sheet);
@ -363,7 +363,7 @@ class Xls extends BaseWriter
$spContainer->setOPT(0x03BF, 0x000A0000); // Group Shape -> fPrint $spContainer->setOPT(0x03BF, 0x000A0000); // Group Shape -> fPrint
// set coordinates and offsets, client anchor // set coordinates and offsets, client anchor
$endCoordinates = Cell::stringFromColumnIndex($iInc - 1); $endCoordinates = Coordinate::stringFromColumnIndex($iInc - 1);
$endCoordinates .= $rangeBounds[0][1] + 1; $endCoordinates .= $rangeBounds[0][1] + 1;
$spContainer->setStartCoordinates($cDrawing); $spContainer->setStartCoordinates($cDrawing);

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xls; namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer; use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer;
use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer;
use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer; use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer\SpContainer;
@ -421,8 +421,8 @@ class Escher
$recType = 0xF010; $recType = 0xF010;
// start coordinates // start coordinates
list($column, $row) = Cell::coordinateFromString($this->object->getStartCoordinates()); list($column, $row) = Coordinate::coordinateFromString($this->object->getStartCoordinates());
$c1 = Cell::columnIndexFromString($column) - 1; $c1 = Coordinate::columnIndexFromString($column) - 1;
$r1 = $row - 1; $r1 = $row - 1;
// start offsetX // start offsetX
@ -432,8 +432,8 @@ class Escher
$startOffsetY = $this->object->getStartOffsetY(); $startOffsetY = $this->object->getStartOffsetY();
// end coordinates // end coordinates
list($column, $row) = Cell::coordinateFromString($this->object->getEndCoordinates()); list($column, $row) = Coordinate::coordinateFromString($this->object->getEndCoordinates());
$c2 = Cell::columnIndexFromString($column) - 1; $c2 = Coordinate::columnIndexFromString($column) - 1;
$r2 = $row - 1; $r2 = $row - 1;
// end offsetX // end offsetX

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xls; namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
@ -542,14 +542,14 @@ class Workbook extends BIFFwriter
$namedRanges = $this->spreadsheet->getNamedRanges(); $namedRanges = $this->spreadsheet->getNamedRanges();
foreach ($namedRanges as $namedRange) { foreach ($namedRanges as $namedRange) {
// Create absolute coordinate // Create absolute coordinate
$range = Cell::splitRange($namedRange->getRange()); $range = Coordinate::splitRange($namedRange->getRange());
for ($i = 0; $i < count($range); ++$i) { for ($i = 0; $i < count($range); ++$i) {
$range[$i][0] = '\'' . str_replace("'", "''", $namedRange->getWorksheet()->getTitle()) . '\'!' . Cell::absoluteCoordinate($range[$i][0]); $range[$i][0] = '\'' . str_replace("'", "''", $namedRange->getWorksheet()->getTitle()) . '\'!' . Coordinate::absoluteCoordinate($range[$i][0]);
if (isset($range[$i][1])) { if (isset($range[$i][1])) {
$range[$i][1] = Cell::absoluteCoordinate($range[$i][1]); $range[$i][1] = Coordinate::absoluteCoordinate($range[$i][1]);
} }
} }
$range = Cell::buildRange($range); // e.g. Sheet1!$A$1:$B$2 $range = Coordinate::buildRange($range); // e.g. Sheet1!$A$1:$B$2
// parse formula // parse formula
try { try {
@ -584,8 +584,8 @@ class Workbook extends BIFFwriter
// simultaneous repeatColumns repeatRows // simultaneous repeatColumns repeatRows
if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) { if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) {
$repeat = $sheetSetup->getColumnsToRepeatAtLeft(); $repeat = $sheetSetup->getColumnsToRepeatAtLeft();
$colmin = Cell::columnIndexFromString($repeat[0]) - 1; $colmin = Coordinate::columnIndexFromString($repeat[0]) - 1;
$colmax = Cell::columnIndexFromString($repeat[1]) - 1; $colmax = Coordinate::columnIndexFromString($repeat[1]) - 1;
$repeat = $sheetSetup->getRowsToRepeatAtTop(); $repeat = $sheetSetup->getRowsToRepeatAtTop();
$rowmin = $repeat[0] - 1; $rowmin = $repeat[0] - 1;
@ -605,8 +605,8 @@ class Workbook extends BIFFwriter
// Columns to repeat // Columns to repeat
if ($sheetSetup->isColumnsToRepeatAtLeftSet()) { if ($sheetSetup->isColumnsToRepeatAtLeftSet()) {
$repeat = $sheetSetup->getColumnsToRepeatAtLeft(); $repeat = $sheetSetup->getColumnsToRepeatAtLeft();
$colmin = Cell::columnIndexFromString($repeat[0]) - 1; $colmin = Coordinate::columnIndexFromString($repeat[0]) - 1;
$colmax = Cell::columnIndexFromString($repeat[1]) - 1; $colmax = Coordinate::columnIndexFromString($repeat[1]) - 1;
} else { } else {
$colmin = 0; $colmin = 0;
$colmax = 255; $colmax = 255;
@ -634,19 +634,19 @@ class Workbook extends BIFFwriter
$sheetSetup = $this->spreadsheet->getSheet($i)->getPageSetup(); $sheetSetup = $this->spreadsheet->getSheet($i)->getPageSetup();
if ($sheetSetup->isPrintAreaSet()) { if ($sheetSetup->isPrintAreaSet()) {
// Print area, e.g. A3:J6,H1:X20 // Print area, e.g. A3:J6,H1:X20
$printArea = Cell::splitRange($sheetSetup->getPrintArea()); $printArea = Coordinate::splitRange($sheetSetup->getPrintArea());
$countPrintArea = count($printArea); $countPrintArea = count($printArea);
$formulaData = ''; $formulaData = '';
for ($j = 0; $j < $countPrintArea; ++$j) { for ($j = 0; $j < $countPrintArea; ++$j) {
$printAreaRect = $printArea[$j]; // e.g. A3:J6 $printAreaRect = $printArea[$j]; // e.g. A3:J6
$printAreaRect[0] = Cell::coordinateFromString($printAreaRect[0]); $printAreaRect[0] = Coordinate::coordinateFromString($printAreaRect[0]);
$printAreaRect[1] = Cell::coordinateFromString($printAreaRect[1]); $printAreaRect[1] = Coordinate::coordinateFromString($printAreaRect[1]);
$print_rowmin = $printAreaRect[0][1] - 1; $print_rowmin = $printAreaRect[0][1] - 1;
$print_rowmax = $printAreaRect[1][1] - 1; $print_rowmax = $printAreaRect[1][1] - 1;
$print_colmin = Cell::columnIndexFromString($printAreaRect[0][0]) - 1; $print_colmin = Coordinate::columnIndexFromString($printAreaRect[0][0]) - 1;
$print_colmax = Cell::columnIndexFromString($printAreaRect[1][0]) - 1; $print_colmax = Coordinate::columnIndexFromString($printAreaRect[1][0]) - 1;
// construct formula data manually because parser does not recognize absolute 3d cell references // construct formula data manually because parser does not recognize absolute 3d cell references
$formulaData .= pack('Cvvvvv', 0x3B, $i, $print_rowmin, $print_rowmax, $print_colmin, $print_colmax); $formulaData .= pack('Cvvvvv', 0x3B, $i, $print_rowmin, $print_rowmax, $print_colmin, $print_colmax);
@ -666,7 +666,7 @@ class Workbook extends BIFFwriter
$sheetAutoFilter = $this->spreadsheet->getSheet($i)->getAutoFilter(); $sheetAutoFilter = $this->spreadsheet->getSheet($i)->getAutoFilter();
$autoFilterRange = $sheetAutoFilter->getRange(); $autoFilterRange = $sheetAutoFilter->getRange();
if (!empty($autoFilterRange)) { if (!empty($autoFilterRange)) {
$rangeBounds = Cell::rangeBoundaries($autoFilterRange); $rangeBounds = Coordinate::rangeBoundaries($autoFilterRange);
//Autofilter built in name //Autofilter built in name
$name = pack('C', 0x0D); $name = pack('C', 0x0D);

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xls; namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation; use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
@ -260,8 +260,8 @@ class Worksheet extends BIFFwriter
// Determine lowest and highest column and row // Determine lowest and highest column and row
$this->lastRowIndex = ($maxR > 65535) ? 65535 : $maxR; $this->lastRowIndex = ($maxR > 65535) ? 65535 : $maxR;
$this->firstColumnIndex = Cell::columnIndexFromString($minC); $this->firstColumnIndex = Coordinate::columnIndexFromString($minC);
$this->lastColumnIndex = Cell::columnIndexFromString($maxC); $this->lastColumnIndex = Coordinate::columnIndexFromString($maxC);
// if ($this->firstColumnIndex > 255) $this->firstColumnIndex = 255; // if ($this->firstColumnIndex > 255) $this->firstColumnIndex = 255;
if ($this->lastColumnIndex > 255) { if ($this->lastColumnIndex > 255) {
@ -310,7 +310,7 @@ class Worksheet extends BIFFwriter
$width = $defaultWidth; $width = $defaultWidth;
$columnLetter = Cell::stringFromColumnIndex($i); $columnLetter = Coordinate::stringFromColumnIndex($i);
if (isset($columnDimensions[$columnLetter])) { if (isset($columnDimensions[$columnLetter])) {
$columnDimension = $columnDimensions[$columnLetter]; $columnDimension = $columnDimensions[$columnLetter];
if ($columnDimension->getWidth() >= 0) { if ($columnDimension->getWidth() >= 0) {
@ -395,7 +395,7 @@ class Worksheet extends BIFFwriter
foreach ($phpSheet->getCoordinates() as $coordinate) { foreach ($phpSheet->getCoordinates() as $coordinate) {
$cell = $phpSheet->getCell($coordinate); $cell = $phpSheet->getCell($coordinate);
$row = $cell->getRow() - 1; $row = $cell->getRow() - 1;
$column = Cell::columnIndexFromString($cell->getColumn()) - 1; $column = Coordinate::columnIndexFromString($cell->getColumn()) - 1;
// Don't break Excel break the code! // Don't break Excel break the code!
if ($row > 65535 || $column > 255) { if ($row > 65535 || $column > 255) {
@ -479,7 +479,7 @@ class Worksheet extends BIFFwriter
// Hyperlinks // Hyperlinks
foreach ($phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) { foreach ($phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) {
list($column, $row) = Cell::coordinateFromString($coordinate); list($column, $row) = Coordinate::coordinateFromString($coordinate);
$url = $hyperlink->getUrl(); $url = $hyperlink->getUrl();
@ -493,7 +493,7 @@ class Worksheet extends BIFFwriter
$url = 'external:' . $url; $url = 'external:' . $url;
} }
$this->writeUrl($row - 1, Cell::columnIndexFromString($column) - 1, $url); $this->writeUrl($row - 1, Coordinate::columnIndexFromString($column) - 1, $url);
} }
$this->writeDataValidity(); $this->writeDataValidity();
@ -552,10 +552,10 @@ class Worksheet extends BIFFwriter
$lastCell = $explodes[1]; $lastCell = $explodes[1];
} }
$firstCellCoordinates = Cell::coordinateFromString($firstCell); // e.g. array(0, 1) $firstCellCoordinates = Coordinate::coordinateFromString($firstCell); // e.g. array(0, 1)
$lastCellCoordinates = Cell::coordinateFromString($lastCell); // e.g. array(1, 6) $lastCellCoordinates = Coordinate::coordinateFromString($lastCell); // e.g. array(1, 6)
return pack('vvvv', $firstCellCoordinates[1] - 1, $lastCellCoordinates[1] - 1, Cell::columnIndexFromString($firstCellCoordinates[0]) - 1, Cell::columnIndexFromString($lastCellCoordinates[0]) - 1); return pack('vvvv', $firstCellCoordinates[1] - 1, $lastCellCoordinates[1] - 1, Coordinate::columnIndexFromString($firstCellCoordinates[0]) - 1, Coordinate::columnIndexFromString($lastCellCoordinates[0]) - 1);
} }
/** /**
@ -1353,7 +1353,7 @@ class Worksheet extends BIFFwriter
private function writeSelection() private function writeSelection()
{ {
// look up the selected cell range // look up the selected cell range
$selectedCells = Cell::splitRange($this->phpSheet->getSelectedCells()); $selectedCells = Coordinate::splitRange($this->phpSheet->getSelectedCells());
$selectedCells = $selectedCells[0]; $selectedCells = $selectedCells[0];
if (count($selectedCells) == 2) { if (count($selectedCells) == 2) {
list($first, $last) = $selectedCells; list($first, $last) = $selectedCells;
@ -1362,12 +1362,12 @@ class Worksheet extends BIFFwriter
$last = $selectedCells[0]; $last = $selectedCells[0];
} }
list($colFirst, $rwFirst) = Cell::coordinateFromString($first); list($colFirst, $rwFirst) = Coordinate::coordinateFromString($first);
$colFirst = Cell::columnIndexFromString($colFirst) - 1; // base 0 column index $colFirst = Coordinate::columnIndexFromString($colFirst) - 1; // base 0 column index
--$rwFirst; // base 0 row index --$rwFirst; // base 0 row index
list($colLast, $rwLast) = Cell::coordinateFromString($last); list($colLast, $rwLast) = Coordinate::coordinateFromString($last);
$colLast = Cell::columnIndexFromString($colLast) - 1; // base 0 column index $colLast = Coordinate::columnIndexFromString($colLast) - 1; // base 0 column index
--$rwLast; // base 0 row index --$rwLast; // base 0 row index
// make sure we are not out of bounds // make sure we are not out of bounds
@ -1440,12 +1440,12 @@ class Worksheet extends BIFFwriter
++$j; ++$j;
// extract the row and column indexes // extract the row and column indexes
$range = Cell::splitRange($mergeCell); $range = Coordinate::splitRange($mergeCell);
list($first, $last) = $range[0]; list($first, $last) = $range[0];
list($firstColumn, $firstRow) = Cell::coordinateFromString($first); list($firstColumn, $firstRow) = Coordinate::coordinateFromString($first);
list($lastColumn, $lastRow) = Cell::coordinateFromString($last); list($lastColumn, $lastRow) = Coordinate::coordinateFromString($last);
$recordData .= pack('vvvv', $firstRow - 1, $lastRow - 1, Cell::columnIndexFromString($firstColumn) - 1, Cell::columnIndexFromString($lastColumn) - 1); $recordData .= pack('vvvv', $firstRow - 1, $lastRow - 1, Coordinate::columnIndexFromString($firstColumn) - 1, Coordinate::columnIndexFromString($lastColumn) - 1);
// flush record if we have reached limit for number of merged cells, or reached final merged cell // flush record if we have reached limit for number of merged cells, or reached final merged cell
if ($j == $maxCountMergeCellsPerRecord or $i == $countMergeCells) { if ($j == $maxCountMergeCellsPerRecord or $i == $countMergeCells) {
@ -1590,9 +1590,9 @@ class Worksheet extends BIFFwriter
{ {
$panes = []; $panes = [];
if ($freezePane = $this->phpSheet->getFreezePane()) { if ($freezePane = $this->phpSheet->getFreezePane()) {
list($column, $row) = Cell::coordinateFromString($freezePane); list($column, $row) = Coordinate::coordinateFromString($freezePane);
$panes[0] = $row - 1; $panes[0] = $row - 1;
$panes[1] = Cell::columnIndexFromString($column) - 1; $panes[1] = Coordinate::columnIndexFromString($column) - 1;
} else { } else {
// thaw panes // thaw panes
return; return;
@ -1933,7 +1933,7 @@ class Worksheet extends BIFFwriter
$record = 0x009D; // Record identifier $record = 0x009D; // Record identifier
$length = 0x0002; // Bytes to follow $length = 0x0002; // Bytes to follow
$rangeBounds = Cell::rangeBoundaries($this->phpSheet->getAutoFilter()->getRange()); $rangeBounds = Coordinate::rangeBoundaries($this->phpSheet->getAutoFilter()->getRange());
$iNumFilters = 1 + $rangeBounds[1][0] - $rangeBounds[0][0]; $iNumFilters = 1 + $rangeBounds[1][0] - $rangeBounds[0][0];
$header = pack('vv', $record, $length); $header = pack('vv', $record, $length);
@ -2035,13 +2035,13 @@ class Worksheet extends BIFFwriter
foreach ($this->phpSheet->getBreaks() as $cell => $breakType) { foreach ($this->phpSheet->getBreaks() as $cell => $breakType) {
// Fetch coordinates // Fetch coordinates
$coordinates = Cell::coordinateFromString($cell); $coordinates = Coordinate::coordinateFromString($cell);
// Decide what to do by the type of break // Decide what to do by the type of break
switch ($breakType) { switch ($breakType) {
case \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::BREAK_COLUMN: case \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::BREAK_COLUMN:
// Add to list of vertical breaks // Add to list of vertical breaks
$vbreaks[] = Cell::columnIndexFromString($coordinates[0]) - 1; $vbreaks[] = Coordinate::columnIndexFromString($coordinates[0]) - 1;
break; break;
case \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::BREAK_ROW: case \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::BREAK_ROW:
@ -2288,7 +2288,7 @@ class Worksheet extends BIFFwriter
$row_end = $row_start; // Row containing bottom right corner of object $row_end = $row_start; // Row containing bottom right corner of object
// Zero the specified offset if greater than the cell dimensions // Zero the specified offset if greater than the cell dimensions
if ($x1 >= Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_start))) { if ($x1 >= Xls::sizeCol($this->phpSheet, Coordinate::stringFromColumnIndex($col_start))) {
$x1 = 0; $x1 = 0;
} }
if ($y1 >= Xls::sizeRow($this->phpSheet, $row_start + 1)) { if ($y1 >= Xls::sizeRow($this->phpSheet, $row_start + 1)) {
@ -2299,8 +2299,8 @@ class Worksheet extends BIFFwriter
$height = $height + $y1 - 1; $height = $height + $y1 - 1;
// Subtract the underlying cell widths to find the end cell of the image // Subtract the underlying cell widths to find the end cell of the image
while ($width >= Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end))) { while ($width >= Xls::sizeCol($this->phpSheet, Coordinate::stringFromColumnIndex($col_end))) {
$width -= Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end)); $width -= Xls::sizeCol($this->phpSheet, Coordinate::stringFromColumnIndex($col_end));
++$col_end; ++$col_end;
} }
@ -2313,10 +2313,10 @@ class Worksheet extends BIFFwriter
// Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell // Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
// with zero eight or width. // with zero eight or width.
// //
if (Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_start)) == 0) { if (Xls::sizeCol($this->phpSheet, Coordinate::stringFromColumnIndex($col_start)) == 0) {
return; return;
} }
if (Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end)) == 0) { if (Xls::sizeCol($this->phpSheet, Coordinate::stringFromColumnIndex($col_end)) == 0) {
return; return;
} }
if (Xls::sizeRow($this->phpSheet, $row_start + 1) == 0) { if (Xls::sizeRow($this->phpSheet, $row_start + 1) == 0) {
@ -2327,9 +2327,9 @@ class Worksheet extends BIFFwriter
} }
// Convert the pixel values to the percentage value expected by Excel // Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_start)) * 1024; $x1 = $x1 / Xls::sizeCol($this->phpSheet, Coordinate::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / Xls::sizeRow($this->phpSheet, $row_start + 1) * 256; $y1 = $y1 / Xls::sizeRow($this->phpSheet, $row_start + 1) * 256;
$x2 = $width / Xls::sizeCol($this->phpSheet, Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object $x2 = $width / Xls::sizeCol($this->phpSheet, Coordinate::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = $height / Xls::sizeRow($this->phpSheet, $row_end + 1) * 256; // Distance to bottom of object $y2 = $height / Xls::sizeRow($this->phpSheet, $row_end + 1) * 256; // Distance to bottom of object
$this->writeObjPicture($col_start, $x1, $row_start, $y1, $col_end, $x2, $row_end, $y2); $this->writeObjPicture($col_start, $x1, $row_start, $y1, $col_end, $x2, $row_end, $y2);
@ -4413,9 +4413,9 @@ class Worksheet extends BIFFwriter
$arrConditional[] = $conditional->getHashCode(); $arrConditional[] = $conditional->getHashCode();
} }
// Cells // Cells
$arrCoord = Cell::coordinateFromString($cellCoordinate); $arrCoord = Coordinate::coordinateFromString($cellCoordinate);
if (!is_numeric($arrCoord[0])) { if (!is_numeric($arrCoord[0])) {
$arrCoord[0] = Cell::columnIndexFromString($arrCoord[0]); $arrCoord[0] = Coordinate::columnIndexFromString($arrCoord[0]);
} }
if ($numColumnMin === null || ($numColumnMin > $arrCoord[0])) { if ($numColumnMin === null || ($numColumnMin > $arrCoord[0])) {
$numColumnMin = $arrCoord[0]; $numColumnMin = $arrCoord[0];

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Comment; use PhpOffice\PhpSpreadsheet\Comment;
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
@ -177,8 +177,8 @@ class Comments extends WriterPart
private function writeVMLComment(XMLWriter $objWriter, $pCellReference, Comment $pComment) private function writeVMLComment(XMLWriter $objWriter, $pCellReference, Comment $pComment)
{ {
// Metadata // Metadata
list($column, $row) = Cell::coordinateFromString($pCellReference); list($column, $row) = Coordinate::coordinateFromString($pCellReference);
$column = Cell::columnIndexFromString($column); $column = Coordinate::columnIndexFromString($column);
$id = 1024 + $column + $row; $id = 1024 + $column + $row;
$id = substr($id, 0, 4); $id = substr($id, 0, 4);

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing; use PhpOffice\PhpSpreadsheet\Worksheet\BaseDrawing;
@ -77,20 +77,20 @@ class Drawing extends WriterPart
public function writeChart(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart\Chart $pChart, $pRelationId = -1) public function writeChart(XMLWriter $objWriter, \PhpOffice\PhpSpreadsheet\Chart\Chart $pChart, $pRelationId = -1)
{ {
$tl = $pChart->getTopLeftPosition(); $tl = $pChart->getTopLeftPosition();
$tl['colRow'] = Cell::coordinateFromString($tl['cell']); $tl['colRow'] = Coordinate::coordinateFromString($tl['cell']);
$br = $pChart->getBottomRightPosition(); $br = $pChart->getBottomRightPosition();
$br['colRow'] = Cell::coordinateFromString($br['cell']); $br['colRow'] = Coordinate::coordinateFromString($br['cell']);
$objWriter->startElement('xdr:twoCellAnchor'); $objWriter->startElement('xdr:twoCellAnchor');
$objWriter->startElement('xdr:from'); $objWriter->startElement('xdr:from');
$objWriter->writeElement('xdr:col', Cell::columnIndexFromString($tl['colRow'][0]) - 1); $objWriter->writeElement('xdr:col', Coordinate::columnIndexFromString($tl['colRow'][0]) - 1);
$objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['xOffset'])); $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['xOffset']));
$objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1); $objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1);
$objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['yOffset'])); $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($tl['yOffset']));
$objWriter->endElement(); $objWriter->endElement();
$objWriter->startElement('xdr:to'); $objWriter->startElement('xdr:to');
$objWriter->writeElement('xdr:col', Cell::columnIndexFromString($br['colRow'][0]) - 1); $objWriter->writeElement('xdr:col', Coordinate::columnIndexFromString($br['colRow'][0]) - 1);
$objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['xOffset'])); $objWriter->writeElement('xdr:colOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['xOffset']));
$objWriter->writeElement('xdr:row', $br['colRow'][1] - 1); $objWriter->writeElement('xdr:row', $br['colRow'][1] - 1);
$objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['yOffset'])); $objWriter->writeElement('xdr:rowOff', \PhpOffice\PhpSpreadsheet\Shared\Drawing::pixelsToEMU($br['yOffset']));
@ -153,8 +153,8 @@ class Drawing extends WriterPart
// xdr:oneCellAnchor // xdr:oneCellAnchor
$objWriter->startElement('xdr:oneCellAnchor'); $objWriter->startElement('xdr:oneCellAnchor');
// Image location // Image location
$aCoordinates = Cell::coordinateFromString($pDrawing->getCoordinates()); $aCoordinates = Coordinate::coordinateFromString($pDrawing->getCoordinates());
$aCoordinates[0] = Cell::columnIndexFromString($aCoordinates[0]); $aCoordinates[0] = Coordinate::columnIndexFromString($aCoordinates[0]);
// xdr:from // xdr:from
$objWriter->startElement('xdr:from'); $objWriter->startElement('xdr:from');

View File

@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
@ -314,14 +314,14 @@ class Workbook extends WriterPart
} }
// Create absolute coordinate and write as raw text // Create absolute coordinate and write as raw text
$range = Cell::splitRange($pNamedRange->getRange()); $range = Coordinate::splitRange($pNamedRange->getRange());
for ($i = 0; $i < count($range); ++$i) { for ($i = 0; $i < count($range); ++$i) {
$range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . Cell::absoluteReference($range[$i][0]); $range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . Coordinate::absoluteReference($range[$i][0]);
if (isset($range[$i][1])) { if (isset($range[$i][1])) {
$range[$i][1] = Cell::absoluteReference($range[$i][1]); $range[$i][1] = Coordinate::absoluteReference($range[$i][1]);
} }
} }
$range = Cell::buildRange($range); $range = Coordinate::buildRange($range);
$objWriter->writeRawData($range); $objWriter->writeRawData($range);
@ -348,15 +348,15 @@ class Workbook extends WriterPart
$objWriter->writeAttribute('hidden', '1'); $objWriter->writeAttribute('hidden', '1');
// Create absolute coordinate and write as raw text // Create absolute coordinate and write as raw text
$range = Cell::splitRange($autoFilterRange); $range = Coordinate::splitRange($autoFilterRange);
$range = $range[0]; $range = $range[0];
// Strip any worksheet ref so we can make the cell ref absolute // Strip any worksheet ref so we can make the cell ref absolute
if (strpos($range[0], '!') !== false) { if (strpos($range[0], '!') !== false) {
list($ws, $range[0]) = explode('!', $range[0]); list($ws, $range[0]) = explode('!', $range[0]);
} }
$range[0] = Cell::absoluteCoordinate($range[0]); $range[0] = Coordinate::absoluteCoordinate($range[0]);
$range[1] = Cell::absoluteCoordinate($range[1]); $range[1] = Coordinate::absoluteCoordinate($range[1]);
$range = implode(':', $range); $range = implode(':', $range);
$objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range); $objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range);
@ -427,12 +427,12 @@ class Workbook extends WriterPart
$objWriter->writeAttribute('localSheetId', $pSheetId); $objWriter->writeAttribute('localSheetId', $pSheetId);
// Print area // Print area
$printArea = Cell::splitRange($pSheet->getPageSetup()->getPrintArea()); $printArea = Coordinate::splitRange($pSheet->getPageSetup()->getPrintArea());
$chunks = []; $chunks = [];
foreach ($printArea as $printAreaRect) { foreach ($printArea as $printAreaRect) {
$printAreaRect[0] = Cell::absoluteReference($printAreaRect[0]); $printAreaRect[0] = Coordinate::absoluteReference($printAreaRect[0]);
$printAreaRect[1] = Cell::absoluteReference($printAreaRect[1]); $printAreaRect[1] = Coordinate::absoluteReference($printAreaRect[1]);
$chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect); $chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect);
} }

View File

@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx; namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
@ -249,8 +250,8 @@ class Worksheet extends WriterPart
// Calculate freeze coordinates // Calculate freeze coordinates
$xSplit = $ySplit = 0; $xSplit = $ySplit = 0;
list($xSplit, $ySplit) = Cell::coordinateFromString($topLeftCell); list($xSplit, $ySplit) = Coordinate::coordinateFromString($topLeftCell);
$xSplit = Cell::columnIndexFromString($xSplit); $xSplit = Coordinate::columnIndexFromString($xSplit);
// pane // pane
$pane = 'topRight'; $pane = 'topRight';
@ -367,8 +368,8 @@ class Worksheet extends WriterPart
foreach ($pSheet->getColumnDimensions() as $colDimension) { foreach ($pSheet->getColumnDimensions() as $colDimension) {
// col // col
$objWriter->startElement('col'); $objWriter->startElement('col');
$objWriter->writeAttribute('min', Cell::columnIndexFromString($colDimension->getColumnIndex())); $objWriter->writeAttribute('min', Coordinate::columnIndexFromString($colDimension->getColumnIndex()));
$objWriter->writeAttribute('max', Cell::columnIndexFromString($colDimension->getColumnIndex())); $objWriter->writeAttribute('max', Coordinate::columnIndexFromString($colDimension->getColumnIndex()));
if ($colDimension->getWidth() < 0) { if ($colDimension->getWidth() < 0) {
// No width set, apply default of 10 // No width set, apply default of 10
@ -538,7 +539,7 @@ class Worksheet extends WriterPart
// Write data validations? // Write data validations?
if (!empty($dataValidationCollection)) { if (!empty($dataValidationCollection)) {
$dataValidationCollection = Cell::mergeRangesInCollection($dataValidationCollection); $dataValidationCollection = Coordinate::mergeRangesInCollection($dataValidationCollection);
$objWriter->startElement('dataValidations'); $objWriter->startElement('dataValidations');
$objWriter->writeAttribute('count', count($dataValidationCollection)); $objWriter->writeAttribute('count', count($dataValidationCollection));
@ -753,7 +754,7 @@ class Worksheet extends WriterPart
$objWriter->startElement('autoFilter'); $objWriter->startElement('autoFilter');
// Strip any worksheet reference from the filter coordinates // Strip any worksheet reference from the filter coordinates
$range = Cell::splitRange($autoFilterRange); $range = Coordinate::splitRange($autoFilterRange);
$range = $range[0]; $range = $range[0];
// Strip any worksheet ref // Strip any worksheet ref
if (strpos($range[0], '!') !== false) { if (strpos($range[0], '!') !== false) {
@ -921,7 +922,7 @@ class Worksheet extends WriterPart
$objWriter->writeAttribute('manualBreakCount', count($aRowBreaks)); $objWriter->writeAttribute('manualBreakCount', count($aRowBreaks));
foreach ($aRowBreaks as $cell) { foreach ($aRowBreaks as $cell) {
$coords = Cell::coordinateFromString($cell); $coords = Coordinate::coordinateFromString($cell);
$objWriter->startElement('brk'); $objWriter->startElement('brk');
$objWriter->writeAttribute('id', $coords[1]); $objWriter->writeAttribute('id', $coords[1]);
@ -939,10 +940,10 @@ class Worksheet extends WriterPart
$objWriter->writeAttribute('manualBreakCount', count($aColumnBreaks)); $objWriter->writeAttribute('manualBreakCount', count($aColumnBreaks));
foreach ($aColumnBreaks as $cell) { foreach ($aColumnBreaks as $cell) {
$coords = Cell::coordinateFromString($cell); $coords = Coordinate::coordinateFromString($cell);
$objWriter->startElement('brk'); $objWriter->startElement('brk');
$objWriter->writeAttribute('id', Cell::columnIndexFromString($coords[0]) - 1); $objWriter->writeAttribute('id', Coordinate::columnIndexFromString($coords[0]) - 1);
$objWriter->writeAttribute('man', '1'); $objWriter->writeAttribute('man', '1');
$objWriter->endElement(); $objWriter->endElement();
} }
@ -969,7 +970,7 @@ class Worksheet extends WriterPart
$objWriter->startElement('sheetData'); $objWriter->startElement('sheetData');
// Get column count // Get column count
$colCount = Cell::columnIndexFromString($pSheet->getHighestColumn()); $colCount = Coordinate::columnIndexFromString($pSheet->getHighestColumn());
// Highest row number // Highest row number
$highestRow = $pSheet->getHighestRow(); $highestRow = $pSheet->getHighestRow();
@ -977,7 +978,7 @@ class Worksheet extends WriterPart
// Loop through cells // Loop through cells
$cellsByRow = []; $cellsByRow = [];
foreach ($pSheet->getCoordinates() as $coordinate) { foreach ($pSheet->getCoordinates() as $coordinate) {
$cellAddress = Cell::coordinateFromString($coordinate); $cellAddress = Coordinate::coordinateFromString($coordinate);
$cellsByRow[$cellAddress[1]][] = $coordinate; $cellsByRow[$cellAddress[1]][] = $coordinate;
} }

View File

@ -2,11 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Cell; namespace PhpOffice\PhpSpreadsheetTests\Cell;
use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Exception;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CellTest extends TestCase class CoordinateTest extends TestCase
{ {
/** /**
* @dataProvider providerColumnString * @dataProvider providerColumnString
@ -15,7 +15,7 @@ class CellTest extends TestCase
*/ */
public function testColumnIndexFromString($expectedResult, ...$args) public function testColumnIndexFromString($expectedResult, ...$args)
{ {
$result = Cell::columnIndexFromString(...$args); $result = Coordinate::columnIndexFromString(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -29,7 +29,7 @@ class CellTest extends TestCase
$cellAddress = 'ABCD'; $cellAddress = 'ABCD';
try { try {
Cell::columnIndexFromString($cellAddress); Coordinate::columnIndexFromString($cellAddress);
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf(Exception::class, $e); self::assertInstanceOf(Exception::class, $e);
self::assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters'); self::assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
@ -44,7 +44,7 @@ class CellTest extends TestCase
$cellAddress = ''; $cellAddress = '';
try { try {
Cell::columnIndexFromString($cellAddress); Coordinate::columnIndexFromString($cellAddress);
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf(Exception::class, $e); self::assertInstanceOf(Exception::class, $e);
self::assertEquals($e->getMessage(), 'Column string index can not be empty'); self::assertEquals($e->getMessage(), 'Column string index can not be empty');
@ -61,7 +61,7 @@ class CellTest extends TestCase
*/ */
public function testStringFromColumnIndex($expectedResult, ...$args) public function testStringFromColumnIndex($expectedResult, ...$args)
{ {
$result = Cell::stringFromColumnIndex(...$args); $result = Coordinate::stringFromColumnIndex(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -77,7 +77,7 @@ class CellTest extends TestCase
*/ */
public function testCoordinateFromString($expectedResult, ...$args) public function testCoordinateFromString($expectedResult, ...$args)
{ {
$result = Cell::coordinateFromString(...$args); $result = Coordinate::coordinateFromString(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -91,7 +91,7 @@ class CellTest extends TestCase
$cellAddress = 'A1:AI2012'; $cellAddress = 'A1:AI2012';
try { try {
Cell::coordinateFromString($cellAddress); Coordinate::coordinateFromString($cellAddress);
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf(Exception::class, $e); self::assertInstanceOf(Exception::class, $e);
self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells'); self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
@ -106,7 +106,7 @@ class CellTest extends TestCase
$cellAddress = ''; $cellAddress = '';
try { try {
Cell::coordinateFromString($cellAddress); Coordinate::coordinateFromString($cellAddress);
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf(Exception::class, $e); self::assertInstanceOf(Exception::class, $e);
self::assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string'); self::assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
@ -121,7 +121,7 @@ class CellTest extends TestCase
$cellAddress = 'AI'; $cellAddress = 'AI';
try { try {
Cell::coordinateFromString($cellAddress); Coordinate::coordinateFromString($cellAddress);
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf(Exception::class, $e); self::assertInstanceOf(Exception::class, $e);
self::assertEquals($e->getMessage(), 'Invalid cell coordinate ' . $cellAddress); self::assertEquals($e->getMessage(), 'Invalid cell coordinate ' . $cellAddress);
@ -138,7 +138,7 @@ class CellTest extends TestCase
*/ */
public function testAbsoluteCoordinateFromString($expectedResult, ...$args) public function testAbsoluteCoordinateFromString($expectedResult, ...$args)
{ {
$result = Cell::absoluteCoordinate(...$args); $result = Coordinate::absoluteCoordinate(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -152,7 +152,7 @@ class CellTest extends TestCase
$cellAddress = 'A1:AI2012'; $cellAddress = 'A1:AI2012';
try { try {
Cell::absoluteCoordinate($cellAddress); Coordinate::absoluteCoordinate($cellAddress);
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf(Exception::class, $e); self::assertInstanceOf(Exception::class, $e);
self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells'); self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
@ -169,7 +169,7 @@ class CellTest extends TestCase
*/ */
public function testAbsoluteReferenceFromString($expectedResult, ...$args) public function testAbsoluteReferenceFromString($expectedResult, ...$args)
{ {
$result = Cell::absoluteReference(...$args); $result = Coordinate::absoluteReference(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -183,7 +183,7 @@ class CellTest extends TestCase
$cellAddress = 'A1:AI2012'; $cellAddress = 'A1:AI2012';
try { try {
Cell::absoluteReference($cellAddress); Coordinate::absoluteReference($cellAddress);
} catch (\Exception $e) { } catch (\Exception $e) {
self::assertInstanceOf(Exception::class, $e); self::assertInstanceOf(Exception::class, $e);
self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells'); self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
@ -200,7 +200,7 @@ class CellTest extends TestCase
*/ */
public function testSplitRange($expectedResult, ...$args) public function testSplitRange($expectedResult, ...$args)
{ {
$result = Cell::splitRange(...$args); $result = Coordinate::splitRange(...$args);
foreach ($result as $key => $split) { foreach ($result as $key => $split) {
if (!is_array($expectedResult[$key])) { if (!is_array($expectedResult[$key])) {
self::assertEquals($expectedResult[$key], $split[0]); self::assertEquals($expectedResult[$key], $split[0]);
@ -222,7 +222,7 @@ class CellTest extends TestCase
*/ */
public function testBuildRange($expectedResult, ...$args) public function testBuildRange($expectedResult, ...$args)
{ {
$result = Cell::buildRange(...$args); $result = Coordinate::buildRange(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -241,7 +241,7 @@ class CellTest extends TestCase
} }
$cellRange = ''; $cellRange = '';
Cell::buildRange($cellRange); Coordinate::buildRange($cellRange);
} }
/** /**
@ -251,7 +251,7 @@ class CellTest extends TestCase
*/ */
public function testRangeBoundaries($expectedResult, ...$args) public function testRangeBoundaries($expectedResult, ...$args)
{ {
$result = Cell::rangeBoundaries(...$args); $result = Coordinate::rangeBoundaries(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -267,7 +267,7 @@ class CellTest extends TestCase
*/ */
public function testRangeDimension($expectedResult, ...$args) public function testRangeDimension($expectedResult, ...$args)
{ {
$result = Cell::rangeDimension(...$args); $result = Coordinate::rangeDimension(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -283,7 +283,7 @@ class CellTest extends TestCase
*/ */
public function testGetRangeBoundaries($expectedResult, ...$args) public function testGetRangeBoundaries($expectedResult, ...$args)
{ {
$result = Cell::getRangeBoundaries(...$args); $result = Coordinate::getRangeBoundaries(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -299,7 +299,7 @@ class CellTest extends TestCase
*/ */
public function testExtractAllCellReferencesInRange($expectedResult, ...$args) public function testExtractAllCellReferencesInRange($expectedResult, ...$args)
{ {
$result = Cell::extractAllCellReferencesInRange(...$args); $result = Coordinate::extractAllCellReferencesInRange(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -315,7 +315,7 @@ class CellTest extends TestCase
*/ */
public function testMergeRangesInCollection($expectedResult, ...$args) public function testMergeRangesInCollection($expectedResult, ...$args)
{ {
$result = Cell::mergeRangesInCollection(...$args); $result = Coordinate::mergeRangesInCollection(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }