Aspose cells java watermark depricated

I am referring the watermark code from your documentation


<pre class=“code-java” style=“padding: 0px; margin-top: 0px; margin-bottom: 0px; overflow: auto; font-family: “Courier New”, Courier, monospace; line-height: 1.3; color: rgb(51, 51, 51); font-size: 12.0333px; background-color: rgb(255, 255, 255);”>//Instantiate a new workbook.
//Open the existing excel file.
Workbook workbook = new Workbook(dataDir + “AsposeChart.xls”);

//Get the chart in the first worksheet.
com.aspose.cells.Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);

//Add a WordArt watermark (shape) to the chart’s plot area.
com.aspose.cells.Shape wordart = chart.getShapes().addTextEffectInChart(MsoPresetTextEffect.TEXT_EFFECT_2,
“CONFIDENTIAL”, “Arial Black”, 66, false, false, 1200, 500, 2000, 3000);

//Get the shape’s fill format.
com.aspose.cells.MsoFillFormat wordArtFormat = wordart.getFillFormat();

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

//Get the line format and make it invisible.
com.aspose.cells.MsoLineFormat lineFormat = wordart.getLineFormat();
lineFormat.setVisible(false);

//Save the excel file.
workbook.save(dataDir + “AsposeChartWatermarked_Out.xls”, SaveFormat.EXCEL_97_TO_2003);<pre class=“code-java” style=“padding: 0px; margin-top: 0px; margin-bottom: 0px; overflow: auto; font-family: “Courier New”, Courier, monospace; line-height: 1.3; color: rgb(51, 51, 51); font-size: 12.0333px; background-color: rgb(255, 255, 255);”>
<pre class=“code-java” style=“padding: 0px; margin-top: 0px; margin-bottom: 0px; overflow: auto; font-family: “Courier New”, Courier, monospace; line-height: 1.3; color: rgb(51, 51, 51); font-size: 12.0333px; background-color: rgb(255, 255, 255);”>
<pre class=“code-java” style=“padding: 0px; margin-top: 0px; margin-bottom: 0px; overflow: auto; font-family: “Courier New”, Courier, monospace; line-height: 1.3; color: rgb(51, 51, 51); font-size: 12.0333px; background-color: rgb(255, 255, 255);”>But the issue is I am getting deprecation warning for aspose cells 16.10.0<pre class=“code-java” style=“padding: 0px; margin-top: 0px; margin-bottom: 0px; overflow: auto; font-family: “Courier New”, Courier, monospace; line-height: 1.3; color: rgb(51, 51, 51); font-size: 12.0333px; background-color: rgb(255, 255, 255);”><pre style=“color: rgb(0, 0, 0); font-family: “Fira Code”; font-size: 9pt;”>MsoFillFormat wordArtFormat = wordart.getFillFormat();<pre style=“color: rgb(0, 0, 0); font-family: “Fira Code”; font-size: 9pt;”><pre style=“font-family: “Fira Code”; font-size: 9pt;”>MsoLineFormat lineFormat = wordart.getLineFormat();<pre style=“font-family: “Fira Code”; font-size: 9pt;”>please tell me if there is change in the documentation for newer apis<pre class=“code-java” style=“padding: 0px; margin-top: 0px; margin-bottom: 0px; overflow: auto; font-family: “Courier New”, Courier, monospace; line-height: 1.3; color: rgb(51, 51, 51); font-size: 12.0333px; background-color: rgb(255, 255, 255);”>

Hi there,


Thank you for contacting Aspose support.

Please try the following piece of code to watermark the charts with latest APIs. Please also provide the us the link where you have found the depreciated code segment so we could improve it as per most recent API set.

Java

//Instantiate a new workbook.
//Open the existing excel file.
Workbook workbook = new Workbook(dir + “sample.xlsx”);
//Get the chart in the first worksheet.
Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
//Add a WordArt watermark (shape) to the chart’s plot area.
com.aspose.cells.Shape wordart = chart.getShapes().addTextEffectInChart(MsoPresetTextEffect.TEXT_EFFECT_2,
“CONFIDENTIAL”, “Arial Black”, 66, false, false, 1200, 500, 2000, 3000);
//Get the shape’s fill format.
FillFormat wordArtFormat = wordart.getFill();
//Set the transparency.
wordArtFormat.setTransparency(0.9);
//Make the line invisible.
wordart.setHasLine(false);
//Save the excel file.
workbook.save(dir + “AsposeChartWatermarked_Out.xlsx”, SaveFormat.XLSX);

Hi again,


I have found this article (on adding watermarks to charts) in Aspose.Cells for Java documentation, however, the said article is not using any depreciated APIs. Please provide the link where you have found the code snippet from your original post so we could amend it for future reference.

Thanks for the reply

Here is a link to that documentation:

Add Word Art Watermark to Worksheet using Aspose.Cells|Documentation

and how to set color for FillFormat wordArtFormat object. like earlier
<pre class=“code-java” style=“padding: 0px; margin: 0px; text-align: left; overflow: auto; font-family: “Courier New”, Courier, monospace; line-height: 1.3; color: rgb(51, 51, 51); font-size: 12.0333px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);”>wordArtFormat.setForeColor(Color.getRed());

Hi there,


Thank you for the link. Please note, the shared article is from the competitor analysis (Aspose.Cells vs Apache POI). It is best that you should always refer to the articles under the Developer Guide as they are always up-to-date according to latest APIs. We will soon review the articles under the Plugins node of the documentation as well and update them where required.

Regarding the requirement to color the WordArt, please check the following piece of code.

Java

//Instantiate a new workbook.
//Open the existing excel file.
Workbook workbook = new Workbook(dir + “sample.xlsx”);
//Get the chart in the first worksheet.
Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);
//Add a WordArt watermark (shape) to the chart’s plot area.
com.aspose.cells.Shape wordart = chart.getShapes().addTextEffectInChart(MsoPresetTextEffect.TEXT_EFFECT_2,
“CONFIDENTIAL”, “Arial Black”, 66, false, false, 1200, 500, 2000, 3000);
//Get the shape’s fill format.
FillFormat wordArtFormat = wordart.getFill();
//Set color for FillFormat
wordArtFormat.setFillType(FillType.SOLID);
wordArtFormat.getSolidFill().setColor(Color.getRed());

//Set the transparency.
wordArtFormat.setTransparency(0.9);
//Make the line invisible.
wordart.setHasLine(false);
//Save the excel file.
workbook.save(dir + “AsposeChartWatermarked_Out.xlsx”, SaveFormat.XLSX);

After adding watermark to worksheet, when the user clicks on that watermark the user is able to edit the watermark, how can I stop this behavior?

Here is my code for adding watermark

private static void attachWaterMark(Workbook workbook, String name, String date, String ip) {
String message = String.format(“Downloaded for: %s on %s @ %s”, name, date, ip);

for (int i = 0; i < workbook.getWorksheets().getCount(); i++) {
Worksheet worksheet = workbook.getWorksheets().get(i);
Shape wordart = worksheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1,
message, “Open Sans”, 20, false, false ,
18, 8, 1, 1, 50, 800);
FillFormat wordArtFormat = wordart.getFill();
wordArtFormat.setFillType(FillType.SOLID);
wordArtFormat.getSolidFill().setColor(Color.getLightGray());
wordArtFormat.setTransparency(0.9);
wordart.setHasLine(false);
}
}

Hi there,


Please use the Shape.setLocked & setLockedProperty methods in order to lock certain aspects of the shape. Please check following piece of code for elaboration.

Java

//Instantiate a new workbook.
//Open the existing excel file.
Workbook workbook = new Workbook(dir + “sample.xlsx”);
//Access first worksheet.
Worksheet worksheet = workbook.getWorksheets().get(0);
//Add a WordArt watermark (shape) to the worksheet.
Shape wordart = worksheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1,
“Confidential”, “Open Sans”, 20, false, false ,
18, 8, 1, 1, 50, 800);

//Lock Shape Aspects.
wordart.setLocked(true);
wordart.setLockedProperty(ShapeLockType.SELECTION, true);
wordart.setLockedProperty(ShapeLockType.SHAPE_TYPE, true);
wordart.setLockedProperty(ShapeLockType.MOVE, true);
wordart.setLockedProperty(ShapeLockType.RESIZE, true);
wordart.setLockedProperty(ShapeLockType.TEXT, true);

//Get the shape’s fill format.
FillFormat wordArtFormat = wordart.getFill();
//Set color for FillFormat
wordArtFormat.setFillType(FillType.SOLID);
wordArtFormat.getSolidFill().setColor(Color.getRed());
//Set the transparency.
wordArtFormat.setTransparency(0.9);
//Make the line invisible.
wordart.setHasLine(false);
//Save the excel file.
workbook.save(dir + “output.xlsx”, SaveFormat.XLSX);

Hey there,


Sorry I am new in this, I need to delete the watermark from excel workbook in java.

if you know to resolve this, can you help me please

thanks in advance

This is my code for to add the WaterMark:

try {
Workbook wb = new Workbook();

//Access first worksheet.
Worksheet worksheet = wb.getWorksheets().get(0);
//Add a WordArt watermark (shape) to the worksheet.
Shape wordart = worksheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1,
“CONFIDENTIAL”, “Arial Black”, 50, false, true, 18, 8, 1, 1, 130, 800);

//Lock Shape Aspects.
wordart.setLocked(true);
wordart.setLockedProperty(ShapeLockType.SELECTION, true);
wordart.setLockedProperty(ShapeLockType.SHAPE_TYPE, true);
wordart.setLockedProperty(ShapeLockType.MOVE, true);
wordart.setLockedProperty(ShapeLockType.RESIZE, true);
wordart.setLockedProperty(ShapeLockType.TEXT, true);

//Get the shape’s fill format.
FillFormat wordArtFormat = wordart.getFill();
//Set color for FillFormat
wordArtFormat.setFillType(FillType.SOLID);
wordArtFormat.getSolidFill().setColor(Color.getRed());
//Set the transparency.
wordArtFormat.setTransparency(0.9);
//Make the line invisible.
wordart.setHasLine(false);
wb.save(“C:\Users\German\Documents\PDF_PRUEBA.xls”);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

So I need to remove this watermark after

Hi German,


Thank you for contacting Aspose support.

First of all, we humbly request you to always create new threads with appropriate problem description and summary in order to keep the tracking of inquiries easy and efficient. That said, if you wish to remove a particular shape after creating it, it is best that you should name the shapes. At the time of removing a particular shape, you can simply iterate through the shape’s collection and remove a particular shape. Please check the following piece of code demonstrating the said approach.

Java

Workbook wb = new Workbook();
//Access first worksheet.
Worksheet worksheet = wb.getWorksheets().get(0);
//Add a WordArt watermark (shape) to the worksheet.
Shape wordart = worksheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1,
“CONFIDENTIAL”, “Arial Black”, 50, false, true, 18, 8, 1, 1, 130, 800);

//Name watermark
wordart.setName(“watermark”);
//Lock Shape Aspects.
wordart.setLocked(true);
wordart.setLockedProperty(ShapeLockType.SELECTION, true);
wordart.setLockedProperty(ShapeLockType.SHAPE_TYPE, true);
wordart.setLockedProperty(ShapeLockType.MOVE, true);
wordart.setLockedProperty(ShapeLockType.RESIZE, true);
wordart.setLockedProperty(ShapeLockType.TEXT, true);

//Get the shape’s fill format.
FillFormat wordArtFormat = wordart.getFill();
//Set color for FillFormat
wordArtFormat.setFillType(FillType.SOLID);
wordArtFormat.getSolidFill().setColor(Color.getRed());
//Set the transparency.
wordArtFormat.setTransparency(0.9);
//Make the line invisible.
wordart.setHasLine(false);
wb.save(dir + “PDF_PRUEBA.xls”);

//Removing watermark
wb = new Workbook(dir + “PDF_PRUEBA.xls”);
worksheet = wb.getWorksheets().get(0);
//Get the shape collection
ShapeCollection shapes = worksheet.getShapes();
//Iterate over the collection
for(int i = 0; i < shapes.getCount(); i++)
{
Shape shape = shapes.get(i);
String name = shape.getName();
//Identify the shape to be removed
if(name.equals(“watermark”))
{
System.out.println("Shape found at index " + i);
//Remove the shape
shapes.remove(shape);
System.out.println(“Shape “+ name +” has been removed”);
}
}
wb.save(dir + “final.xls”);

Hi again,


Adding more to my previous response, in case you have received a spreadsheet, and you are not aware if and how the shapes have been named then you can opt the following approach to delete the watermark.

Java

Workbook wb = new Workbook(dir + “PDF_PRUEBA.xls”);
Worksheet worksheet = wb.getWorksheets().get(0);
//Get the shape collection
ShapeCollection shapes = worksheet.getShapes();
//Iterate over the collection
for(int i = 0; i < shapes.getCount(); i++)
{
Shape shape = shapes.get(i);
String text = shape.getTextEffect().getText();
//Identify the shape to be removed
if(!text.isEmpty() && text.equals(“CONFIDENTIAL”))
{
System.out.println("Shape found at index " + i);
//Remove the shape
shapes.remove(shape);
}
}
wb.save(dir + “final.xls”);
Hey all,

I am using aspose.words for to add the watermark into document, but I need to delete this watermark. I search in all side but I don't find nothing

If you know about this, Can you help me please?

Thanks in advance :)

This is my code java:

public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Document doc = new Document("C:\\Users\\German\\Documents\\memorando-general.docx");
insertWatermarkText(doc, "CONFIDENTIAL");
doc.save("C:\\Users\\German\\Documents\\memorando-general-OUT.docx");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Inserts a watermark into a document.
*
* @param doc
* The input document.
* @param watermarkText
* Text of the watermark.
*/
private static void insertWatermarkText(Document doc, String watermarkText) throws Exception {
// Create a watermark shape. This will be a WordArt shape.
// You are free to try other shape types as watermarks.
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
// Set up the text of the watermark.
watermark.getTextPath().setText(watermarkText);
watermark.getTextPath().setFontFamily("Arial Black");
watermark.setWidth(500);
watermark.setHeight(100);
// Text will be directed from the bottom-left to the top-right corner.
watermark.setRotation(-40);
// Remove the following two lines if you need a solid black text.
watermark.getFill().setColor(Color.red); // Try LightGray to get more Word-style watermark
watermark.setStrokeColor(Color.GRAY); // Try LightGray to get more Word-style watermark
// Place the watermark in the page center.
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setVerticalAlignment(VerticalAlignment.CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.appendChild(watermark);
// Insert the watermark into all headers of each document section.
for (Section sect : doc.getSections()) {
// There could be up to three different headers in each section, since we want
// the watermark to appear on all pages, insert into all headers.
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
}
}
private static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, int headerType) throws Exception {
HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);
if (header == null) {
// There is no header of the specified type in the current section, create it.
header = new HeaderFooter(sect.getDocument(), headerType);
sect.getHeadersFooters().add(header);
}
// Insert a clone of the watermark into the header.
header.appendChild(watermarkPara.deepClone(true));
}
private static void RemoveWatermark(Document doc)
{
//what do I add here?
}

Hi German Gonzalez,


Well, you have posted your query/issue in the wrong forum. Please see/follow up your other thread (in Aspose.Words forum) for reply:
<a rel=“nofollow” href="

Thank you.

Hi,

By following the given code I got the desired output, when the watermark is rendered on the excel file, I am not able to click on the cell where the watermark exist.

for (int i = 0; i < workbook.getWorksheets().getCount(); i++) {
Worksheet worksheet = workbook.getWorksheets().get(i);
Shape wordart = worksheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1,
message, “Open Sans”, 11, false, false ,
a, 8, b, 1, 25, 700);

//Lock Shape Aspects.
wordart.setLocked(true);
wordart.setLockedProperty(ShapeLockType.SELECTION, true);
wordart.setLockedProperty(ShapeLockType.SHAPE_TYPE, true);
wordart.setLockedProperty(ShapeLockType.MOVE, true);
wordart.setLockedProperty(ShapeLockType.RESIZE, true);
wordart.setLockedProperty(ShapeLockType.TEXT, true);

FillFormat wordArtFormat = wordart.getFill();
wordArtFormat.setFillType(FillType.SOLID);
wordArtFormat.getSolidFill().setColor(Color.getLightGray());
wordArtFormat.setTransparency(0.55);
wordart.setHasLine(false);
}

Hi Vikram,


Good to know that the suggested code works for your needs. Feel free to write us back if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.

Hi,

The issue with above code is the the user can not able to select the cell where the watermark exits. I need a solution for so that the cell can be selected where the watermark exists.

Hi,


This is not directly possible. You may either lock/unlock word art shape but when you click on the watermark shape, it won’t select the underlying cell(s) (behind) even the word art is unlocked. This is MS Excel behavior and nothing to do with Aspose.Cells APIs. To select the underlying cells, you got to select some cell above the wordart shape and then use the down arrow key, etc. to select those cells or values.

Thank you.