MID Function in ONLYOFFICE Spreadsheet Editor: Syntax and Worked Examples
Use MID and MIDB in ONLYOFFICE with worked ASCII examples and clear byte-contract, source and migration cautions.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
=MID(A2,4,2) returns the expected text ON when A2 contains CA-ON-1047. MID extracts characters starting at a chosen position; it does not know that ON is a region code or that hyphens divide fields.
Availability and version history
- Introduced: The original introduction version and date are not established by the checked references.
- Availability: Documented in current ONLYOFFICE Spreadsheet Editor help; no final supported-version endpoint is established.
- Scope: Desktop and Docs release separately. Older builds, mobile clients, localized parsing and imported-workbook parity remain separately unverified.
- Checked: October 14, 2026, against the official MID reference, vendor illustration and pinned calculation source. ASCII examples were independently calculated; no native execution of these extraction formulas was performed.
Syntax and one-based positions
MID(text, start_num, num_chars)
The official reference specifies the source text, starting position and character count. All three arguments are supplied; no optional count or default is documented. Position 1 refers to the first character in these ordinary-text examples.
Create VendorMid, put Online Office in A1 and =MID(A1,3,4) in C1. The official illustration shows line. Starting at the third character and taking four gives l, i, n, e. The space and the following word are outside the requested section.
The pinned source supports the ordinary substring calculations below. It is implementation evidence, not a native test or proof that every installed build behaves identically.
Preserve the six-code worksheet
Create MiddleCodes, reserving A1:H12. Put Code in A1 and these text identifiers in A2:A7:
| Cell | Code |
|---|---|
| A2 | CA-ON-1047 |
| A3 | US-NY-0052 |
| A4 | CA-BC-0318 |
| A5 | CA-ON-1048 |
| A6 | US-CA-2004 |
| A7 | BADCODE |
Enter =MID(A2,4,2) in C2 and fill through C7. The original first three expected results remain ON, NY and BC:
| Row | Expected C |
|---|---|
| 2 | ON |
| 3 | NY |
| 4 | BC |
| 5 | ON |
| 6 | CA |
| 7 | CO |
The last result is important: BADCODE has C and O in positions 4 and 5, so fixed slicing produces plausible-looking text despite the missing separators. A substring result is not a validation result.
Put =MID(A2,7,4) in C9 for the original expected serial 1047. Put =MID(A3,7,4) in C10 for text 0052, retaining both leading zeroes. These formulas select a different part of the original codes without changing A or C2:C7.
Extract the field between hyphens
In D2 enter the original nested delimiter formula and fill through D6:
=MID(A2,FIND("-",A2)+1,FIND("-",A2,FIND("-",A2)+1)-FIND("-",A2)-1)
Expected D2:D6 is ON,NY,BC,ON,CA. The first hyphen is at 3 and the second at 6, so the selected part starts at 4 and has 6−3−1=2 characters.
In D7 enter the guarded version for BADCODE:
=IFERROR(MID(A7,FIND("-",A7)+1,FIND("-",A7,FIND("-",A7)+1)-FIND("-",A7)-1),"Check code")
Expected D7 is Check code. FIND documents #VALUE! when the required delimiter is absent, and IFERROR supplies the fallback. The guard does not validate permitted region letters or the serial field.
Advanced: audit the positions when field lengths change
Create VariableRegion, reserving A1:F8. Put Code, First hyphen, Second hyphen, Count, Extracted region and Fixed comparison in A1:F1. Enter CA-ON-1047, CA-ONT-1047 and CAN-ONT-7 in A2:A4.
Enter these formulas in row 2 and fill B2:F2 through row 4:
B2: =FIND("-",A2)
C2: =FIND("-",A2,B2+1)
D2: =C2-B2-1
E2: =MID(A2,B2+1,D2)
F2: =MID(A2,4,2)
| Row | B | C | D | E | F |
|---|---|---|---|---|---|
| 2 | 3 | 6 | 2 | ON | ON |
| 3 | 3 | 7 | 3 | ONT | ON |
| 4 | 4 | 8 | 3 | ONT | -O |
The longer middle field first changes the needed count. The longer first field then changes the starting position as well. Explicit helper positions explain both changes; increasing the fixed count alone would not fix the third row.
On a copy named ChangedSerial, change only A4 to CAN-ONT-0007. B:E remain 4,8,3,ONT, and F remains -O. A change after the second hyphen does not change the middle field in this structure.
Empty results, errors and character scope
The pinned source returns the available tail when a requested substring reaches beyond the end, and empty text when a positive start is beyond the source. Those are source-level observations, not a complete native boundary contract. These worksheet examples stay within explicit positive integer positions and counts.
Do not import another product’s rules for zero or negative positions, fractional counts, numeric/date conversion or Unicode graphemes. ONLYOFFICE’s help also describes MIDB for byte-oriented language scenarios; this guide does not establish byte/character parity. The source snapshot has additional conversion and boundary branches, but those are not a substitute for testing the actual target build.
LEFT and RIGHT are simpler when the desired field is at an end. Keep the original text for diagnosis, including meaningful spaces and leading zeroes. The examples use English function names and commas; confirm the installed editor’s notation when migrating a workbook.
MIDB: documented byte-oriented variant
MIDB(text, start_num, num_bytes)
All three arguments are required: source text, starting position and extraction count. The help describes num_bytes in bytes; the ASCII controls below use positive integer positions counted from 1.
Documentation and implementation are different evidence
The official MID/MIDB reference describes MIDB for byte-oriented or double-byte-character-set language use. However, the pinned MIDB implementation directly inherits MID, without a separate calculation override in that definition. This is a documented-contract versus inspected-implementation discrepancy, not proof that all clients implement a separate DBCS byte algorithm.
The added coverage was checked on October 19, 2026. Neither the first supported version nor a last supported version is established. The source revision is evidence about that revision, not native execution, a universal Unicode rule or cross-version compatibility.
Worked ASCII controls for MIDB
On a separate MidbControls sheet, enter the following formulas into individual empty cells. They contain their inputs, so they do not overwrite the earlier worksheets. Results are independently reasoned from ordinary ASCII and the inherited calculation, not observations from a running ONLYOFFICE editor. Text results remain text; “empty text” means a formula result of zero length.
| Formula | Expected text or error | Explanation |
|---|---|---|
=MIDB("ORD-4821-ON",5,4) |
text 4821 |
Four positions beginning at 5 select the serial. |
=MIDB("ORD-4821-ON",10,2) |
text ON |
Positions 10 and 11 select ON. |
=MIDB("ABC",2,1) |
text B |
Position 2 selects B. |
=MIDB("ABC",2,9) |
BC | Only the available tail remains. |
=MIDB("ABC",4,1) |
empty text | A positive start beyond the end returns empty text. |
=MIDB("ABC",2,0) |
empty text | A zero extraction count selects nothing. |
=MIDB("ABC",2,-1) |
#VALUE! | A negative count is rejected by the inherited calculation. |
In ORD-4821-ON, position 5 is the first digit and position 10 is O. Keep the extracted serial as text so leading zeroes survive. Do not infer the behavior of a zero start from another spreadsheet.
Migrating a workbook that uses MIDB
Keep a copy of the original formula and its source text. Compare the ASCII controls first, then separately check the real workbook’s Japanese, Chinese or Korean text, mixed-script strings, emoji and combining marks in the intended editor/build and locale. Record actual results instead of deriving them from these ASCII examples.
Do not equate the B suffix with UTF-8 file size, display width or user-perceived characters, and do not silently replace MIDB with MID in a workbook whose author depended on byte positions. Matching names and inherited code do not establish import/export parity. Confirm formula separators and language in the destination editor; fractional counts, type conversions and unlisted error cases remain outside this evidence.