{"record":{"id":"8419ed32494e505d","repo":"iOfficeAI/OfficeCLI","slug":"source-sheet-has-no-relationship-id","errorCode":null,"errorMessage":"Source sheet has no relationship id","messagePattern":"Source sheet has no relationship id","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/PivotTableHelper.Readback.cs","lineNumber":409,"sourceCode":"            var parts = newSourceSpec.Split('!', 2);\n            newSheetName = parts[0].Trim().Trim('\\'', '\"').Trim();\n            newRef = parts[1].Trim();\n        }\n        else\n        {\n            newSheetName = existingWsSource.Sheet?.Value ?? \"\";\n            newRef = newSourceSpec;\n        }\n\n        // Locate the source worksheet via the workbook part.\n        var workbookPart = pivotPart.GetParentParts().OfType<WorksheetPart>().FirstOrDefault()\n            ?.GetParentParts().OfType<WorkbookPart>().FirstOrDefault()\n            ?? throw new InvalidOperationException(\"Workbook part not reachable from pivot table part\");\n        var sheetEntry = workbookPart.Workbook?.Sheets?.Elements<Sheet>()\n            .FirstOrDefault(s => s.Name?.Value == newSheetName)\n            ?? throw new ArgumentException($\"Source sheet not found: {newSheetName}\");\n        if (sheetEntry.Id?.Value is not string srcRelId)\n            throw new InvalidOperationException(\"Source sheet has no relationship id\");\n        var sourceWsPart = workbookPart.GetPartById(srcRelId) as WorksheetPart\n            ?? throw new InvalidOperationException(\"Source sheet relationship does not resolve to a WorksheetPart\");\n\n        // Re-read source data from the new range.\n        var (headers, columnData, _) = ReadSourceData(sourceWsPart, newRef);\n        if (headers.Length == 0)\n            throw new ArgumentException(\"Source range has no data\");\n        if (columnData.Count == 0 || columnData[0].Length == 0)\n            throw new ArgumentException(\"Source range has no data rows\");\n\n        // R15-2: Before mutating any cache/pivot state, validate that existing\n        // row/col/value/filter field references still fit inside the new\n        // (possibly narrower) header list. A silent drop or index clamp here\n        // would leave the DataFields pointing past the rendered columnData,\n        // crashing RenderPivotIntoSheet with ArgumentOutOfRangeException.\n        // Prefer strict error over data loss: user must explicitly restate the\n        // affected axes in the same Set call if they intended to drop them.\n        var newFieldCount = headers.Length;","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/PivotTableHelper.Readback.cs#L391-L427","documentation":"Thrown when the <Sheet> element WAS found in Workbook.Sheets but its Id attribute is null or not a string. Every <Sheet> in valid OOXML must carry an r:id relationship attribute linking it to a worksheet part. The pattern 'sheetEntry.Id?.Value is not string srcRelId' guards both the null-Id and non-string-Id cases, indicating the package's relationship layer is corrupt.","triggerScenarios":"The xlsx was hand-edited, produced by a broken third-party exporter, or suffered a partial/corrupted save, stripping the r:id from a <sheet> element. Effectively unreachable with files written by Excel or LibreOffice.","commonSituations":"Files generated by low-quality OOXML libraries that omit relationship ids; manual XML editing of the sheet inside the zip; a save interrupted partway through leaving workbook.xml with dangling sheet entries.","solutions":["Open and re-save the workbook in Excel or LibreOffice to repair the relationship layer.","Use a different worksheet as the pivot source.","Validate the package structure with an OOXML repair/conformance tool.","If generating the file programmatically, ensure every <sheet r:id=\"...\"/> entry has a matching relationship in workbook.xml.rels."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { SetPivotTableProperties(pivotPart, new { source = spec }); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"relationship id\"))\n{\n    // Package corruption — the sheet's r:id is missing.\n    // Re-save in Excel/LibreOffice, or fall back to a different source sheet.\n    ReportPackageCorruption(workbookPath);\n}","preventionTips":["Do not hand-edit the XML inside xlsx packages.","Use reputable libraries to generate xlsx files.","Re-save workbooks in Excel/LibreOffice before programmatic manipulation if they came from an untrusted source.","Validate package conformance before processing unfamiliar files."],"tags":["pivot","excel","ooxml","corruption","relationship","set-property"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}