I want to use C++ language to add watermarks (including text and pictures) in Excel. I can’t find relevant sample codes in the reference documents( docs.cells ). I’m not particularly familiar with other languages (such as c#/java). Who can tell me where I can find relevant codes? or related API, thanks
Aspose.Cells for C++ supports to add wordart watermarks to Excel spreadsheets. Please check the API reference page. You are right, the relevant document with example code is missing in the docs. We will add relevant document soon. In the meantime, you may refer to C#.NET document on how to add watermarks to Excel sheet for your reference.
@dage123
Please refer to the code below.
void AddTextWarterMark()
{
// Instantiate a new Workbook
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook();
// Get the first worksheet
intrusive_ptr<IWorksheetCollection> wsc = wb->GetIWorksheets();
intrusive_ptr<IWorksheet> ws = wsc->GetObjectByIndex(0);
// 1: Add Text Watermark
intrusive_ptr<IShape> wordart = ws->GetIShapes()->AddITextEffect(MsoPresetTextEffect_TextEffect1,
new String("CONFIDENTIAL"), new String("Arial Black"), 50, false, true
, 18, 8, 1, 1, 130, 800);
// Get the fill format of the word art
intrusive_ptr<IFillFormat> wordArtFormat = wordart->GetIFillFormat();
// Set the transparency
wordArtFormat->SetTransparency( 0.9);
// Save the file
wb->Save(new String("Watermark_Text.xlsx"));
}
void AddPictureWarterMark()
{
// Instantiate a new Workbook
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook();
// Get the first worksheet
intrusive_ptr<IWorksheetCollection> wsc = wb->GetIWorksheets();
intrusive_ptr<IWorksheet> ws = wsc->GetObjectByIndex(0);
// Set a picture as the Watermark.
ws->SetBackgroundImage(File::ReadAllBytes(new String("D:\\logo.png")));
// Save the file
wb->Save(new String("Watermark_Pict.xlsx"));
}
Hope helps a bit!
It solved my problem perfectly, thank you very much