Contact

CODE Function (OpenOffice Calc)

Text Intermediate OpenOffice Calc

Learn the CODE function in Apache OpenOffice Calc: Returns a numeric code for the first character in a text string.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Availability and version history

  • Introduced: Documented by Apache OpenOffice 4.1.16; original introduction not established.
  • Availability: Supported in Apache OpenOffice 4.1.16, verified against its function registry. This identifies a supported release, not a final working version.
  • Scope: Desktop Calc, using the English function name. Availability in other spreadsheet applications is separate.
  • Checked: 2026-10-14 — function reference; versioned support. Documentation/source check; not a new native test. Existing example-specific test claims below retain their stated scope.

CODE returns a numeric code for the first character of text using the application’s system encoding. It is useful for inspecting ordinary characters, but it is not a portable Unicode-code-point function. The basic Latin examples below deliberately use characters whose codes are stable in the common ASCII-compatible encodings.

Syntax and arguments

=CODE(text)

text is the single required source string or text reference. Only its first stored character is used. The 4.1.16 source converts that character through the system text encoding and casts the result to an unsigned byte. There is no argument for choosing an encoding, character position or Unicode mode. English function names and semicolon argument separators are used here.

Reproducible examples

Formula Expected result
=CODE("A") 65
=CODE("a") 97
=CODE("0") 48
=CODE(" ") 32
=CODE("AB") 65
=CODE("-") 45

The first formula preserves the original guide’s worked example. Its historical comparable LibreOffice 25.2 check was not an OpenOffice test. New results are independently checked reference expectations; no fresh native or GUI test is claimed. Here "" denotes zero-length text.

Practical worksheet: inspect leading characters in imported labels

Enter Alpha, alpha and Alpha in A2:A4, preserving the leading ordinary space in A4. In B2 enter =CODE(A2) and fill down. In an ASCII-compatible system encoding, expected codes are 65, 97 and 32. This distinguishes uppercase A, lowercase a and the leading space even when the labels look similar.

In C2 enter =LEFT(A2;1) and fill down to show the character being inspected. CODE does not search for the first visible letter or skip whitespace: the leading space is the first character. Keep this helper beside the code to avoid mistaking a prefix check for validation of the full string.

Advanced applications

Inspect a chosen position. With AB-01 in A2, =CODE(MID(A2;3;1)) gives 45 for the hyphen in the stated encoding scope. Validate the position against LEN(A2) first so the extracted string is nonempty.

Use the appropriate character model. UNICODE is the function intended for a Unicode number, whereas CODE is tied to the loaded code table/system encoding. A non-ASCII character may not map consistently across machines. Do not infer that a CODE result is a Unicode scalar or the first byte of a UTF-8 encoding.

Cross-check a basic character. =CHAR(CODE("A")) returns A within the same ASCII-compatible encoding. This small round trip does not establish that every character survives the conversion. Unsupported characters can be mapped or substituted during encoding, so a successful basic example is not a multilingual portability certificate.

Errors, edge cases and troubleshooting

CODE inspects only the first character. CODE(“A”) and CODE(“AB”) both return 65 in the stated encoding scope, so equality of their codes does not establish equality of the strings. Use EXACT for a full case-sensitive text comparison.

The retained help warns that the loaded code table matters. These basic examples must not be extended into a universal claim that CODE always returns ASCII, a Unicode code point, or a portable byte sequence. For non-ASCII data, use an explicitly chosen character/encoding model and test representative inputs in the target build.

Supply nonempty text. Empty-input behavior and unmappable-character substitutions are not certified by this guide; guard with LEN(text)>0 before indexing a character. Numeric and date input conversion need not reproduce the formatted display. A visible space may be an ordinary space or a different character; the simple code32 result only identifies the ordinary-space example here. No fresh native locale or encoding execution is claimed.

Documentation and verification

See the Apache OpenOffice CODE reference, 4.1.16 text-function help, and versioned interpreter. The official source snapshots were retrieved on October 13, 2026 and re-read for this guide; no new retrieval date is implied. Source inspection and reference calculations do not certify native encoding, locale or extreme-input behavior. First introduction and final functioning version remain unestablished; the lifecycle section identifies documented support.