{"record":{"id":"3346b358e37dc759","repo":"iOfficeAI/OfficeCLI","slug":"invalid-field-value-empty-a1-range","errorCode":null,"errorMessage":"Invalid {field} '{value}': empty A1 range.","messagePattern":"Invalid (.+?) '(.+?)': empty A1 range\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs","lineNumber":39,"sourceCode":"    // rule cannot land an `INVALID!REF` literal in the sheet — Excel\n    // refuses to open the file in that state.\n    private static readonly System.Text.RegularExpressions.Regex SqrefShape =\n        new(@\"^\\$?[A-Z]+\\$?[0-9]+(:\\$?[A-Z]+\\$?[0-9]+)?(\\s+\\$?[A-Z]+\\$?[0-9]+(:\\$?[A-Z]+\\$?[0-9]+)?)*$\",\n            System.Text.RegularExpressions.RegexOptions.Compiled\n            | System.Text.RegularExpressions.RegexOptions.IgnoreCase);\n\n    // Whole-column (A:A, B:XFD) and whole-row (1:1, 2:10) tokens are legal\n    // sqref members — dump reads them from real files, so add/replay must\n    // accept them too (a column-wide CF rule could not be round-tripped).\n    private static readonly System.Text.RegularExpressions.Regex SqrefWholeToken =\n        new(@\"^(\\$?[A-Z]+:\\$?[A-Z]+|\\$?[0-9]+:\\$?[0-9]+)$\",\n            System.Text.RegularExpressions.RegexOptions.Compiled\n            | System.Text.RegularExpressions.RegexOptions.IgnoreCase);\n\n    internal static string ValidateSqref(string value, string field)\n    {\n        if (string.IsNullOrWhiteSpace(value))\n            throw new ArgumentException($\"Invalid {field} '{value}': empty A1 range.\");\n        var trimmed = value.Trim();\n        var ok = trimmed\n            .Split(' ', StringSplitOptions.RemoveEmptyEntries)\n            .All(tok => SqrefShape.IsMatch(tok) || SqrefWholeToken.IsMatch(tok));\n        if (!ok)\n            throw new ArgumentException(\n                $\"Invalid {field} '{value}': expected an A1 reference (e.g. 'A1', 'A1:D10', 'A:A', '1:3', 'A1 B2:C5').\");\n        // Shape-valid tokens can still point outside Excel's grid: sqref=\"A0\"\n        // passed here, saved fine, and real Excel refused the whole file\n        // (0x800A03EC) — the same out-of-grid family the drawing-anchor parser\n        // rejects. Bounds-check every cell/row/column component.\n        foreach (var tok in trimmed.Split(' ', StringSplitOptions.RemoveEmptyEntries))\n        {\n            foreach (System.Text.RegularExpressions.Match cm in\n                System.Text.RegularExpressions.Regex.Matches(tok, @\"\\$?([A-Z]+)?\\$?([0-9]+)?\",\n                    System.Text.RegularExpressions.RegexOptions.IgnoreCase))\n            {\n                if (cm.Length == 0) continue;","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Validation.cs#L21-L57","documentation":"Thrown by ValidateSqref when the sqref value is null, empty, or whitespace. sqref (sequence-of-references) is the OOXML attribute holding A1 ranges for conditional formatting, data validation, etc. An empty value is invalid — at least one A1 token is required.","triggerScenarios":"Calling any CF/DV API with sqref='', sqref=null (when the API passes it through), or sqref='   ' (only whitespace). ValidateSqref is the shared entry point for all sqref-bearing fields.","commonSituations":"Optional parameters defaulting to empty string; form inputs left blank; conditional logic that builds sqref conditionally and ends up empty.","solutions":["Provide at least one A1 token (e.g. 'A1' or 'A1:B10').","Skip the CF/DV rule entirely if there is no range to apply it to.","Default the parameter to a meaningful range rather than ''."],"exampleFix":"// before\nstring sqref = \"\"; // empty\n// after\nstring sqref = \"A1\"; // at least one cell\n// or skip the rule if no range applies:\nif (string.IsNullOrWhiteSpace(sqref)) return;","handlingStrategy":"validation","validationCode":"static bool HasSqrefValue(string s) => !string.IsNullOrWhiteSpace(s);","typeGuard":"null","tryCatchPattern":"try { ValidateSqref(value, field); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"empty A1 range\"))\n{ /* skip the CF/DV rule or default to a sane range */ }","preventionTips":["sqref must never be empty for a CF/DV rule.","Treat blank sqref as 'no rule' upstream rather than passing it down.","Default optional sqref params to null and skip the rule when null."],"tags":["excel","conditional-formatting","data-validation","input-validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}