@@ -71,44 +71,12 @@ public function updateCellReference(string $cellReference = 'A1', bool $includeA
71
71
$ updateColumn = (($ absoluteColumn !== '$ ' ) && $ newColumnIndex >= $ this ->beforeColumn );
72
72
$ updateRow = (($ absoluteRow !== '$ ' ) && $ newRowIndex >= $ this ->beforeRow );
73
73
} else {
74
- // A special case is removing the left/top or bottom/right edge of a range
75
- // $topLeft is null if we aren't adjusting a range at all.
76
- if (
77
- $ topLeft !== null
78
- && $ this ->numberOfColumns < 0
79
- && $ newColumnIndex >= $ this ->beforeColumn + $ this ->numberOfColumns
80
- && $ newColumnIndex <= $ this ->beforeColumn - 1
81
- ) {
82
- if ($ topLeft ) {
83
- $ newColumnIndex = $ this ->beforeColumn + $ this ->numberOfColumns ;
84
- } else {
85
- $ newColumnIndex = $ this ->beforeColumn + $ this ->numberOfColumns - 1 ;
86
- }
87
- } elseif ($ newColumnIndex >= $ this ->beforeColumn ) {
88
- // Create new column reference
89
- $ newColumnIndex += $ this ->numberOfColumns ;
90
- }
74
+ $ newColumnIndex = $ this ->computeNewColumnIndex ($ newColumnIndex , $ topLeft );
91
75
$ newColumn = $ absoluteColumn . Coordinate::stringFromColumnIndex ($ newColumnIndex );
92
- //$updateColumn = ($newColumnIndex >= $this->beforeColumn);
93
76
$ updateColumn = false ;
94
- // A special case is removing the left/top or bottom/right edge of a range
95
- // $topLeft is null if we aren't adjusting a range at all.
96
- if (
97
- $ topLeft !== null
98
- && $ this ->numberOfRows < 0
99
- && $ newRowIndex >= $ this ->beforeRow + $ this ->numberOfRows
100
- && $ newRowIndex <= $ this ->beforeRow - 1
101
- ) {
102
- if ($ topLeft ) {
103
- $ newRowIndex = $ this ->beforeRow + $ this ->numberOfRows ;
104
- } else {
105
- $ newRowIndex = $ this ->beforeRow + $ this ->numberOfRows - 1 ;
106
- }
107
- } elseif ($ newRowIndex >= $ this ->beforeRow ) {
108
- $ newRowIndex = $ newRowIndex + $ this ->numberOfRows ;
109
- }
77
+
78
+ $ newRowIndex = $ this ->computeNewRowIndex ($ newRowIndex , $ topLeft );
110
79
$ newRow = $ absoluteRow . $ newRowIndex ;
111
- //$updateRow = ($newRowIndex >= $this->beforeRow);
112
80
$ updateRow = false ;
113
81
}
114
82
@@ -126,6 +94,51 @@ public function updateCellReference(string $cellReference = 'A1', bool $includeA
126
94
return "{$ newColumn }{$ newRow }" ;
127
95
}
128
96
97
+ public function computeNewColumnIndex (int $ newColumnIndex , ?bool $ topLeft ): int
98
+ {
99
+ // A special case is removing the left/top or bottom/right edge of a range
100
+ // $topLeft is null if we aren't adjusting a range at all.
101
+ if (
102
+ $ topLeft !== null
103
+ && $ this ->numberOfColumns < 0
104
+ && $ newColumnIndex >= $ this ->beforeColumn + $ this ->numberOfColumns
105
+ && $ newColumnIndex <= $ this ->beforeColumn - 1
106
+ ) {
107
+ if ($ topLeft ) {
108
+ $ newColumnIndex = $ this ->beforeColumn + $ this ->numberOfColumns ;
109
+ } else {
110
+ $ newColumnIndex = $ this ->beforeColumn + $ this ->numberOfColumns - 1 ;
111
+ }
112
+ } elseif ($ newColumnIndex >= $ this ->beforeColumn ) {
113
+ // Create new column reference
114
+ $ newColumnIndex += $ this ->numberOfColumns ;
115
+ }
116
+
117
+ return $ newColumnIndex ;
118
+ }
119
+
120
+ public function computeNewRowIndex (int $ newRowIndex , ?bool $ topLeft ): int
121
+ {
122
+ // A special case is removing the left/top or bottom/right edge of a range
123
+ // $topLeft is null if we aren't adjusting a range at all.
124
+ if (
125
+ $ topLeft !== null
126
+ && $ this ->numberOfRows < 0
127
+ && $ newRowIndex >= $ this ->beforeRow + $ this ->numberOfRows
128
+ && $ newRowIndex <= $ this ->beforeRow - 1
129
+ ) {
130
+ if ($ topLeft ) {
131
+ $ newRowIndex = $ this ->beforeRow + $ this ->numberOfRows ;
132
+ } else {
133
+ $ newRowIndex = $ this ->beforeRow + $ this ->numberOfRows - 1 ;
134
+ }
135
+ } elseif ($ newRowIndex >= $ this ->beforeRow ) {
136
+ $ newRowIndex = $ newRowIndex + $ this ->numberOfRows ;
137
+ }
138
+
139
+ return $ newRowIndex ;
140
+ }
141
+
129
142
public function cellAddressInDeleteRange (string $ cellAddress ): bool
130
143
{
131
144
[$ cellColumn , $ cellRow ] = Coordinate::coordinateFromString ($ cellAddress );
0 commit comments