Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#435·OfficeCLI

`get` and `view text` on xlsx are quadratic in the shared-strings table

Author: rpinckneCreated Sep 24, 2026Updated Sep 25, 2026

Version: OfficeCLI 1.0.152, linux-x64 (self-contained). The machine was a Linux VM with 8 vCPU and 16 GB.

Summary. Reading a workbook whose text cells use the shared-strings table slows quadratically with the number of shared strings. The slow commands are officecli get <file> / --depth 3 and officecli view <file> text. Excel and LibreOffice always write shared strings, so every real-world workbook takes this path. The same cells written as inline strings read in linear time. The cost looks like a per-cell shared-string lookup by index that walks the table (O(index)) instead of indexing a materialized list. Edits (batch set) are not affected.

Repro. The script below writes a one-column workbook of N unique strings. Mode shared writes t="s" cells plus xl/sharedStrings.xml. Mode inline writes the same text as t="inlineStr".

bash
python3 sst_repro.py 40000 shared shared.xlsx
python3 sst_repro.py 40000 inline inline.xlsx
time officecli get shared.xlsx / --depth 3 > /dev/null
time officecli get inline.xlsx / --depth 3 > /dev/null
time officecli view shared.xlsx text > /dev/null
sst_repro.py
python
# Minimal SpreadsheetML: one sheet, N rows x 1 column of unique strings.
# mode "shared": t="s" cells + xl/sharedStrings.xml (what Excel writes)
# mode "inline": t="inlineStr" cells (no shared-strings table)
import sys, zipfile
n, mode, out = int(sys.argv[1]), sys.argv[2], sys.argv[3]
NS = 'xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"'
R = 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"'
if mode == "shared":
    rows = "".join(f'<row r="{i}"><c r="A{i}" t="s"><v>{i-1}</v></c></row>' for i in range(1, n + 1))
    sst = f'<sst {NS} count="{n}" uniqueCount="{n}">' + "".join(f"<si><t>item {i}</t></si>" for i in range(n)) + "</sst>"
else:
    rows = "".join(f'<row r="{i}"><c r="A{i}" t="inlineStr"><is><t>item {i-1}</t></is></c></row>' for i in range(1, n + 1))
with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z:
    z.writestr("[Content_Types].xml", '<?xml version="1.0" encoding="UTF-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>' + ('<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>' if mode == "shared" else "") + "</Types>")
    z.writestr("_rels/.rels", '<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>')
    z.writestr("xl/workbook.xml", f'<?xml version="1.0" encoding="UTF-8"?><workbook {NS} {R}><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets></workbook>')
    z.writestr("xl/_rels/workbook.xml.rels", '<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>' + ('<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>' if mode == "shared" else "") + "</Relationships>")
    z.writestr("xl/worksheets/sheet1.xml", f'<?xml version="1.0" encoding="UTF-8"?><worksheet {NS}><sheetData>{rows}</sheetData></worksheet>')
    if mode == "shared":
        z.writestr("xl/sharedStrings.xml", '<?xml version="1.0" encoding="UTF-8"?>' + sst)

Measured (wall time; OFFICECLI_NO_AUTO_RESIDENT=1; a cold process for each command):

Rows (unique strings) get / --depth 3 inline get / --depth 3 shared view text inline view text shared
5,000 1.4 s 2.4 s 1.3 s 1.6 s
10,000 1.5 s 4.9 s 1.3 s 2.7 s
20,000 1.8 s 16.1 s 1.5 s 7.0 s
40,000 2.6 s 63.7 s 1.8 s 19.3 s

Each doubling of the shared-strings table roughly quadruples the time. A realistic 12-column ledger compounds this: 20,000 rows with two free-text columns (about 45,000 unique strings) takes more than 120 s for get / --depth 3, where the same data inline takes 5.5 s.

Bounded reads stay fast on the same files. view text --max-lines 1000, get / --depth 0 and a ranged get /Sheet1/A1:L200 each take 4 to 9 s at 50,000 rows. Only whole-sheet reads show the growth.

Expected. Linear time in the number of cells, as the inline case already is. For example, materialize the shared-string items into an indexable list once per document open.

Also noticed: get / --depth 1 and --depth 2 return every cell of every sheet on an xlsx, the same as --depth 3. Only --depth 0 stops at the sheet list. The help text suggests depth limits the returned levels.

Source: iOfficeAI/OfficeCLI

View original on GitHubView discussion on GitHub