GroupDocsGists
10/24/2017 - 1:02 PM

RemoveAttachmentExcel.cs

using (CellsDocument doc = Document.Load<CellsDocument>(Utilities.MapSourceFilePath(FilePath)))
{
    foreach (CellsWorksheet worksheet in doc.Worksheets)
    {
        for (int i = worksheet.Attachments.Count - 1; i >= 0; i--)
        {
            CellsAttachment attachment = worksheet.Attachments[i];
            if (attachment.IsLink && !File.Exists(attachment.SourceFullName) || // Linked file that is not available at this moment
                attachment.DocumentInfo.IsEncrypted) // Attached file protected with a password
            {
                // Remove the file if it meets at least one of the conditions above
                worksheet.Attachments.RemoveAt(i);
            }
        }
    }
    // Save changes
    doc.Save();
}