Free Support Forum - aspose.com

Creating a text watermark on every worksheet

Hi there,

I am trying to create a specific text (i.e “Confidential”) on every worksheet of a given excel.
I’ve read some posts on this matter but haven’t found a satisfying answer.
1. I do not want to create a background image (via setBackground)
2. If possible - I could use a word Art object (Shape?) to deliver. But in an answer to a post in 2009 you wrote that this is not supported - has this changed? If it has - in what version? and could you give me some sample code to use this.

Thanks,
Garkler

Hi Garkler,


Assuming that you are using the .NET version of Aspose.Cells API. Yes, we support adding WordArts to any worksheet. Please check the below link for an online demo on the topic,
Add WordArt Watermark to Worksheet

Hope it helped. Please feel free to write back.

Hey, thank you very much for your quick response, this could help me resolve my issue, but I don’t have a lot of manipulation over the shape objects.

The only fitting TextEffect is 9, which gives me some opacity but the color is purplish.
Is there a way to change the color of the wordart and increase the opacity.

Similarly, perhaps there is another solution for my problem - which is to create a watermark similar to that done in the aspose.words? i.e control over color etc.

Thanks!

Hi,

See the following code, this will add a watermark with red color.
Sample code:
// Add Watermark
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

Aspose.Cells.Drawing.Shape wordart = sheet.Shapes.AddTextEffect(MsoPresetTextEffect.TextEffect1,
“CONFIDENTIAL”, “Arial Black”, 50, false, true
, 18, 8, 1, 1, 130, 800);

MsoFillFormat wordArtFormat = wordart.FillFormat;
wordArtFormat.ForeColor = System.Drawing.Color.Red;
wordArtFormat.Transparency = 0.9;
MsoLineFormat lineFormat = wordart.LineFormat;
lineFormat.IsVisible = false;

workbook.Save(“e:\test2\redReportTest.xls”);

Thank you.

Hey amjad!

thanks again for all your help !!

I’ve added this code and it works wonderfully, after adding the wordart watermark to the worksheet, I go on to render the worksheet to an image and then add it to a new workbook using this code :

public Workbook InsertWorkbookAsImages(Workbook wrkExcel)

{

Workbook dstWrk = new Workbook();

//Loop over the worksheets collection

for (int index = 0; index < wrkExcel.Worksheets.Count; index++)

{

MemoryStream ms = new MemoryStream();

Worksheet worksheet = wrkExcel.Worksheets[index];

//Define ImageOrPrintOptions

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

//Specify the image format

imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Bmp;

//Only one page for the whole sheet would be rendered

imgOptions.OnePagePerSheet = false;

imgOptions.IsImageFitToPage = false;

//Render the sheet with respect to specified image/print options

SheetRender sr = new SheetRender(worksheet, imgOptions);

for (int j = 0; j < sr.PageCount; j++)

{

//sr.ToImage(0, ms);

//Render the image for the sheet

Bitmap bitmap = sr.ToImage(j);

bitmap.Save(ms, ImageFormat.Bmp);

int newindex = dstWrk.Worksheets.Add();

dstWrk.Worksheets[newindex].Pictures.Add(0, 0, ms);

}

}

}

Regarding this I have two questions :

  1. On rendering the image - the wordart object is not saved to the image, and what is created is just the data of the worksheet. Is there a property that i am missing to create the wordart as embedded ?

  2. Since the wordart is created on a worksheet, and yet I would like to break the worksheet into pages, is there a solution to create it for every page?

Thanks !

Garkler

Save Edit

Hi Garkler,


Using Aspose.Cells for .NET 5.3.3.1, I was unable to render WordArt to image [attached is an archive containing the input and output files]. So I have logged a Ticket under ID CELLSNET-27703 in our tracking system. Soon we will get back to you on this.
Thank you

My Sample Code C#

Workbook srcWrk = new Workbook(“c:\temp\AddingWordArt.xls”);


for (int index = 0; index < srcWrk.Worksheets.Count; index++)

{

Worksheet worksheet = srcWrk.Worksheets[index];


ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

imgOptions.OnePagePerSheet = false;

imgOptions.IsImageFitToPage = false;

SheetRender sr = new SheetRender(worksheet, imgOptions);


for (int j = 0; j < sr.PageCount; j++)

{

sr.ToTiff(“C:\temp\totiff.tiff”);

sr.ToImage(j,“C:\temp\toImage.tiff”);

}

}