Search code examples
c#excelaspose

How to repeat watermark in excel created


In my webform project, I generate excel file with Aspose in C#, and I add watermark to it with this code:

 Aspose.Cells.Worksheet sheet = workbook.Worksheets[0];
            Aspose.Cells.Drawing.MsoPresetTextEffect effect = Aspose.Cells.Drawing.MsoPresetTextEffect.TextEffect2;
            Aspose.Cells.Drawing.Shape wordart = sheet.Shapes.AddTextEffect(effect,"WATERMARKTEXT", "Arial Black", 47, false, false, 1, 1, 1, 1, 50, 300);
            Aspose.Cells.Drawing.MsoFillFormat wordArtFormat = wordart.FillFormat;
            wordArtFormat.ForeColor = System.Drawing.Color.Red;
            wordArtFormat.Transparency = 0.8;
            Aspose.Cells.Drawing.MsoLineFormat lineFormat = wordart.LineFormat;
            lineFormat.IsVisible = false;
            return workbook;

But I want to repeat this watermark horizontally and vertically in each sheet. how can I do this?


Solution

  • I use this method for setting background instead of watermark :

      private static Aspose.Cells.Workbook AddExcelWaterMark(Aspose.Cells.Workbook workbook)
        {
            try
            {
                string path = HttpContext.Current.Server.MapPath("~/images/ExcelBackGround.png");
                byte[] bgBuffer = File.ReadAllBytes(path);
    
                foreach (Aspose.Cells.Worksheet sheet in workbook.Worksheets)
                    sheet.SetBackground(bgBuffer);
    
                return workbook;
            }
            catch
            {
                return workbook;
            }
        }