mirror of
https://github.com/iOfficeAI/OfficeCLI
synced 2026-04-21 13:37:23 +00:00
fix(xlsx): accept /namedrange[NAME] path bracket on Add
Users naturally write `add /namedrange[MyRange] ...` to mirror the selector notation used elsewhere, but the handler only looked at --prop name= and failed with 'name property is required'. Extract the identifier from the path bracket as the default name (integers are preserved as index semantics for future use).
This commit is contained in:
parent
a23c854241
commit
046cd3f2a1
1 changed files with 20 additions and 1 deletions
|
|
@ -479,7 +479,26 @@ public partial class ExcelHandler
|
|||
|
||||
case "namedrange" or "definedname":
|
||||
{
|
||||
var nrName = properties.GetValueOrDefault("name", "");
|
||||
// R4-4: accept `/namedrange[NAME]` path form so users don't
|
||||
// have to repeat the name in --prop name=. Path brackets take
|
||||
// precedence only when --prop name= is absent (explicit prop
|
||||
// still wins on mismatch, to keep other `/namedrange[N]` int
|
||||
// indexing semantics elsewhere in the handler usable as-is).
|
||||
var pathNrName = "";
|
||||
{
|
||||
var mNr = System.Text.RegularExpressions.Regex.Match(
|
||||
parentPath, @"^/namedrange\[([^\]]+)\]/?$",
|
||||
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
||||
if (mNr.Success)
|
||||
{
|
||||
var captured = mNr.Groups[1].Value;
|
||||
// Only treat as a name if it is not a pure integer
|
||||
// (preserves existing `/namedrange[1]` semantics).
|
||||
if (!int.TryParse(captured, out _))
|
||||
pathNrName = captured;
|
||||
}
|
||||
}
|
||||
var nrName = properties.GetValueOrDefault("name", pathNrName);
|
||||
if (string.IsNullOrEmpty(nrName))
|
||||
throw new ArgumentException("'name' property is required for namedrange");
|
||||
// Per OOXML §18.2.5: defined-name identifiers must start with
|
||||
|
|
|
|||
Loading…
Reference in a new issue