iOfficeAI/OfficeCLI · error · ArgumentException

'object-xml' property is required for ole (verbatim oleObjec

Error message

'object-xml' property is required for ole (verbatim oleObjects child element)

What it means

The 'object-xml' property carries the verbatim <oleObjects> child element (an <mc:AlternateContent> or bare <oleObject>) with its pinned rIds. It is required because the handler appends it directly into the worksheet's <oleObjects>; there is no semantic OLE construction path.

Source

Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.cs:1280

                // (anchor shape) and <legacyDrawing>, all of which must stay
                // consistent — so the handler wires everything here instead
                // of leaving XML splicing to a companion raw-set.
                // Props: rid + data (+content-type/extension) = payload part;
                // icon-rid + icon-data (+icon-content-type) = objectPr image;
                // vml-shape = the <v:shape> anchor XML verbatim;
                // object-xml = the <oleObjects> CHILD element verbatim
                // (mc:AlternateContent or bare oleObject, pinned rIds inside).
                var oleSheetName = parentPartPath.TrimStart('/');
                var oleWs = FindWorksheet(oleSheetName)
                    ?? throw new ArgumentException(
                        $"Sheet not found: {oleSheetName}. ole must be added under a sheet: add-part <file> /<SheetName> --type ole");
                properties ??= new Dictionary<string, string>();
                var oleRid = properties.GetValueOrDefault("rid")
                    ?? throw new ArgumentException("'rid' property is required for ole (pinned payload relationship id)");
                var oleDataB64 = properties.GetValueOrDefault("data")
                    ?? throw new ArgumentException("'data' property is required for ole (base64 payload bytes)");
                var oleObjectXml = properties.GetValueOrDefault("object-xml")
                    ?? throw new ArgumentException("'object-xml' property is required for ole (verbatim oleObjects child element)");
                byte[] oleBytes;
                try { oleBytes = Convert.FromBase64String(oleDataB64); }
                catch (FormatException) { throw new ArgumentException("add-part ole: 'data' is not valid base64"); }

                var oleCt = properties.GetValueOrDefault("content-type")
                    ?? "application/vnd.openxmlformats-officedocument.oleObject";
                var oleExt = properties.GetValueOrDefault("extension") ?? ".bin";
                if (!oleExt.StartsWith('.')) oleExt = "." + oleExt;

                // Kind comes from the dump (source part type), because content
                // type alone cannot classify legacy package formats (.xls
                // carries application/vnd.ms-excel, not an OOXML CT). Fallback
                // for hand-written batches that omit ole-kind: package iff the
                // CT is a non-oleObject openxmlformats CT.
                var oleKind = properties.GetValueOrDefault("ole-kind")
                    ?? (oleCt.StartsWith(
                            "application/vnd.openxmlformats-officedocument.", StringComparison.OrdinalIgnoreCase)
                        && !oleCt.Equals(

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Set properties["object-xml"] to the verbatim <oleObject> (or <mc:AlternateContent>) markup.
  2. Ensure the r:id inside matches the supplied 'rid'.
  3. Re-dump to capture the exact child element.

Example fix

// before
var props = new Dictionary<string,string>{ ["rid"]="rId4", ["data"] = b64 };
handler.AddPart("/Sheet1", "ole", props);
// after
props["object-xml"] = "<oleObject r:id=\"rId4\" ... />";
handler.AddPart("/Sheet1", "ole", props);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(properties?.GetValueOrDefault("object-xml")))
    throw new InvalidOperationException("ole requires verbatim 'object-xml'.");

Type guard

static bool HasObjectXml(Dictionary<string,string>? p) =>
    !string.IsNullOrEmpty(p?.GetValueOrDefault("object-xml"));

Try / catch

try { handler.AddPart(parent, "ole", props); }
catch (ArgumentException ex) when (ex.Message.Contains("'object-xml' property is required for ole"))
{ /* supply the oleObjects child element, retry */ }

Prevention

When it happens

Trigger: AddPart(..., "ole", properties) where properties has no 'object-xml' key or a null value.

Common situations: Hand-authored batch missing the child element; a dump that emitted only the payload and icon but not the oleObjects element; supplying the whole <worksheet> root instead of just the child.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/e7560896c15e86c0. Report an issue: GitHub.