Пример #1
0
        public void remhyp()
        {
            Uri           z      = new Uri("http://broken-link/");
            WorksheetPart wsPart =
                (WorksheetPart)(wbPart.GetPartById(sheet.Id));
            var hyperLinks = wsPart.Worksheet.Descendants <Hyperlinks>().First();
            var hyperRel   = wsPart.HyperlinkRelationships.Where(c => c.Uri == z).FirstOrDefault();

            foreach (Hyperlink item in hyperLinks)
            {
                if (hyperRel.Id == item.Id)
                {
                    wsPart.DeleteReferenceRelationship(item.Id.ToString());

                    item.Remove();
                }
                if (hyperLinks.Count() == 0)
                {
                    hyperLinks.Remove();
                }
            }
            wsPart.Worksheet.Save();
        }