iOfficeAI/OfficeCLI · error · ArgumentException
Sheet not found: {oleSheetName}
Error message
Sheet not found: {oleSheetName} What it means
Thrown by the OLE-add handler when the sheet name extracted from the parentPath does not resolve to an existing worksheet. The path is split on the first '/' and the first segment is the sheet name; if FindWorksheet returns null, this fires before any OLE processing begins.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Drawings.cs:74
// Structure produced:
// Worksheet > oleObjects > oleObject(progId, shapeId, r:id=embedRel)
// > objectPr(defaultSize=0, r:id=iconRel)
// > anchor(moveWithCells=1)
// > from(col, colOff, row, rowOff)
// > to (col, colOff, row, rowOff)
//
// We skip the legacy VML shape that Excel historically
// generates as a fallback — when the modern objectPr/anchor
// is present, Office 2010+ renders from it directly. The
// constraint-required shapeId still needs a value, so we
// allocate one in the legal range (1-67098623) unique per
// worksheet. For round-trip fidelity, we also create an
// empty legacy VmlDrawingPart and register the shapeId
// there so the relationship target exists.
var oleSheetSegs = parentPath.TrimStart('/').Split('/', 2);
var oleSheetName = oleSheetSegs[0];
var oleWorksheet = FindWorksheet(oleSheetName)
?? throw new ArgumentException($"Sheet not found: {oleSheetName}");
var oleSrc = OfficeCli.Core.OleHelper.RequireSource(properties);
OfficeCli.Core.OleHelper.WarnOnUnknownOleProps(properties);
// Embedding the workbook into itself: the source is open/locked by this
// resident session, so the read yields 0 bytes and produces an empty
// OLE payload real Excel refuses (0x800A03EC). Reject up front.
try
{
if (!string.IsNullOrEmpty(oleSrc) && !string.IsNullOrEmpty(_filePath)
&& string.Equals(Path.GetFullPath(oleSrc), Path.GetFullPath(_filePath),
StringComparison.OrdinalIgnoreCase))
throw new ArgumentException(
"Cannot embed a workbook into itself: the source file is the workbook being edited. "
+ "Embed a different file, or make a copy of the source first.");
}
catch (ArgumentException) { throw; }
catch { /* path canonicalization failed — fall through to normal read */ }View on GitHub (pinned to 1ced45e900)
Solutions
- List worksheets to confirm the exact sheet name.
- Check for trailing spaces or case sensitivity.
- Create the sheet if needed before adding the OLE object.
Example fix
// before (sheet is 'Dashboard') add /dashboard --type ole --src data.xlsx // after add /Dashboard --type ole --src data.xlsx
Defensive patterns
Strategy: validation
Validate before calling
// Check the sheet exists before calling OLE add
var sheetName = parentPath.TrimStart('/').Split('/', 2)[0];
if (handler.FindWorksheet(sheetName) == null)
throw new InvalidOperationException($"Sheet not found: {sheetName}"); Try / catch
try { handler.AddOle(parentPath, properties); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Sheet not found:"))
{
Console.Error.WriteLine($"{ex.Message} Verify the sheet name.");
} Prevention
- List worksheets and verify the exact name before the add call.
- Check casing and trailing whitespace in sheet names.
- Create the target sheet if it does not exist.
When it happens
Trigger: Calling add /NonExistentSheet --type ole --src object.xlsx. The worksheet with that exact name does not exist in the workbook.
Common situations: Sheet was renamed or deleted. Casing or whitespace mismatch. Script references a sheet from a template that was modified.
Related errors
- Sheet not found: {sheetName}
- Sheet not found: {fbSheetName}
- Cannot embed a workbook into itself: the source file is the
- 'display' property is not supported for Excel OLE (Excel alw
- 'name' property is not supported for Excel OLE (Spreadsheet
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/a8d19d45539c62ef.
Report an issue: GitHub.