Hello.
I’m trying to do as i said in the title. Currently, my code adds the watermark into the file sheets, but it always comes in black and the text horizontal. How could i change my code to make the watermark red and also displayed in the left bottom -> right top diagonal?
My code currently is this:
Boolean aplicarMarcaDaguaXLS(String filePath, String outputFilePath, String text) {
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 the watermark in diagonal style. Moreover, “Arial Red” refers to font name but there is no such font with this name, either you use “Arial” or “Arial Black”. 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 Black", 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.