@@ -118,16 +118,13 @@ export const COLUMN = {
118
118
description : _t ( "Column number of a specified cell." ) ,
119
119
args : [
120
120
arg (
121
- "cell_reference (meta, default='this cell')" ,
121
+ "cell_reference (meta, range<meta>, default='this cell')" ,
122
122
_t (
123
123
"The cell whose column number will be returned. Column A corresponds to 1. By default, the function use the cell in which the formula is entered."
124
124
)
125
125
) ,
126
126
] ,
127
- compute : function ( cellReference : Maybe < { value : string } > ) {
128
- if ( isEvaluationError ( cellReference ?. value ) ) {
129
- return cellReference ;
130
- }
127
+ compute : function ( cellReference : Matrix < { value : string } > | undefined ) {
131
128
if ( cellReference === undefined ) {
132
129
if ( this . __originCellPosition ?. col === undefined ) {
133
130
return new EvaluationError (
@@ -136,21 +133,22 @@ export const COLUMN = {
136
133
)
137
134
) ;
138
135
}
139
- return this . __originCellPosition ! . col ! + 1 ;
136
+ return this . __originCellPosition . col + 1 ;
140
137
}
141
-
142
- const zone = this . getters . getRangeFromSheetXC (
138
+ if ( cellReference [ 0 ] [ 0 ] === undefined ) {
139
+ return new EvaluationError ( _t ( "The range is out of bounds." ) ) ;
140
+ }
141
+ if ( cellReference [ 0 ] [ 0 ] . value === CellErrorType . InvalidReference ) {
142
+ return cellReference [ 0 ] [ 0 ] ; // return the same error
143
+ }
144
+ const left = this . getters . getRangeFromSheetXC (
143
145
this . getters . getActiveSheetId ( ) ,
144
- cellReference . value
145
- ) . zone ;
146
-
147
- if ( zone . left === zone . right ) {
148
- return zone . left + 1 ;
146
+ cellReference [ 0 ] [ 0 ] . value
147
+ ) . zone . left ;
148
+ if ( cellReference . length === 1 ) {
149
+ return left + 1 ;
149
150
}
150
-
151
- return generateMatrix ( zone . right - zone . left + 1 , 1 , ( col , row ) => ( {
152
- value : zone . left + col + 1 ,
153
- } ) ) ;
151
+ return generateMatrix ( cellReference . length , 1 , ( col , row ) => ( { value : left + col + 1 } ) ) ;
154
152
} ,
155
153
isExported : true ,
156
154
} satisfies AddFunctionDescription ;
@@ -161,13 +159,16 @@ export const COLUMN = {
161
159
162
160
export const COLUMNS = {
163
161
description : _t ( "Number of columns in a specified array or range." ) ,
164
- args : [ arg ( "range (meta)" , _t ( "The range whose column count will be returned." ) ) ] ,
165
- compute : function ( range : { value : string } ) {
166
- if ( isEvaluationError ( range ?. value ) ) {
167
- return range ;
162
+ args : [ arg ( "range (any, range<any>)" , _t ( "The range whose column count will be returned." ) ) ] ,
163
+ compute : function ( range : Arg ) {
164
+ const _range = toMatrix ( range ) ;
165
+ if ( _range [ 0 ] [ 0 ] === undefined ) {
166
+ return new EvaluationError ( _t ( "The range is out of bounds." ) ) ;
167
+ }
168
+ if ( _range [ 0 ] [ 0 ] . value === CellErrorType . InvalidReference ) {
169
+ return _range [ 0 ] [ 0 ] ;
168
170
}
169
- const zone = toZone ( range . value ) ;
170
- return zone . right - zone . left + 1 ;
171
+ return _range . length ;
171
172
} ,
172
173
isExported : true ,
173
174
} satisfies AddFunctionDescription ;
@@ -504,16 +505,13 @@ export const ROW = {
504
505
description : _t ( "Row number of a specified cell." ) ,
505
506
args : [
506
507
arg (
507
- "cell_reference (meta, default='this cell')" ,
508
+ "cell_reference (meta, range<meta>, default='this cell')" ,
508
509
_t (
509
510
"The cell whose row number will be returned. By default, this function uses the cell in which the formula is entered."
510
511
)
511
512
) ,
512
513
] ,
513
- compute : function ( cellReference : Maybe < { value : string } > ) {
514
- if ( isEvaluationError ( cellReference ?. value ) ) {
515
- return cellReference ;
516
- }
514
+ compute : function ( cellReference : Matrix < { value : string } > | undefined ) {
517
515
if ( cellReference === undefined ) {
518
516
if ( this . __originCellPosition ?. row === undefined ) {
519
517
return new EvaluationError (
@@ -522,21 +520,22 @@ export const ROW = {
522
520
)
523
521
) ;
524
522
}
525
- return this . __originCellPosition ! . row ! + 1 ;
523
+ return this . __originCellPosition . row + 1 ;
526
524
}
527
-
528
- const zone = this . getters . getRangeFromSheetXC (
525
+ if ( cellReference [ 0 ] [ 0 ] === undefined ) {
526
+ return new EvaluationError ( _t ( "The range is out of bounds." ) ) ;
527
+ }
528
+ if ( cellReference [ 0 ] [ 0 ] . value === CellErrorType . InvalidReference ) {
529
+ return cellReference [ 0 ] [ 0 ] ; // return the same error
530
+ }
531
+ const top = this . getters . getRangeFromSheetXC (
529
532
this . getters . getActiveSheetId ( ) ,
530
- cellReference . value
531
- ) . zone ;
532
-
533
- if ( zone . top === zone . bottom ) {
534
- return zone . top + 1 ;
533
+ cellReference [ 0 ] [ 0 ] . value
534
+ ) . zone . top ;
535
+ if ( cellReference [ 0 ] . length === 1 ) {
536
+ return top + 1 ;
535
537
}
536
-
537
- return generateMatrix ( 1 , zone . bottom - zone . top + 1 , ( col , row ) => ( {
538
- value : zone . top + row + 1 ,
539
- } ) ) ;
538
+ return generateMatrix ( 1 , cellReference [ 0 ] . length , ( col , row ) => ( { value : top + row + 1 } ) ) ;
540
539
} ,
541
540
isExported : true ,
542
541
} satisfies AddFunctionDescription ;
@@ -547,13 +546,16 @@ export const ROW = {
547
546
548
547
export const ROWS = {
549
548
description : _t ( "Number of rows in a specified array or range." ) ,
550
- args : [ arg ( "range (meta)" , _t ( "The range whose row count will be returned." ) ) ] ,
551
- compute : function ( range : { value : string } ) {
552
- if ( isEvaluationError ( range ?. value ) ) {
553
- return range ;
549
+ args : [ arg ( "range (any, range<any>)" , _t ( "The range whose row count will be returned." ) ) ] ,
550
+ compute : function ( range : Arg ) {
551
+ const _range = toMatrix ( range ) ;
552
+ if ( _range [ 0 ] [ 0 ] === undefined ) {
553
+ return new EvaluationError ( _t ( "The range is out of bounds." ) ) ;
554
+ }
555
+ if ( _range [ 0 ] [ 0 ] . value === CellErrorType . InvalidReference ) {
556
+ return _range [ 0 ] [ 0 ] ;
554
557
}
555
- const zone = toZone ( range . value ) ;
556
- return zone . bottom - zone . top + 1 ;
558
+ return _range [ 0 ] . length ;
557
559
} ,
558
560
isExported : true ,
559
561
} satisfies AddFunctionDescription ;
@@ -975,7 +977,7 @@ export const OFFSET = {
975
977
) ,
976
978
args : [
977
979
arg (
978
- "cell_reference (meta)" ,
980
+ "cell_reference (meta, range<meta> )" ,
979
981
_t ( "The starting point from which to count the offset rows and columns." )
980
982
) ,
981
983
arg ( "offset_rows (number)" , _t ( "The number of rows to offset by." ) ) ,
@@ -990,26 +992,26 @@ export const OFFSET = {
990
992
) ,
991
993
] ,
992
994
compute : function (
993
- cellReference : Maybe < { value : string } > ,
995
+ cellReference : Matrix < { value : string } > ,
994
996
offsetRows : Maybe < FunctionResultObject > ,
995
997
offsetColumns : Maybe < FunctionResultObject > ,
996
998
height : Maybe < FunctionResultObject > ,
997
999
width : Maybe < FunctionResultObject >
998
1000
) {
999
- if ( isEvaluationError ( cellReference ? .value ) ) {
1000
- return cellReference ;
1001
+ if ( isEvaluationError ( cellReference [ 0 ] [ 0 ] . value ) ) {
1002
+ return cellReference [ 0 ] [ 0 ] ;
1001
1003
}
1002
1004
1003
- const _cellReference = cellReference ? .value ;
1004
- if ( ! _cellReference ) {
1005
+ const ref0 = cellReference [ 0 ] [ 0 ] . value ;
1006
+ if ( ! ref0 ) {
1005
1007
return new EvaluationError (
1006
1008
"In this context, the function OFFSET needs to have a cell or range in parameter."
1007
1009
) ;
1008
1010
}
1009
- const zone = toZone ( _cellReference ) ;
1011
+ const zone = toZone ( ref0 ) ;
1010
1012
1011
- let offsetHeight = zone . bottom - zone . top + 1 ;
1012
- let offsetWidth = zone . right - zone . left + 1 ;
1013
+ let offsetHeight = cellReference [ 0 ] . length ;
1014
+ let offsetWidth = cellReference . length ;
1013
1015
1014
1016
if ( height ) {
1015
1017
const _height = toNumber ( height , this . locale ) ;
@@ -1031,7 +1033,7 @@ export const OFFSET = {
1031
1033
offsetWidth = _width ;
1032
1034
}
1033
1035
1034
- const { sheetName } = splitReference ( _cellReference ) ;
1036
+ const { sheetName } = splitReference ( ref0 ) ;
1035
1037
1036
1038
const sheetId =
1037
1039
( sheetName && this . getters . getSheetIdByName ( sheetName ) ) || this . getters . getActiveSheetId ( ) ;
0 commit comments