GroupDocsGists
10/24/2017 - 1:02 PM

AddWatermarkToAttachmentExcel.cs

TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
using (CellsDocument doc = Document.Load<CellsDocument>(Utilities.MapSourceFilePath(FilePath)))
{
    foreach (CellsWorksheet worksheet in doc.Worksheets)
    {
        foreach (CellsAttachment attachment in worksheet.Attachments)
        {
            // Check if the attached file is supported by GroupDocs.Watermark
            if (attachment.DocumentInfo.FileFormat != FileFormat.Undefined && !attachment.DocumentInfo.IsEncrypted)
            {
                // Load the attached document
                using (Document attachedDocument = attachment.LoadDocument())
                {
                    // Add wateramrk
                    attachedDocument.AddWatermark(watermark);

                    // Save changes in the attached file
                    attachedDocument.Save();
                }
            }
        }
    }
    // Save changes
    doc.Save();
}