@@ -1752,31 +1752,35 @@ public function mergeCells($range)
1752
1752
{
1753
1753
$ range = Functions::trimSheetFromCellReference (Validations::validateCellRange ($ range ));
1754
1754
1755
- if (preg_match ('/^([A-Z]+)( \\d+):([A-Z]+)( \\d+)$/ ' , $ range , $ matches ) === 1 ) {
1756
- $ this ->mergeCells [$ range ] = $ range ;
1757
- $ firstRow = (int ) $ matches [2 ];
1758
- $ lastRow = (int ) $ matches [4 ];
1759
- $ firstColumn = $ matches [1 ];
1760
- $ lastColumn = $ matches [3 ];
1761
- $ firstColumnIndex = Coordinate::columnIndexFromString ($ firstColumn );
1762
- $ lastColumnIndex = Coordinate::columnIndexFromString ($ lastColumn );
1763
- $ numberRows = $ lastRow - $ firstRow ;
1764
- $ numberColumns = $ lastColumnIndex - $ firstColumnIndex ;
1765
-
1766
- // create upper left cell if it does not already exist
1767
- $ upperLeft = "{$ firstColumn }{$ firstRow }" ;
1768
- if (!$ this ->cellExists ($ upperLeft )) {
1769
- $ this ->getCell ($ upperLeft )->setValueExplicit (null , DataType::TYPE_NULL );
1770
- }
1755
+ if (strpos ($ range , ': ' ) === false ) {
1756
+ $ range .= ": {$ range }" ;
1757
+ }
1771
1758
1772
- // Blank out the rest of the cells in the range (if they exist)
1773
- if ($ numberRows > $ numberColumns ) {
1774
- $ this ->clearMergeCellsByColumn ($ firstColumn , $ lastColumn , $ firstRow , $ lastRow , $ upperLeft );
1775
- } else {
1776
- $ this ->clearMergeCellsByRow ($ firstColumn , $ lastColumnIndex , $ firstRow , $ lastRow , $ upperLeft );
1777
- }
1759
+ if (preg_match ('/^([A-Z]+)( \\d+):([A-Z]+)( \\d+)$/ ' , $ range , $ matches ) !== 1 ) {
1760
+ throw new Exception ('Merge must be on a valid range of cells. ' );
1761
+ }
1762
+
1763
+ $ this ->mergeCells [$ range ] = $ range ;
1764
+ $ firstRow = (int ) $ matches [2 ];
1765
+ $ lastRow = (int ) $ matches [4 ];
1766
+ $ firstColumn = $ matches [1 ];
1767
+ $ lastColumn = $ matches [3 ];
1768
+ $ firstColumnIndex = Coordinate::columnIndexFromString ($ firstColumn );
1769
+ $ lastColumnIndex = Coordinate::columnIndexFromString ($ lastColumn );
1770
+ $ numberRows = $ lastRow - $ firstRow ;
1771
+ $ numberColumns = $ lastColumnIndex - $ firstColumnIndex ;
1772
+
1773
+ // create upper left cell if it does not already exist
1774
+ $ upperLeft = "{$ firstColumn }{$ firstRow }" ;
1775
+ if (!$ this ->cellExists ($ upperLeft )) {
1776
+ $ this ->getCell ($ upperLeft )->setValueExplicit (null , DataType::TYPE_NULL );
1777
+ }
1778
+
1779
+ // Blank out the rest of the cells in the range (if they exist)
1780
+ if ($ numberRows > $ numberColumns ) {
1781
+ $ this ->clearMergeCellsByColumn ($ firstColumn , $ lastColumn , $ firstRow , $ lastRow , $ upperLeft );
1778
1782
} else {
1779
- throw new Exception ( ' Merge must be set on a range of cells. ' );
1783
+ $ this -> clearMergeCellsByRow ( $ firstColumn , $ lastColumnIndex , $ firstRow , $ lastRow , $ upperLeft );
1780
1784
}
1781
1785
1782
1786
return $ this ;
0 commit comments