iOfficeAI/OfficeCLI · error · ArgumentException
drawing-group anchor XML is not a valid xdr:twoCellAnchor: {
Error message
drawing-group anchor XML is not a valid xdr:twoCellAnchor: {ex.Message} What it means
The 'anchor-xml' string was passed to the OpenXML SDK constructor `new XDR.TwoCellAnchor(anchorXml)` and it threw. This means the value is present but is not parseable as an xdr:twoCellAnchor element — malformed XML, wrong root element, undeclared namespace prefix, or a non-XML payload (e.g. still base64-encoded). The original exception message is embedded for diagnosis.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.cs:1135
// to semantic leaf shapes when a group references package
// parts such as images/charts.
var groupSheetName = parentPartPath.TrimStart('/');
var groupWorksheet = FindWorksheet(groupSheetName)
?? throw new ArgumentException(
$"Sheet not found: {groupSheetName}. drawing-group must be added under a sheet.");
properties ??= new Dictionary<string, string>();
var anchorXml = properties.GetValueOrDefault("anchor-xml")
?? throw new ArgumentException(
"'anchor-xml' property is required for drawing-group (verbatim xdr anchor XML)");
XDR.TwoCellAnchor groupAnchor;
try
{
groupAnchor = new XDR.TwoCellAnchor(anchorXml);
}
catch (Exception ex)
{
throw new ArgumentException(
$"drawing-group anchor XML is not a valid xdr:twoCellAnchor: {ex.Message}", ex);
}
if (groupAnchor.GetFirstChild<XDR.GroupShape>() == null)
throw new ArgumentException(
"drawing-group anchor XML must contain a top-level xdr:grpSp.");
List<DumpDrawingHyperlinkSpec> groupHyperlinks;
try
{
groupHyperlinks = DecodeDumpDrawingHyperlinks(
properties.GetValueOrDefault("hyperlinks") ?? "");
}
catch (FormatException ex)
{
throw new ArgumentException(
$"drawing-group 'hyperlinks' carrier is invalid: {ex.Message}", ex);
}
View on GitHub (pinned to 1ced45e900)
Solutions
- Ensure anchor-xml is raw, well-formed XML with the xdr namespace declared.
- If you sourced it from a base64 field, decode it first (Convert.FromBase64String then UTF-8 decode).
- Load it through XDocument.Parse in a scratch test to isolate the parse error from the SDK.
- Confirm the root is <xdr:twoCellAnchor>, not a wrapper.
Example fix
// before — still base64 encoded
props["anchor-xml"] = "PHhkcjp0d29DZWxsQW5jaG9y...";
// after — decoded raw XML
props["anchor-xml"] = System.Text.Encoding.UTF8.GetString(
Convert.FromBase64String("PHhkcjp0d29DZWxsQW5jaG9y...")); Defensive patterns
Strategy: try-catch
Validate before calling
try { _ = System.Xml.Linq.XDocument.Parse(props["anchor-xml"]); }
catch (System.Xml.XmlException ex) { /* surface parse error before AddPart */ } Type guard
static bool AnchorParses(string xml)
{ try { return System.Xml.Linq.XDocument.Parse(xml) != null; } catch { return false; } } Try / catch
try { handler.AddPart(parent, "drawing-group", props); }
catch (ArgumentException ex) when (ex.Message.Contains("not a valid xdr:twoCellAnchor"))
{ /* inspect ex.InnerException, fix markup, decode if still base64 */ } Prevention
- Pre-parse anchor-xml with XDocument.Parse to catch XML errors early.
- Decode base64 payloads before assigning to anchor-xml.
- Confirm the root element is xdr:twoCellAnchor with the xdr namespace declared.
When it happens
Trigger: anchor-xml is truncated, has HTML-escaped entities (< instead of <), is missing the xdr namespace declaration, has a different root element (e.g. <xdr:wsDr> or <xdr:absoluteAnchor>), or was left base64-encoded from the dump.
Common situations: Copy-paste truncation of a large group anchor; a transport layer that HTML-escaped the XML; forgetting that the dump emits base64 XML elsewhere and assuming anchor-xml is also encoded; mismatched OpenXML SDK version that rejects the namespace.
Related errors
- Sheet not found: {groupSheetName}. drawing-group must be add
- 'anchor-xml' property is required for drawing-group (verbati
- drawing-group anchor XML must contain a top-level xdr:grpSp.
- drawing-group 'hyperlinks' carrier is invalid: {ex.Message}
- drawing-group hyperlink entries require non-empty Id and Tar
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/a13b6f423eee3b29.
Report an issue: GitHub.