{"record":{"id":"2e89b1ea83ec1aec","repo":"iOfficeAI/OfficeCLI","slug":"worksheet-missing","errorCode":null,"errorMessage":"Worksheet missing","messagePattern":"Worksheet missing","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.Cache.cs","lineNumber":258,"sourceCode":"\n    private static string MonthShortName(int month)\n        => month switch\n        {\n            1  => \"Jan\", 2  => \"Feb\", 3  => \"Mar\", 4  => \"Apr\",\n            5  => \"May\", 6  => \"Jun\", 7  => \"Jul\", 8  => \"Aug\",\n            9  => \"Sep\", 10 => \"Oct\", 11 => \"Nov\", 12 => \"Dec\",\n            _  => month.ToString(System.Globalization.CultureInfo.InvariantCulture),\n        };\n\n    private static string CapitalizeFirst(string s)\n        => string.IsNullOrEmpty(s) ? s : char.ToUpperInvariant(s[0]) + s.Substring(1);\n\n    // ==================== Source Data Reader ====================\n\n    private static (string[] headers, List<string[]> columnData, uint?[] columnStyleIds) ReadSourceData(\n        WorksheetPart sourceSheet, string sourceRef)\n    {\n        var ws = sourceSheet.Worksheet ?? throw new InvalidOperationException(\"Worksheet missing\");\n        var sheetData = ws.GetFirstChild<SheetData>();\n        if (sheetData == null) return (Array.Empty<string>(), new List<string[]>(), Array.Empty<uint?>());\n\n        // Parse range \"A1:D100\"\n        var parts = sourceRef.Replace(\"$\", \"\").Split(':');\n        if (parts.Length != 2) throw new ArgumentException($\"Invalid source range: {sourceRef}\");\n\n        var (startCol, startRow) = ParseCellRef(parts[0]);\n        var (endCol, endRow) = ParseCellRef(parts[1]);\n\n        var startColIdx = ColToIndex(startCol);\n        var endColIdx = ColToIndex(endCol);\n        // R6-3: reject columns beyond Excel's hard max (XFD = 16384). Previously\n        // XFE / XFZ / ZZZZ silently parsed into oversized indices, produced a\n        // giant colCount, and either crashed deep in the renderer or wrote an\n        // invalid source range into the cache.\n        const int ExcelMaxColumn = 16384; // XFD\n        if (startColIdx > ExcelMaxColumn)","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.Cache.cs#L240-L276","documentation":"InvalidOperationException thrown in PivotTableHelper.ReadSourceData when the supplied WorksheetPart has a null Worksheet. This is an internal-state/precondition failure: the pivot cache builder was handed a worksheet part whose underlying Worksheet DOM object is missing, so it cannot read the source cell range.","triggerScenarios":"Creating/refreshing a pivot table (or computing per-column style ids) against a WorksheetPart whose .Worksheet is null — typically a corrupted, empty, or not-yet-loaded sheet part inside the workbook package.","commonSituations":"Operating on a workbook where the source sheet was deleted/corrupted but the part reference remains; an incompletely-saved file; pointing sourceRef at a sheet whose part exists but contains no <worksheet> root.","solutions":["Verify the source worksheet exists and is a valid sheet in the workbook before creating/refreshing the pivot table.","Open and repair the workbook in Excel, then retry.","Confirm sourceRef targets an existing, populated sheet (not a deleted/renamed one)."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"var ws = sourceSheet.Worksheet;\nif (ws == null) { /* report: source worksheet part is missing its <worksheet>; repair file */ }","typeGuard":"static bool HasValidWorksheet(DocumentFormat.OpenXml.Packaging.WorksheetPart p) => p?.Worksheet != null;","tryCatchPattern":null,"preventionTips":["Validate the source sheet part has a non-null Worksheet before pivot operations.","Repair corrupted/incomplete workbooks in Excel before operating.","Point sourceRef at a real, populated sheet."],"tags":["pivot-table","excel","ooxml","invalid-operation","precondition","officecli"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}