title: How to delete all external relationships from OOXML spreadsheet
body: <p>I have received help how to identify all external relationships in Open XML SDK. See here: <a href="https://stackoverflow.com/questions/73219104/find-all-external-relationships-in-an-ooxml-excel-spreadsheet">Find all external relationships in an OOXML/Excel spreadsheet</a></p>
  <p>I want to delete all identified external relationships, but I get the error <code>System.InvalidOperationException: 'The specified ExternalRelationship is not referenced by this part.'</code>.</p>
  <p>What is the issue?</p>
  <pre><code>using DocumentFormat.OpenXml.Packaging;
  using DocumentFormat.OpenXml.Spreadsheet;
  
  using (var spreadsheet = SpreadsheetDocument.Open(file, true))
  {
      List&lt;ExternalRelationship&gt; extRels = spreadsheet
          .GetAllParts()
          .SelectMany(p =&gt; p.ExternalRelationships)
          .ToList();
  
      if (extRels.Count &gt; 0) // If external relationships
      {
          Console.WriteLine($&quot;--&gt; {extRels.Count} external relationships&quot;);
          foreach (ExternalRelationship rel in extRels)
          {
              spreadsheet.DeleteExternalRelationship(rel);
              // I have also tried this: spreadsheet.DeleteExternalRelationship(rel.Id);
              // and this: spreadsheet.WorkbookPart.DeleteExternalRelationship(rel);
          }
      }
      else // If no external relationships, inform user
      {
          Console.WriteLine($&quot;--&gt; {extRels.Count} external relationships&quot;);
      }
  
      spreadsheet.Save();
  }
  </code></pre>