SpreadsheetLoadOptionsloadOptions=newSpreadsheetLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\spreadsheet.xlsx"
Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions);SpreadsheetContentcontent=watermarker.getContent(SpreadsheetContent.class);for(SpreadsheetWorksheetworksheet:content.getWorksheets()){for(SpreadsheetHeaderFooterheaderFooter:worksheet.getHeadersFooters()){System.out.println(headerFooter.getHeaderFooterType());for(SpreadsheetHeaderFooterSectionsection:headerFooter.getSections()){System.out.println(section.getSectionType());if(section.getImage()!=null){System.out.println(section.getImage().getWidth());System.out.println(section.getImage().getHeight());System.out.println(section.getImage().getBytes().length);}System.out.println(section.getScript());}}}watermarker.close();
Clearing a particular header and footer
You can also clear a particular header and 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"
Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions);SpreadsheetContentcontent=watermarker.getContent(SpreadsheetContent.class);SpreadsheetHeaderFooterSectionCollectionsections=content.getWorksheets().get_Item(0).getHeadersFooters().getByOfficeHeaderFooterType(OfficeHeaderFooterType.HeaderPrimary).getSections();for(SpreadsheetHeaderFooterSectionsection:sections){section.setScript(null);section.setImage(null);}watermarker.save("spreadsheet.xlsx");watermarker.close();
Clearing a particular section of header and footer
Using GroupDocs.Watermark, you can also clear a particular section of header and footer as shown in the sample code below.
SpreadsheetLoadOptionsloadOptions=newSpreadsheetLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\spreadsheet.xlsx"
Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions);SpreadsheetContentcontent=watermarker.getContent(SpreadsheetContent.class);SpreadsheetHeaderFooterSectionsection=content.getWorksheets().get_Item(0).getHeadersFooters().getByOfficeHeaderFooterType(OfficeHeaderFooterType.HeaderEven).getSections().getBySpreadsheetHeaderFooterSectionType(SpreadsheetHeaderFooterSectionType.Left);section.setImage(null);section.setScript(null);watermarker.save("spreadsheet.xlsx");watermarker.close();
Adding watermark to all images in header and footer
GroupDocs.Watermark enables you to add watermark to images inside any header and 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"
Watermarkerwatermarker=newWatermarker("spreadsheet.xlsx",loadOptions);// Initialize image or text watermark
TextWatermarkwatermark=newTextWatermark("Protected image",newFont("Arial",8));watermark.setHorizontalAlignment(HorizontalAlignment.Center);watermark.setVerticalAlignment(VerticalAlignment.Center);watermark.setRotateAngle(45);watermark.setSizingType(SizingType.ScaleToParentDimensions);watermark.setScaleFactor(1);SpreadsheetContentcontent=watermarker.getContent(SpreadsheetContent.class);for(SpreadsheetWorksheetworksheet:content.getWorksheets()){for(SpreadsheetHeaderFooterheaderFooter:worksheet.getHeadersFooters()){for(SpreadsheetHeaderFooterSectionsection:headerFooter.getSections()){if(section.getImage()!=null){// Add watermark to the image
section.getImage().add(watermark);}}}}watermarker.save("spreadsheet.xlsx");watermarker.close();
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.