{"record":{"id":"0113cdaff293d989","repo":"iOfficeAI/OfficeCLI","slug":"series-seriesidx-not-found-total-serieschildr","errorCode":null,"errorMessage":"Series {seriesIdx} not found (total: {seriesChildren.Count})","messagePattern":"Series (.+?) not found \\(total: (.+?)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Handlers/Excel/ExcelHandler.Query.cs","lineNumber":741,"sourceCode":"                if (cxTitleText != null) chartNode.Format[\"title\"] = cxTitleText;\n                // Count series\n                var cxSeries = cxChartSpace.Descendants<DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing.Series>().ToList();\n                chartNode.Format[\"seriesCount\"] = cxSeries.Count;\n            }\n            else\n            {\n                var chart = chartInfo.StandardPart!.ChartSpace?.GetFirstChild<DocumentFormat.OpenXml.Drawing.Charts.Chart>();\n                if (chart != null)\n                    ChartHelper.ReadChartProperties(chart, chartNode, chartMatch.Groups[2].Success ? 1 : depth);\n            }\n\n            // If series sub-path requested, extract the specific series child\n            if (chartMatch.Groups[2].Success)\n            {\n                var seriesIdx = int.Parse(chartMatch.Groups[2].Value);\n                var seriesChildren = chartNode.Children.Where(c => c.Type == \"series\").ToList();\n                if (seriesIdx < 1 || seriesIdx > seriesChildren.Count)\n                    throw new ArgumentException($\"Series {seriesIdx} not found (total: {seriesChildren.Count})\");\n                var seriesNode = seriesChildren[seriesIdx - 1];\n                seriesNode.Path = path;\n                return seriesNode;\n            }\n            return chartNode;\n        }\n\n        // Pivot table path: /Sheet1/pivottable[N]\n        var pivotMatch = Regex.Match(cellRef, @\"^pivottable\\[(\\d+)\\]$\", RegexOptions.IgnoreCase);\n        if (pivotMatch.Success)\n        {\n            var ptIdx = int.Parse(pivotMatch.Groups[1].Value);\n            var pivotParts = worksheet.PivotTableParts.ToList();\n            if (ptIdx < 1 || ptIdx > pivotParts.Count)\n                throw new ArgumentException($\"PivotTable index {ptIdx} out of range (1-{pivotParts.Count})\");\n\n            var pivotPart = pivotParts[ptIdx - 1];\n            var ptNode = new DocumentNode { Path = path, Type = \"pivottable\" };","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Handlers/Excel/ExcelHandler.Query.cs#L723-L759","documentation":"Thrown for /Sheet/chart[N]/series[K] when K exceeds the number of series Children on chart N (1-based). Series Children are only populated for standard charts; an extended chart has zero series Children, so any series index throws 'Series K not found (total: 0)'. The count comes from chartNode.Children of Type 'series'.","triggerScenarios":"handler.Get(\"/Sheet1/chart[1]/series[5]\") on a chart with fewer than 5 series. Indexing a series on an extended chart (total: 0). series[0].","commonSituations":"Hard-coded series index after series were added or removed. Querying series on a modern/extended chart. Zero-based indexing.","solutions":["Use a 1-based index within the chart's series-children count.","For extended charts, read seriesCount from Format instead of indexing series Children.","Enumerate the chart node's series Children first to learn the count."],"exampleFix":"// before\nvar s = handler.Get(\"/Sheet1/chart[1]/series[5]\"); // throws if <5 series\n\n// after\nvar chart = handler.Get(\"/Sheet1/chart[1]\");\nvar series = chart.Children.Where(c => c.Type == \"series\").ToList();\nif (series.Count == 0) return null; // extended chart — read chart.Format[\"seriesCount\"] instead\nvar s = handler.Get(\"/Sheet1/chart[1]/series[\" + Math.Min(5, series.Count) + \"]\");","handlingStrategy":"try-catch","validationCode":"// discover series count from the chart node, then index safely\nvar chart = handler.Get(\"/Sheet1/chart[1]\");\nvar series = chart.Children.Where(c => c.Type == \"series\").ToList();\nif (series.Count == 0) return null; // extended chart — read Format[\"seriesCount\"]\nvar n = Math.Clamp(k, 1, series.Count);\nreturn handler.Get($\"/Sheet1/chart[1]/series[{n}]\");","typeGuard":"static int? ElementIndex(string cellRef, string element)\n{\n    var m = Regex.Match(cellRef, $@\"^{Regex.Escape(element)}\\[(\\d+)$\", RegexOptions.IgnoreCase);\n    return m.Success && int.TryParse(m.Groups[1].Value, out var i) ? i : null;\n}","tryCatchPattern":"try { return handler.Get(\"/Sheet1/chart[1]/series[5]\"); }\ncatch (ArgumentException ex) { /* ex.Message: 'Series 5 not found (total: N)' */ return null; }","preventionTips":["Series indices are 1-based — there is no index 0.","Extended charts expose seriesCount in Format, not series Children — don't index them.","Read the chart node's series Children to learn the count first."],"tags":["excel","charts","series","path-index","argument-exception"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}