iOfficeAI/OfficeCLI · error · ArgumentException
Sheet not found: {dvSheetName}
Error message
Sheet not found: {dvSheetName} What it means
Thrown by AddValidation when FindWorksheet(dvSheetName) returns null. dvSheetName is the first segment of parentPath after trimming '/'. Same plain 'Sheet not found: <name>' inline form used by AddComment.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.Tables.cs:507
return rowEl != null && colEl != null
&& int.TryParse(rowEl.Value.Trim(), out var r) && r == row0
&& int.TryParse(colEl.Value.Trim(), out var c) && c == col0;
});
if (target == null) return;
target.Remove();
using var wstream = vmlPart.GetStream(System.IO.FileMode.Create, System.IO.FileAccess.Write);
vmlDoc.Save(wstream);
}
catch { }
}
private string AddValidation(string parentPath, string type, InsertPosition? position, Dictionary<string, string> properties)
{
var index = position?.Index;
var dvSegments = parentPath.TrimStart('/').Split('/', 2);
var dvSheetName = dvSegments[0];
var dvWorksheet = FindWorksheet(dvSheetName)
?? throw new ArgumentException($"Sheet not found: {dvSheetName}");
// CONSISTENCY(range-alias): cf/colorscale/iconset/pivottable all take
// sqref/range/ref interchangeably; validation lacked `range` only.
var dvSqref = properties.GetValueOrDefault("sqref")
?? properties.GetValueOrDefault("range")
?? properties.GetValueOrDefault("ref")
?? throw new ArgumentException("Property 'sqref' (or 'range'/'ref') is required for validation");
// NOTE: multi-region sqref ("A1:A5 C1:C5") is legal and opens fine in
// real Excel — a fuzz report claiming otherwise was a render-service
// cache false positive (fresh-content retest and an openpyxl gold
// sample both open cleanly). Do not add a guard for multi-region —
// but DO validate each token's A1 shape: an arbitrary string landed
// verbatim in sqref= and real Excel refused the file (0x800A03EC)
// while schema validation stayed green.
dvSqref = ValidateSqref(dvSqref, "validation ref");
var dv = new DataValidationView on GitHub (pinned to 1ced45e900)
Solutions
- Verify the name against handler.GetDumpSheetNames() and use the exact spelling.
- Correct the first parentPath segment (case-insensitive match).
- Create the sheet first if it is genuinely missing.
Example fix
// before
handler.Add("/Sheat1", "validation", null, new() { ["sqref"] = "A1:A5", ["type"] = "whole" });
// after
handler.Add("/Sheet1", "validation", null, new() { ["sqref"] = "A1:A5", ["type"] = "whole" }); Defensive patterns
Strategy: validation
Validate before calling
var sheet = parentPath.TrimStart('/').Split('/', 2)[0];
if (!handler.GetDumpSheetNames()
.Any(n => n.Equals(sheet, StringComparison.OrdinalIgnoreCase)))
throw new InvalidOperationException($"No sheet '{sheet}'. Available: " +
string.Join(", ", handler.GetDumpSheetNames())); Prevention
- Resolve sheet names dynamically via GetDumpSheetNames().
- Validate the parentPath first segment before every validation add.
- Guard against empty sheet names from malformed paths.
When it happens
Trigger: Call Add type "validation"/"datavalidation" with a parentPath whose first segment names no worksheet, e.g. "/BadSheet".
Common situations: Sheet-name typo; sheet renamed/deleted; path copied from a different workbook; locale-specific sheet name with characters that need exact spelling.
Related errors
- Sheet not found: {cmtSheetName}
- Sheet not found: {afSheetName}
- Unrecognized cell parent path segment '{cellSegments[1]}'. E
- Anchor must be a column path like /{colSheetName}/col[L], go
- series must be added to a chart parent: /SheetName/chart[N]
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/ecd89b87a8998df1.
Report an issue: GitHub.