Working with spreadsheet document attachments
Leave feedback
On this page
Excel worksheets can embed file attachments (OLE objects). They are available through SpreadsheetContent.worksheets[i].attachments. Each attachment exposes alternative_text, is_link, source_full_name, content, and get_document_info(), and the document it contains can be opened in its own Watermarker.
Open each attachment’s bytes in its own Watermarker, add a watermark, and write the result back:
importiofromgroupdocs.watermarkimportWatermarkerfromgroupdocs.watermark.watermarksimportTextWatermark,Font,Colorfromgroupdocs.watermark.options.spreadsheetimportSpreadsheetLoadOptionsdefwatermark_attached_documents():withWatermarker("./spreadsheet.xlsx",SpreadsheetLoadOptions())aswatermarker:content=watermarker.get_content()forworksheetincontent.worksheets:forattachmentinworksheet.attachments:withWatermarker(io.BytesIO(attachment.content))asinner:wm=TextWatermark("CONFIDENTIAL",Font("Arial",19.0))wm.foreground_color=Color.redinner.add(wm)buffer=io.BytesIO()inner.save(buffer)# write the watermarked attachment bytes back as neededwatermarker.save("./output.xlsx")if__name__=="__main__":watermark_attached_documents()
spreadsheet.xlsx is the sample file used in this example. Click here to download it.