You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/types-of-values.md
+65-18Lines changed: 65 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Types of values
2
2
3
-
In HyperFormula, values can be of type Number, Text, Logical, Date, Time, DateTime, Error, Duration, Currency, or Percentage depending on the data.
3
+
In HyperFormula, values can be of type Number, Text, Logical, Date, Time, DateTime, Error, Currency, or Percentage depending on the data.
4
4
Functions may work differently based on the types of arguments.
5
5
6
6
| Type of value | Description |
@@ -12,35 +12,62 @@ Functions may work differently based on the types of arguments.
12
12
| Time | A time in hh:mm:ss or hh:mm (default format), like 10:40:16. |
13
13
| DateTime | Date and Time types combined into one, like 22/06/2022 10:40:16. |
14
14
| Error | An error returned as a result of formula calculation, like #REF! |
15
-
| Duration | A time-based amount of time |
16
15
| Currency | Number representing currency |
17
16
| Percentage | Number representing percentage |
18
17
19
-
## Date and time values
18
+
## How cell value types are determined
20
19
21
-
For better compatibility with other spreadsheet software, HyperFormula stores
22
-
date and time values as numbers. This makes it easier to perform mathematical
23
-
operations such as calculating the number of days between two dates.
20
+
HyperFormula automatically detects the type of cell content when you set a value using methods like `setCellContents`, `buildFromArray`, or `setSheetContent`. The type detection follows this priority order:
24
21
25
-
- A Date value is represented as the number of full days since
- A Time value is represented as a fraction of a full day.
28
-
- A DateTime value is represented as the number of (possibly fractional) days
29
-
since [`nullDate`](../api/interfaces/configparams.md#nulldate).
22
+
### For JavaScript values
30
23
31
-
## Text values
24
+
When you pass JavaScript values directly (not as strings):
32
25
33
-
When working with text values directly inside formulas, you must enclose them in double quotes (`"`). This is different from entering text into cells, where quotes are not required. E.g.:
26
+
-`number` → **Number type**
27
+
-`boolean` → **Logical type**
28
+
-`Date` object → **Date/DateTime type** (converted to internal numeric representation)
29
+
-`null` or `undefined` → **Empty cell**
34
30
35
-
```excel
36
-
=IF(B1="Active", "Status OK", "Check Status")
31
+
```js
32
+
consthf=HyperFormula.buildFromArray([
33
+
[42], // Number
34
+
[true], // Logical
35
+
[newDate()], // Date/DateTime
36
+
[null], // Empty
37
+
]);
37
38
```
38
39
39
-
### Forcing the text value type
40
+
### For string values
41
+
42
+
When you pass string values, HyperFormula detects the type as follows:
40
43
41
-
Like most spreadsheet software, HyperFormula automatically detects the type of an input value.
44
+
- String is "TRUE" or "FALSE" (case-insensitive) → **Logical type**
45
+
- String starting with `=` → **Formula type**
46
+
- String ending with `%` → **Percentage type**
47
+
- String contains currency symbol → **Currency type**
48
+
- String can be parsed as a number → **Number type**
49
+
- String matches date/time format → **Date/Time/DateTime type**
50
+
- None of the above match → **Text type**
51
+
52
+
```js
53
+
consthf=HyperFormula.buildFromArray([
54
+
["TRUE"], // Logical
55
+
["true"], // Logical
56
+
["=SUM(1,2,3)"], // Formula
57
+
["25%"], // Percentage (0.25)
58
+
["$100"], // Currency (100)
59
+
["123.45"], // Number
60
+
["5E+01"], // Number
61
+
["22/06/2022 10:40:16"], // DateTime
62
+
["22/06/2022"], // Date
63
+
["10:40:16"], // Time
64
+
["Hello"], // Text
65
+
]);
66
+
```
42
67
43
-
But sometimes the value should be treated as text even though it's parsable as a formula, number, date, time, datetime, boolean, currency or percentage.
68
+
### Forcing the text value type
69
+
70
+
Sometimes a value should be treated as text even though it's parsable as a formula, number, date, time, datetime, boolean, currency or percentage.
44
71
Typical examples are numeric values with no number semantics, such as ZIP codes, bank sort codes, social security numbers, etc.
45
72
46
73
To prevent the automatic type conversion, prepend the value value with an apostrophe (`'`).
- A Time value is represented as a fraction of a full day.
99
+
- A DateTime value is represented as the number of (possibly fractional) days
100
+
since [`nullDate`](../api/interfaces/configparams.md#nulldate).
101
+
102
+
## Text values
103
+
104
+
When working with text values directly inside formulas, you must enclose them in double quotes (`"`). This is different from entering text into cells, where quotes are not required. E.g.:
105
+
106
+
```excel
107
+
=IF(B1="Active", "Status OK", "Check Status")
108
+
```
109
+
63
110
## Getting cell type
64
111
65
112
Cells have types that can be retrieved by using the `getCellType` method. Cell
0 commit comments