Watermarking not working properly in Excel file using Aspose Cells Java API

@amjad.sahi
Hi trying to watermark an excel file with one sheet .It watermarks,but the existing content is removed.

Was trying to use this code to watermark.


File inputDir = new File(fileDir);
String fname = filetoWatermark.getName();

		if (!inputDir.exists()) {
			System.out.println("Input directory is not valid");
		} else {

			workbook = new Workbook(fileDir + fname);

			workbook = new Workbook();

			Worksheet sheet = workbook.getWorksheets().get(0);
			
			System.out.println(sheet.getName());


			//	Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, "CONFIDENTIAL",
			//			"Arial Black", 50, false, true, 18, 8, 1, 1, 130, 800);

			Shape wordart = sheet.getShapes().addTextEffect(MsoPresetTextEffect.TEXT_EFFECT_1, watermarkText,
					"Arial Black", 50, false, true, 18, 8, 1, 1, 130, 800);

			wordart.setRotationAngle(330);
			FillFormat wordArtFormat = wordart.getFill();

			wordArtFormat.setOneColorGradient(com.aspose.cells.Color.getRed(), 0.2, GradientStyleType.DIAGONAL_UP, 2);

			wordArtFormat.setTransparency(0.9);

			// Make the line invisible
			///	LineFormat lineFormat = wordart.getLine();
			///	lineFormat.setWeight(0.0);
	//		PageSetup pageSetup = workbook.getWorksheets().get(0).getPageSetup();
	//		pageSetup.setFooter(2, "&\"Times New Roman,Bold\"&D-&T");
			String watermarkedFilePath = outputDirectory + File.separator + fname;

			// Save the file
			workbook.save(watermarkedFilePath); 
			watermarkedFile = true;

Uploading the sample xls files where it was tried.

files.zip (9.1 KB)

Thanks
Sabarish

@sabkan

From your code, it seems you make the workbook as empty one after instantiating it from the template file:

			workbook = new Workbook(fileDir + fname);

			workbook = new Workbook(); //is it the expected code here?

Maybe you should remove the second line of code and try again?

Thanks.good catch.
That was the issue.

@sabkan,

You are welcome. It’s good to know that your issue is resolved after commenting out or removing the unnecessary line of code from your code segment.