iOfficeAI/OfficeCLI · error · ArgumentException

Sheet not found: {groupSheetName}. drawing-group must be add

Error message

Sheet not found: {groupSheetName}. drawing-group must be added under a sheet.

What it means

Thrown by AddPart when handling a 'drawing-group' part type: the carrier for a verbatim DrawingML group (<xdr:grpSp>) anchor. The parent part path is stripped of a leading '/' and used as a sheet name to locate the hosting worksheet via FindWorksheet. A group anchor must be appended into a sheet's DrawingsPart, so if no worksheet matches the name, the add cannot proceed. FindWorksheet is case-insensitive but otherwise exact.

Source

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

                    )
                );
                chartPart.ChartSpace.Save();

                var chartIdx = drawingsPart.ChartParts.ToList().IndexOf(chartPart);
                return (relId, $"/{sheetName}/chart[{chartIdx + 1}]");

            case "drawing-group":
            {
                // Verbatim DrawingML group carrier for xlsx dump→batch.
                // The full hosting anchor is preserved because flattening a
                // <xdr:grpSp> loses the child coordinate system, z-order,
                // styles and the fact that the objects are grouped. Only
                // hyperlink relationships are carried here; dump falls back
                // 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(

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Pass the sheet display name as the parent path (e.g. "/Sheet1"), not an internal part path.
  2. List available sheets first and use the exact name (case-insensitive match is accepted).
  3. If replaying a dump, re-run the dump against the current file so sheet names stay in sync.
  4. If the sheet was intentionally removed, drop the drawing-group entry from the batch or target a surviving sheet.

Example fix

// before — internal path, no sheet named 'xl/drawings/drawing1.xml'
handler.AddPart("/xl/drawings/drawing1.xml", "drawing-group", props);
// after — sheet display name as parent path
handler.AddPart("/Sheet1", "drawing-group", props);
Defensive patterns

Strategy: validation

Validate before calling

var name = parentPartPath.TrimStart('/');
var exists = handler.GetWorksheets()
    .Any(w => w.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
if (!exists) { /* list sheets, fix path, abort */ }

Type guard

static bool SheetResolves(ExcelHandler h, string parentPartPath) =>
    h.GetWorksheets().Any(w => w.Name.Equals(
        parentPartPath.TrimStart('/'), StringComparison.OrdinalIgnoreCase));

Try / catch

try { handler.AddPart(parentPartPath, "drawing-group", props); }
catch (ArgumentException ex) when (ex.Message.Contains("Sheet not found"))
{ /* reconcile sheet name, then retry with corrected path */ }

Prevention

When it happens

Trigger: Calling AddPart(parentPartPath, "drawing-group", ...) where parentPartPath (after TrimStart('/')) does not resolve to any worksheet name — e.g. an internal OOXML path like "/xl/drawings/drawing1.xml", a renamed/deleted sheet, a sheet[N] index that no longer exists, or an empty string.

Common situations: Replaying a dump into a workbook whose target sheet was renamed or removed between dump and batch; passing the package part path instead of the sheet display name; typo or trailing whitespace in the sheet name; referencing a sheet by 1-based index after sheets were reordered.

Related errors


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