đź’ˇ Full working example on GitHub: groupdocs-watermark/audit-hidden-watermarks-in-excel-workbooks-dotnet
Introduction
Excel has no watermark feature. Ask it to add one and you will find yourself putting a picture in a header, setting a background image, or dropping a WordArt shape onto the sheet - three unrelated mechanisms that happen to produce something watermark-shaped. Add OLE attachments, which can carry an entire marked file inside the workbook, and there are four separate places a mark can live.
Three of them are invisible in the editing grid. Header content appears in print preview. A background sits behind the cells and scrolls past unnoticed. An attachment is an icon nobody clicks. Only shapes are obvious, and they are the one carrier a reader can delete without thinking about it.
So the first question about a workbook is not “how do I add a watermark” but “what is already in here, and where”. This guide answers that with GroupDocs.Watermark for .NET, then marks and clears each carrier in turn.
Why the Invisible Carriers Matter
Two failures follow from marks you cannot see, and they point in opposite directions.
The first: a workbook leaves the building believing it is marked. The notice went into a header, which the recipient never opens, and the spreadsheet they forward looks entirely unmarked on screen. The marking existed, and did nothing.
The second: a workbook arrives from a client, becomes the basis for your own model, and quietly carries their logo and confidentiality notice into your reporting. Nobody put them there on purpose, and nobody noticed they stayed.
Both are inventory problems before they are watermarking problems.
Prerequisites
- .NET 8.0 SDK or later
- GroupDocs.Watermark 26.9.0
- An
.xlsxworkbook - Optionally a licence; without one the library runs in evaluation mode
Installation
dotnet add package GroupDocs.Watermark --version 26.9.0
Step 1: Inventory What Is Already There
The pass to run first. It loads the workbook, changes nothing, and reports each carrier separately.
using var watermarker = new Watermarker(sourcePath, new SpreadsheetLoadOptions());
SpreadsheetContent content = watermarker.GetContent<SpreadsheetContent>();
for (int i = 0; i < content.Worksheets.Count; i++)
{
SpreadsheetWorksheet worksheet = content.Worksheets[i];
int headerTexts = 0;
int headerImages = 0;
foreach (SpreadsheetHeaderFooter headerFooter in worksheet.HeadersFooters)
{
foreach (SpreadsheetHeaderFooterSection section in headerFooter.Sections)
{
if (!string.IsNullOrEmpty(section.Script)) headerTexts++;
if (section.Image != null) headerImages++;
}
}
Console.WriteLine($"Worksheet {i}: header texts {headerTexts}, header images "
+ $"{headerImages}, background {(worksheet.BackgroundImage != null ? "yes" : "no")}, "
+ $"shapes {worksheet.Shapes.Count}, attachments {worksheet.Attachments.Count}");
}
For the demo workbook this prints:
Worksheet 0: header texts 4, header images 1, background yes, shapes 1, attachments 0
Worksheet 1: header texts 1, header images 0, background no, shapes 0, attachments 0
One sheet carrying marks in four places, another with a single header string.
Note the loop over HeadersFooters: each worksheet has six of them - primary,
even and first, as header and footer - with three sections each. Eighteen
slots per sheet is why checking “the header” proves nothing.
Step 2: Mark the Header Picture
A header picture is usually a logo, and it prints on every page while staying out of the editing view entirely.
foreach (SpreadsheetHeaderFooter headerFooter in worksheet.HeadersFooters)
{
foreach (SpreadsheetHeaderFooterSection section in headerFooter.Sections)
{
if (section.Image != null)
{
section.Image.Add(watermark);
stamped++;
}
}
}
section.Image is a SpreadsheetWatermarkableImage, so Add rasterises the
mark into the picture data rather than placing anything new on the sheet.
Switch Excel to Page Layout view and the header appears - the stamped logo on
the left, the confidentiality notice in the centre:
Switch back to Normal view and all of that disappears. The grid shows the figures alone, which is exactly why header marking is so easy to overlook when auditing a workbook by eye.
Step 3: Mark the Shape Images
Shapes are the visible layer - logos, callouts, pasted charts. Marking the picture rather than the sheet means the mark survives the picture being copied elsewhere.
foreach (SpreadsheetShape shape in worksheet.Shapes)
{
if (shape.Image != null)
{
shape.Image.Add(watermark);
stamped++;
}
}
Shapes without a picture - text boxes, autoshapes - have a null Image and
are skipped, which is what the guard is for.
Step 4: The Background, Visible Only on Screen
Worksheet backgrounds are the sturdiest carrier: a tiled picture behind the cells that a reader cannot select or delete on the sheet.
foreach (SpreadsheetWorksheet worksheet in content.Worksheets)
{
if (worksheet.BackgroundImage != null)
{
worksheet.BackgroundImage.Add(watermark);
stamped++;
}
}
In Normal view the tiled INTERNAL pattern sits behind the cells, carrying the stamp wherever the sheet scrolls:
After BackgroundImage = null the same workbook is clean, with the data and
the chart untouched:
There is a catch worth knowing before choosing this carrier: Excel does not print worksheet backgrounds. Render the printed page of all three versions - original, stamped, background removed - and they come out byte-for-byte identical. The file changes substantially; the printed page does not.
So the background protects the screen copy and contributes nothing to a printout or a PDF export. Use a header when the mark has to survive printing.
Step 5: Attachments Are Not Covered by Any of This
An OLE attachment is a whole file stored inside the workbook, and the watermark you applied to the workbook does not reach inside it.
foreach (SpreadsheetAttachment attachment in worksheet.Attachments)
{
Console.WriteLine($" attachment: {attachment.SourceFullName} "
+ $"({attachment.Content.Length} bytes)");
found++;
}
SourceFullName and Content are enough for an audit line without writing
anything to disk. A non-zero count means the workbook is carrying a file that
keeps whatever marking it had when embedded - frequently none.
The demo adds one so there is something real to find:
content.Worksheets[0].Attachments.AddAttachment(
payload, attachmentName, null, 50, 100, 200, 100);
The arguments are the content bytes, a source file name whose extension picks the opening application, an optional preview image, and the frame rectangle in points. Passing null for the preview is what produces this on the sheet:
An entire file lives behind that rectangle. Supply a preview image and it at least looks like something; leave it null, as here, and a reader scrolling the sheet has no reason to think anything is there at all.
Step 6: Clearing What Should Not Be There
The cleanup half. Setting Script and Image to null empties a header
section; assigning null to BackgroundImage drops the tiled picture.
foreach (SpreadsheetHeaderFooterSection section in headerFooter.Sections)
{
if (!string.IsNullOrEmpty(section.Script) || section.Image != null)
{
section.Script = null;
section.Image = null;
cleared++;
}
}
Compare that with the Page Layout screenshot from Step 2. The logo and the confidentiality notice are gone, replaced by Excel’s empty “Add header” placeholder, and the figures are exactly as they were. This is the pass to run on a workbook that arrived from outside and is about to become your own.
The guard matters for the return value: without it the method would report eighteen cleared sections per sheet whether or not anything was in them. Here it reports five, which is the number that actually held content.
Comparing the Four Carriers
| Header / footer | Background | Shape | Attachment | |
|---|---|---|---|---|
| Visible in the grid | No | Behind cells | Yes | Icon only |
| Prints | Yes | No | Yes | No |
| Image can be watermarked | Yes | Yes | Yes | No |
| Reader deletes it in one click | No | No | Yes | Yes |
| Can hide a whole file | No | No | No | Yes |
Read it as a set of trade-offs rather than a ranking. Headers reach paper but hide on screen. Backgrounds do the reverse. Shapes communicate immediately and disappear just as fast. Attachments are the blind spot in every audit that only looks at the sheet.
Practical Notes
- Inventory before marking. One load, no save, and it replaces an assumption with a list.
- Iterate all eighteen header slots. Six header/footer types times three sections; the primary header is not the whole story.
- Null-check every carrier.
BackgroundImage,section.Imageandshape.Imageare null more often than not. - Return counts, not void. “Stamped nothing” and “worked” produce files that look identical otherwise.
- Check attachments separately. Workbook-level marking stops at that boundary.
- Pick the carrier by where the mark must survive - on paper, on screen, or inside a picture that gets copied elsewhere.
Conclusion
The honest answer to “does this workbook have a watermark” is a list, not a yes or no: four carriers, each with different visibility and different durability. The inventory pass costs one document load and tells you which ones are in play.
From there the choice follows the requirement. Mark the header when it has to print. Mark the background when it has to resist casual removal on screen. Mark the shape images when the pictures themselves are the asset. And check the attachments every time, because that is the one place a workbook-level watermark never reaches.