SpreadsheetLoadOptionsloadOptions=newSpreadsheetLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\spreadsheet.xlsx"using(Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions)){SpreadsheetContentcontent=watermarker.GetContent<SpreadsheetContent>();foreach(SpreadsheetWorksheetworksheetincontent.Worksheets){foreach(SpreadsheetHeaderFooterheaderFooterinworksheet.HeadersFooters){Console.WriteLine(headerFooter.HeaderFooterType);foreach(SpreadsheetHeaderFooterSectionsectioninheaderFooter.Sections){Console.WriteLine(section.SectionType);if(section.Image!=null){Console.WriteLine(section.Image.Width);Console.WriteLine(section.Image.Height);Console.WriteLine(section.Image.GetBytes().Length);}Console.WriteLine(section.Script);}}}}
Clearing a particular header or footer
You can also clear a particular header or footer using GroupDocs.Watermark as shown in the below code sample.
SpreadsheetLoadOptionsloadOptions=newSpreadsheetLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\spreadsheet.xlsx"using(Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions)){SpreadsheetContentcontent=watermarker.GetContent<SpreadsheetContent>();foreach(SpreadsheetHeaderFooterSectionsectionincontent.Worksheets[0].HeadersFooters[OfficeHeaderFooterType.HeaderPrimary].Sections){section.Script=null;section.Image=null;}watermarker.Save("spreadsheet.xlsx");}
Clearing a particular section of header or footer
Using GroupDocs.Watermark, you can also clear a particular section of header or footer as shown in the sample code below.
SpreadsheetLoadOptionsloadOptions=newSpreadsheetLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\spreadsheet.xlsx"using(Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions)){SpreadsheetContentcontent=watermarker.GetContent<SpreadsheetContent>();SpreadsheetHeaderFooterSectionsection=content.Worksheets[0].HeadersFooters[OfficeHeaderFooterType.HeaderEven].Sections[SpreadsheetHeaderFooterSectionType.Left];section.Image=null;section.Script=null;watermarker.Save("spreadsheet.xlsx");}
Adding watermark to all images in header and footer
GroupDocs.Watermark enables you to add watermark to images inside any header or footer. You can use below code sample to achieve this.
SpreadsheetLoadOptionsloadOptions=newSpreadsheetLoadOptions();// Specify an absolute or relative path to your document. Ex: @"C:\Docs\spreadsheet.xlsx"using(Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions)){// Initialize image or text watermarkTextWatermarkwatermark=newTextWatermark("Protected image",newFont("Arial",8));watermark.HorizontalAlignment=HorizontalAlignment.Center;watermark.VerticalAlignment=VerticalAlignment.Center;watermark.RotateAngle=45;watermark.SizingType=SizingType.ScaleToParentDimensions;watermark.ScaleFactor=1;SpreadsheetContentcontent=watermarker.GetContent<SpreadsheetContent>();foreach(SpreadsheetWorksheetworksheetincontent.Worksheets){foreach(SpreadsheetHeaderFooterheaderFooterinworksheet.HeadersFooters){foreach(SpreadsheetHeaderFooterSectionsectioninheaderFooter.Sections){if(section.Image!=null){// Add watermark to the imagesection.Image.Add(watermark);}}}}watermarker.Save("spreadsheet.xlsx");}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.