iOfficeAI/OfficeCLI · error · System.ArgumentException
Sheet not found: {rbSheetName}
Error message
Sheet not found: {rbSheetName} What it means
Thrown by AddRowBreak when FindWorksheet(rbSheetName) returns null. The sheet name is taken from the first segment of parentPath (after trimming the leading slash). Unlike AddRun there is no prior path-length check, so any parentPath whose first segment is not a real worksheet triggers this, including empty or malformed paths.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Cells.cs:1327
return $"/{runSheetName}/{runCellRef}/run[{runIndex}]";
}
private string AddPageBreak(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)
{
var index = position?.Index;
// Route to rowbreak or colbreak based on properties
if (properties.ContainsKey("col") || properties.ContainsKey("column"))
return Add(parentPath, "colbreak", position, properties);
return Add(parentPath, "rowbreak", position, properties);
}
private string AddRowBreak(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)
{
var index = position?.Index;
var rbSegments = parentPath.TrimStart('/').Split('/', 2);
var rbSheetName = rbSegments[0];
var rbWorksheet = FindWorksheet(rbSheetName)
?? throw new ArgumentException($"Sheet not found: {rbSheetName}");
var rbWs = GetSheet(rbWorksheet);
var rbRowIdx = uint.Parse(properties.GetValueOrDefault("row") ?? properties.GetValueOrDefault("index")
?? throw new ArgumentException("'row' property is required for rowbreak"));
// A break id of 0 or beyond the grid fails the schema's Min/Max
// constraints — reject up front instead of writing invalid OOXML.
if (rbRowIdx < 1 || rbRowIdx > 1048576)
throw new ArgumentException(
$"Invalid 'row' value: '{rbRowIdx}'. Row breaks must be between 1 and 1048576.");
var rowBreaks = rbWs.GetFirstChild<RowBreaks>();
if (rowBreaks == null)
{
rowBreaks = new RowBreaks();
rbWs.AppendChild(rowBreaks);
}
// Optional restricted column span (min/max) — mirrors the Set path so a
// dump-emitted `add rowbreak row=N min=.. max=..` reproduces aView on GitHub (pinned to 1ced45e900)
Solutions
- Confirm the sheet exists via a Get on / and use the exact name.
- Create the sheet first if it is missing.
- Ensure parentPath starts with /<existingSheetName>.
Example fix
// before
handler.Add("/SheetX", "rowbreak", null, new() { ["row"] = "5" }); // SheetX missing
// after
handler.Add("/Sheet1", "rowbreak", null, new() { ["row"] = "5" }); Defensive patterns
Strategy: validation
Validate before calling
string sheet = "Sheet1";
var sheets = handler.Query("/");
if (!sheets.Any(s => string.Equals(s.Name, sheet, StringComparison.OrdinalIgnoreCase)))
throw new InvalidOperationException($"Sheet not found: {sheet}");
handler.Add("/" + sheet, "rowbreak", null, props); Type guard
static bool SheetExists(IExcelHandler h, string sheet)
=> h.Query("/").Any(s => string.Equals(s.Name, sheet, StringComparison.OrdinalIgnoreCase)); Try / catch
try { handler.Add(parentPath, "rowbreak", null, props); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Sheet not found"))
{ /* create the sheet or surface the missing name */ } Prevention
- Resolve sheet names from a freshly queried sheet list.
- Create the sheet before adding breaks to it.
- Build paths with a /{sheet} helper to avoid dropping the leading segment.
When it happens
Trigger: Add type=rowbreak with parentPath="/BadSheet" or parentPath="/BadSheet/...". Also reachable when properties force routing here via AddRowBreak: if col/column keys are absent, Add dispatches to rowbreak. A typo or a deleted sheet name reproduces it.
Common situations: Dump-emitted rowbreak path uses a sheet name that was later renamed. Script targets a sheet from a different workbook. Trailing slash producing an empty first segment.
Related errors
- Sheet not found: {runSheetName}
- 'row' property is required for rowbreak
- Invalid 'row' value: '{rbRowIdx}'. Row breaks must be betwee
- Sheet not found: {cbSheetName}
- Sheet not found: {cfSheetName}
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/5c8fc68b9280eee9.
Report an issue: GitHub.