Add watermark in Diagonal and with RED FONT into xlsx file

Hello. I’m trying to add watermark to each sheet of xls(x) file. Currently, my code does this, but alwais in black font and also in the center of the page. I want it to be red and from in diagonal from bottom to top.
What should i change in my code?
try {
Workbook wb = new Workbook(filePath);
Iterator it = wb.getWorksheets().iterator();
while(it.hasNext()) {
Worksheet sheet = (Worksheet) it.next();
Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, text, “Arial Red”, 50, false, true, 18, 8, 1, 1, 130, 800);
FillFormat wordArtFormat = wordart.getFill();
wordArtFormat.setOneColorGradient(Color.getRed(), 0.2, GradientStyleType.DIAGONAL_UP, 2);
wordArtFormat.setTransparency(0.9);
LineFormat lineFormat = wordart.getLine();
lineFormat.setWeight(0.0);
}
wb.save(outputFilePath);
return true;
} catch (Exception e) {
return false;
}

@rsebastiany,

You may set the rotation angle to set it to diagonal style. Moreover, there is no font with name “Arial Red”. Please try the following sample code for your task. Please refer to it and then you may update it accordingly.
e.g.
Sample code:

        // Instantiate a new Workbook
        Workbook workbook = new Workbook();

        // Get the first default sheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        // Add Watermark
        com.aspose.cells.Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, "CONFIDENTIAL",
                "Arial", 60, false, true,24,8, 3, 4, 120, 700);

        //Set rotation angle
        wordart.setRotationAngle(-45);

        // Get the fill format of the word art
        FillFormat wordArtFormat = wordart.getFill();

        // Set the color
         wordArtFormat.getSolidFill().setColor(com.aspose.cells.Color.getRed());

        // Set the transparency
        wordArtFormat.setTransparency(0.9);

        // Make the line invisible
        LineFormat lineFormat = wordart.getLine();
        lineFormat.setWeight(0.0);

        // Save the file
        workbook.save("f:\\files\\WordArtToWorksheet_out1.xlsx");

Hope, this helps a bit.

@Amjad_Sahi

It has helped. I have just changed a few things, but it is working as expected now. Thank you!

@rsebastiany,

Good to know that the updated code segment works for your needs. Feel free to write us back if you have further queries or comments.