Contact

CODE in Calligra Sheets: Read the First Character’s Numeric Code

Text Intermediate Calligra Sheets

Inspect the first character of a string, distinguish UTF-16 units from Unicode code points, and troubleshoot empty strings.

Verification status: Official documentation referenced; example outcomes independently reasoned or arithmetically checked where stated. Not executed in Calligra Sheets. How formula examples are checked

Version scope: Official Calligra 26.08.2 source (KDE Gear release 2026-10-08); KDE stable KF6 English documentation, accessed 2026-10-11. The source registers CODE separately; no explicit registered alias for this canonical function in the pinned text module. The function has one required argument and no documented optional defaults. Native execution was not performed.

Quick answer: =CODE("KDE") is expected to return 75, the value of the first character K. Calligra’s pinned implementation returns the first UTF-16 code unit using Qt QString[0].unicode(); that distinction matters for characters represented by a surrogate pair. KDE CODE documentation; source implementation.

What CODE is for

Use CODE to check the leading character of imported identifiers, debug leading spaces, or inspect a known single-unit character. The result is a numeric character-unit value, not the numeric value of a whole text field: for "123", CODE examines "1", not the number 123. To get a Unicode code point for an emoji or another supplementary character, the related UNICODE function is more appropriate in this release.

Exact syntax, argument type and defaults

=CODE(text)
Argument Required? Official type Meaning Default
text Yes Text string Inspect first character; later characters are ignored None

The official Calligra XML help registers one string input and an integer result. Source registration contains no alternate alias. Text literals in examples are enclosed by double quotation marks; a reference such as A2 is not quoted. This one-parameter function needs no semicolon separator, but a nested IF formula follows the English handbook’s semicolon convention.

Reproducible worksheet and expected results

In A2:A7 type KDE, Calligra, !, éclair, €, and a cell containing one leading space followed by West. In B2, enter =CODE(A2) and fill down. Expected B2:B7: 75, 67, 33, 233, 8364 and 32. You can independently confirm these first-character values against ordinary Unicode Basic Multilingual Plane mappings. They are not native Calligra observations.

Formula Expected result Basis
=CODE("KDE") 75 KDE official example
=CODE("Calligra") 67 C is U+0043, independent
=CODE("!done") 33 ! is U+0021, independent
=CODE("éclair") 233 é is U+00E9, independent for a precomposed character
=CODE("€100") 8364 Qt first UTF-16 unit U+20AC; code-inspection expectation
=CODE(" North") 32 Leading ordinary space U+0020
=CODE("") internal value error (errorVALUE) Explicit empty-string check in C++ source

For troubleshooting, =CODE("A") and =CODE("A123") both yield 65. CODE never scans past the first character. The empty-string error is source-verified but its displayed English/localized error text is not runtime-confirmed.

Advanced example: detect a hidden leading space

Set A2 to West (one initial regular space) and in B2 use:

=IF(CODE(A2)=32;"Leading ordinary space";"Different first character")

Expected: Leading ordinary space. When A2 is West the expected result is Different first character. This checks an ordinary U+0020 space, not every kind of whitespace. Protect empty imported cells before applying CODE:

=IF(LEN(A2)=0;"Empty";CODE(A2))

This combines three documented functions and is an independently reasoned expected result; it has not been executed in Calligra Sheets. If you need a robust Unicode scalar result, use UNICODE in place of CODE after reviewing its empty-string behaviour.

UTF-16 versus full Unicode code points

A particularly important edge case is the supplementary character 😀 (U+1F600). Qt stores it as a surrogate pair beginning with UTF-16 unit U+D83D, decimal 55357. The pinned CODE implementation reads only str[0].unicode(). It therefore suggests the source-derived expected result =CODE("😀") → 55357; =UNICODE("😀") is expected to return 128512 because the UNICODE implementation calls toUcs4().at(0). These are implementation deductions, not observed Calligra tests. Avoid importing emoji identifiers into CODE-based logic without a native check.

Troubleshooting and compatibility

CODE("") produces a value-related error in the code. A nonempty input beginning with an invisible space or control character can yield a surprising value while the rest of the label looks normal. A decomposed e followed by an accent and a precomposed é have different first units; visually similar text need not have identical CODE values. CODE is not an encoding detector and does not validate the remainder of a string.

Microsoft’s Excel CODE reference says its result depends on the computer’s character set (ANSI on Windows, Macintosh set on Mac). This can differ from Calligra’s Qt UTF-16-unit implementation for non-ASCII input; the English uppercase K example travels better than arbitrary symbols. The latest LibreOffice Calc UNICODE reference is a more suitable conceptual point-of-code comparison, not proof of an identical CODE implementation.

See CHAR, UNICODE, UNICHAR, and LEN.

Source scope, date and validation disclosure

Validation: Official documentation, immutable implementation and independent code-point calculations were checked. No native Calligra execution, installed-platform checks, glyph rendering or workbook interchange tests were performed.