ECMA-376 5th edition Part 1 (December 2016) section 18.17.7 puts 34 functions in the category “Text and Data”: ASC, BAHTTEXT, CHAR, CLEAN, CODE, CONCATENATE, DOLLAR, EXACT, FIND, FINDB, FIXED, JIS, LEFT, LEFTB, LEN, LENB, LOWER, MID, MIDB, PHONETIC, PROPER, REPLACE, REPLACEB, REPT, RIGHT, RIGHTB, SEARCH, SEARCHB, SUBSTITUTE, T, TEXT, TRIM, UPPER and VALUE. Each row below gives the syntax and arguments as the standard writes them, what the standard says the function returns and when it is an error, the standard’s worked examples, [MS-OI29500] v20260818’s note on it where there is one, and the result LibreOffice gives for each example. The Formulas page has the grammar; the byte-counting B functions are described together in their own section. Position numbers (“start-pos”) count from 1.
How the examples were checked
All worked examples of the standard for these functions, with edge cases, were put in a flat ODS workbook of
91 formulas and converted to CSV by LibreOffice (samples/xlsx/oracle/textfn/text-functions.fods and .csv in the
project). Where an example names a cell (A10, B10) the value was put on a second sheet. LibreOffice is an
implementation, not the standard: a difference is reported, not corrected. Where LibreOffice writes
Err:502 it means “invalid argument”, the counterpart of the standard’s
#VALUE! for an out-of-range argument; it has no Excel error name in CSV. The oracle ran with a
British-English locale, which shows in the currency symbol of DOLLAR. Excel itself was not run.
Case, trimming and characters
| Function and arguments | Standard (18.17.7) | Examples: standard says, LibreOffice gives | Excel note |
|---|---|---|---|
LOWER(string) | .203: character-by-character lower case, with one exception: a word-final Σ (U+03A3) becomes ς (U+03C2), not σ | LOWER("AbCd123#$%^") = abcd123#$%^ (LibreOffice: same); LOWER(A10), A10 = 234FRTqwc$#% = 234frtqwc$#% (same) | none |
UPPER(string) | .335: upper-case version | UPPER("AbCd123#$%^") = ABCD123#$%^ (same); A10 = 234FRTqwc$#% gives 234FRTQWC$#% (same) | none |
PROPER(string) | .262: lower case, except the first letter and any letter that follows a non-letter, which are upper case; non-letters unchanged. The argument is text or a reference. | PROPER("12aBC d123aD#$%sd^") = 12Abc D123Ad#$%Sd^ (same, also from a cell) | none |
TRIM(string) | .329: removes leading and trailing space characters (U+0020) and reduces each run of spaces inside to one | TRIM(" abc def ") = abc def. Tried with a longer gap, " abc def ": LibreOffice gives abc def | none |
CLEAN(string) | .40: removes the non-printable characters U+0000 to U+001F | CLEAN("A"&CHAR(2)&"BC") = ABC, and LEN of it is 3 (LibreOffice: same) | 2.1.898: Office also removes U+0080 to U+009F |
CHAR(x) | .35: the character for a code from 1 to 255: Latin ISO 8859-1 everywhere except the Macintosh platform, which uses the Macintosh character set | CHAR(65) = A; CHAR(A10), A10 = 65 = A (same). Edge: CHAR(0) gives a NUL character in LibreOffice though the standard’s range starts at 1 | none |
CODE(string) | .41: the numeric code of the first character; #VALUE! if string is empty | CODE("abc") = 97 (same). Edge: CODE("") is 0 in LibreOffice, #VALUE! in the standard | none |
ASC(string) | .11: for double-byte languages, converts full-width characters to half-width; text without full-width characters is unchanged | The standard’s example ASC("ABC") prints with full-width letters that came out of the text as plain ones. Tried with full-width “ABC”: LibreOffice gives ABC | none |
JIS(string) | .187: converts half-width letters and katakana to full-width (double-byte) characters; text without them is unchanged | Same problem in the standard’s example. Tried JIS("ABC"): LibreOffice gives full-width ABC | none |
PHONETIC(string) | .251: the phonetic (furigana) characters of the text; for a range, those of its upper-left cell; #N/A for a range of non-contiguous cells. The argument is text or a reference. | The standard gives no example. LibreOffice does not know the function (#NAME?) | none |
BAHTTEXT(number) | .22: the number written in words by the Thai convention | BAHTTEXT(1234): the standard prints the Thai words (หนึ่งพันสองร้อยสามสิบสี่บาทถ้วน); LibreOffice does not know the function (#NAME?) | none |
Joining and extracting
| Function and arguments | Standard (18.17.7) | Examples: standard says, LibreOffice gives | Excel note |
|---|---|---|---|
CONCATENATE(argument-list) | .46: the strings of all arguments, joined left to right; each argument designates a string | CONCATENATE("text") = text; CONCATENATE("The total is ",A10," units") = The total is 43 units, A10 = 43; CONCATENATE(3," + ",4," = ",3+4) = 3 + 4 = 7 (all same) | none |
LEFT(string [, number-chars]) | .191: the left-most number-chars characters; default 1; if number-chars exceeds the length, the whole string; negative number-chars is #VALUE! | LEFT("abcdef",2) = ab; LEFT(A10,4), A10 = xyz123 = xyz1 (same). Edges: LEFT("abc") = a; LEFT("abc",10) = abc; LEFT("abc",-1) = Err:502 | 2.1.981: Office says LEFT is for any language |
RIGHT(string [, number-chars]) | .275: the right-most number-chars characters; same defaults and error rule as LEFT | RIGHT("abcdef",2) = ef; RIGHT(A10,4) = z123 (same) | 2.1.1031: Office says RIGHT is for any language |
MID(string, start-pos, number-chars) | .210: number-chars characters from start-pos. #VALUE! if start-pos < 1 or number-chars < 0. If start-pos is beyond the length, or start-pos plus number-chars exceeds it, the whole of string is extracted. | MID("abcdef",3,2) = cd; MID(A10,4,1), A10 = xyz123 = 1; MID("abcdef",4,5) = def (same). Edges: start 0 gives Err:502; start 9 gives an empty string | 2.1.992: MID is for any language; Office returns #VALUE! if start-pos < 1 (the standard’s argument table says < 0 in one place); if start-pos is beyond the length Office returns the empty string, not the whole string; if start-pos plus count exceeds the length it returns the rest from start-pos. LibreOffice agrees with Office here. |
REPLACE(string-1, start-pos, number-chars, string-2) | .272: string-1 with number-chars characters from start-pos replaced by string-2. Beyond the end: string-2 is appended; if the count runs past the end, the rest is replaced. #VALUE! if start-pos < 0 or number-chars < 0 (the argument text says start-pos at least 1). | REPLACE("abcdefghijk",3,4,"XY") = abXYghijk; (…,3,1,"12345") = ab12345defghijk; (…,15,4,"XY") = abcdefghijkXY (all same). Edge: start 0 gives Err:502 | 2.1.1029: Office requires start-pos at least 1; REPLACE is for any language |
SUBSTITUTE(string, old-string, new-string [, occurrence]) | .304: string with one or all occurrences of old-string replaced by new-string. Without occurrence all are replaced. #VALUE! if occurrence ≤ 0. | SUBSTITUTE("abcaaabca","a","xx") = xxbcxxxxxxbcxx (same); (…,"a","xx",3) = abcaxxabca (same); (…,"a","",10): the standard says bcbc, LibreOffice gives abcaaabca unchanged (there is no 10th occurrence). Edge: occurrence 0 gives Err:502 | 2.1.1046: Office returns #VALUE! when occurrence ≤ 0 (the standard text says < 0 in one place) |
REPT(string, replication-count) | .274: string repeated replication-count times (truncated to an integer); 0 gives the empty string; negative is #VALUE! | REPT("ABC",3) = ABCABCABC; LEN(REPT("ABC",0)) = 0 (same). Edge: REPT("ABC",-1) = Err:502 | none |
T(value) | .315: value if it is text; otherwise the empty string. No conversion takes place; T cannot tell a text empty string from a non-text value. | T("Hello") = Hello; T(123) = empty; LEN(T(123)) = 0 (all same) | none |
EXACT(string-1, string-2) | .112: case-sensitive character-by-character comparison; TRUE only if length and contents match | EXACT("ABC","ABC") = TRUE; ("ABC","ABCD") = FALSE; ("Abc","aBC") = FALSE; ("","") = TRUE (all same) | none |
LEN(string) | .193: the number of characters | LEN("abc") = 3; LEN(A10) = 3, abc in A1 (same) | 2.1.983: Office says LEN is for any language |
Finding
| Function and arguments | Standard (18.17.7) | Examples: standard says, LibreOffice gives | Excel note |
|---|---|---|---|
FIND(string-1, string-2 [, start-pos]) | .119: case-sensitive search for string-1 in string-2 from start-pos (default 1); the position of the first match. An empty string-1 is found at start-pos (or 1). #VALUE! if not found or if start-pos is outside string-2. The argument table says start-pos is at least 1. | FIND("de","abcdef") = 4; FIND(A10,B10) = 4 with A10 = de, B10 = abcdef (same). Edges: FIND("DE","abcdef") = #VALUE! (case); FIND("","abcdef") = #VALUE! in LibreOffice, 1 in the standard; start 5 gives #VALUE! | 2.1.950: the standard (a note) says start-pos at least 0, Office requires at least 1; FIND is for any language |
SEARCH(string-1, string-2 [, start-pos]) | .285: like FIND but case-insensitive; string-1 may contain ? (any one character) and * (any sequence), and ~ before either makes it literal. Same defaults and errors as FIND. | SEARCH("de","abcdEF") = 4 (same). SEARCH("?c*e","abcdEF"): the standard says 2; LibreOffice gives #VALUE! because wildcards are off in a flat ODS; opened from an XLSX, LibreOffice reads them (SEARCH("b*c","abcd") = 2, see the viewer section) | 2.1.1037: Office requires start-pos at least 1 where the standard text says 0; SEARCH is for any language |
VALUE(string) | .337: converts text in any number, currency, date or time format (18.8.31) to a number; date and time strings give serial date-times | VALUE("123.456") = 123.456; VALUE("23-Mar-2002") = 37338 (the serial); VALUE("16:48:00")-VALUE("12:17:12") = 0.188056 (all same). VALUE("$1,000"): the standard says 1000; LibreOffice (pound locale) gives Err:502 because $ is not its currency | 2.1.1061: if string is not a number, currency, date or time format, Office returns #VALUE! (LibreOffice: Err:502 for VALUE("abc")) |
Formatting numbers as text
| Function and arguments | Standard (18.17.7) | Examples: standard says, LibreOffice gives | Excel note |
|---|---|---|---|
DOLLAR(number [, num-decimal]) | .94: number rounded to num-decimal places (default 2; truncated to an integer; negative rounds left of the point) with the application’s currency symbol, thousands separator and radix point | With $, comma and point: DOLLAR(1234.567) = $1,234.57; (1234.567,-2) = $1,200; (-1234.567,4) = ($1,234.5670). The standard also lists the same calls for € (1 234,57 €), SFr. (SFr. 1'234.57) and kr formats. LibreOffice with a pound locale: £1,234.57; £1,200; -£1,234.5670 (a minus sign, not brackets) | 2.1.936: separators and symbol are implementation-specific; num-decimal above 127 gives #VALUE! |
FIXED(number [, [num-decimal] [, suppress-commas-flag]]) | .124: number rounded as ROUND does, as text; default 2 places; negative rounds left; with TRUE no commas | FIXED(1234567) = 1,234,567.00; FIXED(1234567.555555,4,TRUE) = 1234567.5556; FIXED(.555555,10) = 0.5555550000; FIXED(1234567,-3) = 1,235,000 (all same) | 2.1.953: the standard says number is truncated to an integer; Office does not truncate number but does truncate num-decimal; the flag removes digit-grouping symbols, not only commas |
TEXT(value, format) | .322: value formatted by the number, currency, date or time format of 18.8.31 | TEXT(1234.567,"$0.00") = $1234.57 (same); TEXT(.125,"$0.0%"): the standard prints 12.5%, LibreOffice gives $12.5% (the format contains a $); TEXT(1234.567,"YYYY-MM-DD HH:MM:SS"): the standard says 1903-05-18 13:36:29 (1900 date system), LibreOffice gives 13:36:28 (it truncates the fractional second where the standard rounds) | none |
The byte-counting B functions
FINDB (.120), LEFTB (.192), LENB (.194), MIDB (.211), REPLACEB (.273), RIGHTB (.276) and SEARCHB (.286) repeat the character functions with positions and counts in bytes, for double-byte (DBCS) languages. The standard’s own text for the lower bounds differs between its argument tables and its error lists for several of them (“at least 0” against “< 0 is #VALUE!”). [MS-OI29500] notes 2.1.951, 2.1.982, 2.1.984, 2.1.993, 2.1.1030, 2.1.1032 and 2.1.1038 say, and this page cites them for all seven:
- the standard does not say positions and lengths are in bytes; in Office they are;
- the standard does not say which languages count as DBCS; in Office they include Japanese, Chinese (Simplified), Chinese (Traditional) and Korean;
- when the default language supports DBCS, each double-byte character counts as 2 bytes and each single-byte character as 1; when it does not, each character counts as 1 byte;
- start-pos must be at least 1 (FINDB, MIDB, REPLACEB, SEARCHB), where the standard says 0;
- MIDB: a start-pos past the end gives the empty string, and a count that runs past the end gives the rest from start-pos, not the whole string.
The standard’s examples assume 1-byte characters, and LibreOffice agrees with them:
LEFTB("abcdef",2) = ab, LEFTB(A10,4) = xyz1, RIGHTB("abcdef",2) = ef,
RIGHTB(A10,4) = z123, LENB("abc") = 3, MIDB("abcdef",3,2) = cd,
MIDB(A10,4,1) = 1, MIDB("abcdef",4,5) = def, FINDB("de","abcdef") = 4,
FINDB(A10,B10) = 4, SEARCHB("de","abcdEF") = 4 and
REPLACEB("abcdefghijk",3,4,"XY") = abXYghijk, (…,3,1,"12345") = ab12345defghijk.
Two cases differ: REPLACEB("abcdefghijk",15,4,"XY") gives Err:502 in LibreOffice (the standard says
abcdefghijkXY, as for REPLACE, which LibreOffice does return), and SEARCHB("?c*e","abcdEF") gives
#VALUE! (the wildcard reason above; the standard says 2). The standard’s argument list for LEFTB, MIDB,
RIGHTB and others uses “number-bytes” where the character versions use “number-chars”;
the oracle ran in a locale without DBCS, so none of the double-byte counting was tried.
A slip in the standard: the description of LEFTB refers to LEFT as §18.17.7.192, which is LEFTB itself; LEFT is .191.
What the viewer does
The viewer shows the value a cell stores and never recalculates a worksheet. Its conditional-format rules
(explorer/formats/xlsx/cf.js) do evaluate LEN, LEFT, RIGHT, MID, TRIM, UPPER, LOWER, EXACT,
SEARCH and FIND. These were run against the LibreOffice results above (23 cases equal, 6 differences, in
test-xlsx-built.mjs):
- LEFT with a negative count and MID with a start of 0 give an empty or clamped text where LibreOffice
returns an error (
LEFT("abc",-1)is "" here and Err:502 there;MID("abcdef",0,2)is "ab" here and Err:502 there); - SEARCH does not read the wildcards
?,*and~, where the standard does and LibreOffice does when it opens an XLSX (SEARCH("b*c","abcd")= 2,SEARCH("a?c","abcd")= 1,SEARCH("~*","a*b")= 2 in samples/xlsx/oracle/wildcardfn; the flat-ODS oracle above gave #VALUE! only because a flat ODS leaves wildcards off; FIND reads none,FIND("b*","abcd")is #VALUE! in both); FIND("","abcdef")is 1 here (the start position, as the standard says) and #VALUE! in LibreOffice;- TRIM removes every white-space character JavaScript knows: a leading no-break space is removed here (length 3) and kept by LibreOffice (length 4);
- lengths and positions count UTF-16 code units: the character U+1F600 counts as 2 here and as 1 in LibreOffice;
- UPPER uses the JavaScript conversion: sharp s gives "SS" here and U+1E9E in LibreOffice; LOWER of a capital sigma at the end of a word gives the final sigma in both;
- none of the other functions of this page (CONCATENATE, TEXT, VALUE, DOLLAR, FIXED and so on) is computed there; a rule that uses one is reported as not calculated.
See also
- Formulas: the grammar, error values and limits
- Functions: logical and math
- Styles part: the number formats TEXT and VALUE refer to (18.8.31)
Not described on this page
- Excel’s own results: only [MS-OI29500] was read; Excel was not run.
- Double-byte counting of the B functions, ASC and JIS on real double-byte text, BAHTTEXT output and PHONETIC: LibreOffice has no BAHTTEXT or PHONETIC and no DBCS locale was run.
- USDOLLAR (18.17.7.336), which the standard defines with a fixed $ format but does not list in the Text and Data category.
- The other categories of 18.17.7: date and time, lookup, statistical, financial, engineering, database, information, cube and web, and the math functions outside the math page.
Sources
- ECMA-376 5th edition Part 1, research/ooxml/ecma376/p1/part1.txt: category table (line 77091), and the definitions 18.17.7.11 (line 77680), .22 (77998), .35 (78633), .40 and .41 (78783, 78797), .46 (78918), .94 (81298), .112 (81852), .119 and .120 (82011, 82037), .124 (82146), .187 (84086), .191 to .194 (84187 to 84260), .203 (84584), .210 and .211 (84900, 84930), .251 (86601), .262 (87202), .272 to .276 (87532 to 87645), .285 and .286 (87932, 87967), .304 (88512), .315 (88870), .322 (89034), .329 (89193), .335 (89338), .337 (89373)
- [MS-OI29500] v20260818, research/ooxml/ms/MS-OI29500.txt, notes 2.1.898, 2.1.936, 2.1.950, 2.1.951, 2.1.953, 2.1.981 to 2.1.984, 2.1.992, 2.1.993, 2.1.1029 to 2.1.1032, 2.1.1037, 2.1.1038, 2.1.1046 and 2.1.1061
- LibreOffice, soffice headless, flat ODS to CSV: samples/xlsx/oracle/textfn/