Water mark text is editable

Hi Team,


I used aspose API to add watermark to an excel file. The watermark text was added without any issues but that watermark text is editable. I am able to modify and delete the watermark text i applied “cognizant” in my case. I am pasting my source code below.

import java.io.FileInputStream;

import com.aspose.cells.Color;
import com.aspose.cells.MsoFillFormat;
import com.aspose.cells.MsoLineFormat;
import com.aspose.cells.MsoPresetTextEffect;
import com.aspose.cells.Shape;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class CreateExcelFileWithWaterMark {
public static void main(String[] args) throws Exception {
//FileInputStream fstream = new FileInputStream(“D:\demo\Input.xls”);
//Instantiate a new Workbook
Workbook workbook = new Workbook(“D:\demo\Input.xlsx”);
System.out.println(“GOT Workbook”);
int sheets = workbook.getWorksheets().getCount();
System.out.println(“Number of sheets—>”+sheets);
//Get the first default sheet
for(int count=0;count<sheets;count++){
Worksheet sheet = workbook.getWorksheets().get(count);
System.out.println(“GOT Worksheet”);
//Add Watermark
Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1,
“cognizant”, “Arial Black”, 50, false, true
, 18, 8, 1, 1, 130, 800);

//Get the fill format of the word art
MsoFillFormat wordArtFormat = wordart.getFillFormat();

//Set the color
wordArtFormat.setForeColor(Color.getRed());

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

//Make the line invisible
MsoLineFormat lineFormat = wordart.getLineFormat();
lineFormat.setVisible(false);
}

//Save the file
workbook.save(“d:\demo\Input_watermark.xlsx”);
System.out.println(“WorkBook saved”);
}

}

Please help me in this regard

Team,


When i tried to add watermark to an excel file of size 1.2 MB I am getting out of memory exception

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.cells.zamn.a(Unknown Source)
at com.aspose.cells.zaco.a(Unknown Source)
at com.aspose.cells.zacn.b(Unknown Source)
at com.aspose.cells.zadb.z(Unknown Source)
at com.aspose.cells.zadb.a(Unknown Source)
at com.aspose.cells.zada.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at com.word.CreateExcelFileWithWaterMark.main(CreateExcelFileWithWaterMark.java:18)

Hi Team,


Please find attached excel file which I am trying to watermark and I am getting below exception
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.aspose.cells.zamn.a(Unknown Source)
at com.aspose.cells.zaco.a(Unknown Source)
at com.aspose.cells.zacn.b(Unknown Source)
at com.aspose.cells.zadb.z(Unknown Source)
at com.aspose.cells.zadb.a(Unknown Source)
at com.aspose.cells.zada.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at com.word.CreateExcelFileWithWaterMark.main(CreateExcelFileWithWaterMark.java:18)

Hi Surabhi,


Thank you for contacting Aspose support.

Please use the Shape.setLockedProperty to lock different aspects of the shape. Please check the following piece of code and its resultant spreadsheet as attached.

Java
//Instantiate a new Workbook
Workbook workbook = new Workbook(“D:/Input_watermark.xlsx”);

int sheets = workbook.getWorksheets().getCount();
System.out.println(“Number of sheets—>”+sheets);

for(int count=0;count<sheets;count++)
{
Worksheet sheet = workbook.getWorksheets().get(count);
System.out.println(“GOT Worksheet”);
//Add Watermark
Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1,
“cognizant”, “Arial Black”, 50, false, true
, 18, 8, 1, 1, 130, 800);

//Get the fill format of the word art
MsoFillFormat wordArtFormat = wordart.getFillFormat();
//Set the color
wordArtFormat.setForeColor(Color.getRed());
//Set the transparency
wordArtFormat.setTransparency(0.9);
//Make the line invisible
MsoLineFormat lineFormat = wordart.getLineFormat();
lineFormat.setVisible(false);

//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);
}
//Save the file
workbook.save(“D:/output.xlsx”);

sbalumsc:
Hi Team,

Please find attached excel file which I am trying to watermark and I am getting below exception
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.aspose.cells.zamn.a(Unknown Source)
at com.aspose.cells.zaco.a(Unknown Source)
at com.aspose.cells.zacn.b(Unknown Source)
at com.aspose.cells.zadb.z(Unknown Source)
at com.aspose.cells.zadb.a(Unknown Source)
at com.aspose.cells.zada.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at com.word.CreateExcelFileWithWaterMark.main(CreateExcelFileWithWaterMark.java:18)


Hi Surabhi,

I have used the latest version of Aspose.Cells for Java 8.4.1.3 with Java heap size set as -Xms256M & -Xmx512M. I am afraid, I am unable to observe any exception while watermarking your sample file. Please check the attached resultant spreadsheet for your reference.

In order to further troubleshoot this scenario, I request you to please give a try to the latest version without modifying your existing Java heap settings. In case the problem persists with latest revision of Aspose.Cells for Java, please increase the Java heap size gradually to see what value can accommodate the provided spreadsheet in memory. Moreover, please note that Aspose.Cells APIs requires almost 10x memory to load the spreadsheet for further processing. In case the available block of memory is less than expected size, you will encounter such problem so it would be appropriate to provide enough memory to your application that can accommodate most samples.