Free Support Forum - aspose.com

Issue in water marking at XLS and XLSX


#1

Dear Team

We have issue of different behavior in water marking on both xls and xlsx files-

Please find the source code of water marking at excel files-

com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(
inStream);

		com.aspose.cells.WorksheetCollection sheets = workbook
				.getWorksheets();

		for (int page_counter = 0; page_counter < sheets.getCount(); page_counter++) {
			com.aspose.cells.Worksheet sheet = workbook.getWorksheets()
					.get(page_counter);
			// Add a page break at cell Y30
			sheet.setPageBreakPreview(true);
			sheet.setPageBreakPreview(true);
			com.aspose.cells.ImageOrPrintOptions printoption = new com.aspose.cells.ImageOrPrintOptions();
			printoption
					.setPrintingPage(com.aspose.cells.PrintingPageType.DEFAULT);
			com.aspose.cells.SheetRender sr = new com.aspose.cells.SheetRender(
					sheet, printoption);

			com.aspose.cells.CellArea[] area = sheet
					.getPrintingPageBreaks(printoption);

			for (int pageBreakCounter = 0; pageBreakCounter < area.length; pageBreakCounter++) {
				int strow = area[pageBreakCounter].StartRow;
				int stcol = area[pageBreakCounter].StartColumn;

				int setRow = strow + 18;
				int setColumn = stcol;

				com.aspose.cells.Shape wordart = sheet
						.getShapes()
						.addTextEffect(
								com.aspose.cells.MsoPresetTextEffect.TEXT_EFFECT_1,
								watermarkText, "Arial", 50, false, true,
								setRow, 10, setColumn, 1, 50, 500);

				com.aspose.cells.FillFormat wordArtFormat = wordart
						.getFill();

				wordArtFormat.setOneColorGradient(
						com.aspose.cells.Color.getLightGray(), 0.2,
						com.aspose.cells.GradientStyleType.HORIZONTAL, 2);

				wordArtFormat.setTransparency(0.5);

				// Lock Shape Aspects
				wordart.setLocked(true);
				wordart.setLockedProperty(
						com.aspose.cells.ShapeLockType.SELECTION, true);
				wordart.setLockedProperty(
						com.aspose.cells.ShapeLockType.SHAPE_TYPE, true);
				wordart.setLockedProperty(
						com.aspose.cells.ShapeLockType.MOVE, true);
				wordart.setLockedProperty(
						com.aspose.cells.ShapeLockType.RESIZE, true);
				wordart.setLockedProperty(
						com.aspose.cells.ShapeLockType.TEXT, true);
				// wordart.setX(10);

				// wordart.setX(10);
				// Integer width =(area[pageBreakCounter].EndRow*25);
				// wordart.setY(width);

				wordart.setRotationAngle(-55);

				com.aspose.cells.LineFormat lineFormat = wordart.getLine();
				lineFormat.setWeight(0.0);

			}

		}

		workbook.save(path + fileName);

#2

Please find the attached images-

Capture_XLS.PNG (32.6 KB)
Capture_XLSX.PNG (39.0 KB)


#3

@praveen043,

Thanks for the code segment and screenshots.

I have tested your scenario/ case using your sample code (with a little adjustment) with a simple template file (attached), it works fine and same for both output files (XLS and XLSX (attached)). I am using Aspose.Cells for Java v18.11.x (latest fix/version):
e.g
Sample code:

com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook("f:\\files\\Bk_test1.xlsx");

						com.aspose.cells.WorksheetCollection sheets = workbook
								.getWorksheets();

						for (int page_counter = 0; page_counter < sheets.getCount(); page_counter++) {
							com.aspose.cells.Worksheet sheet = workbook.getWorksheets()
									.get(page_counter);
							// Add a page break at cell Y30
							sheet.setPageBreakPreview(true);
							sheet.setPageBreakPreview(true);
							com.aspose.cells.ImageOrPrintOptions printoption = new com.aspose.cells.ImageOrPrintOptions();
							printoption
									.setPrintingPage(com.aspose.cells.PrintingPageType.DEFAULT);
							com.aspose.cells.SheetRender sr = new com.aspose.cells.SheetRender(
									sheet, printoption);

							com.aspose.cells.CellArea[] area = sheet
									.getPrintingPageBreaks(printoption);

							for (int pageBreakCounter = 0; pageBreakCounter < area.length; pageBreakCounter++) {
								int strow = area[pageBreakCounter].StartRow;
								int stcol = area[pageBreakCounter].StartColumn;

								int setRow = strow + 18;
								int setColumn = stcol;
									
								String watermarkText = "test_kunalmalani@samil.motherson.com";
								com.aspose.cells.Shape wordart = sheet
										.getShapes()
										.addTextEffect(
												com.aspose.cells.MsoPresetTextEffect.TEXT_EFFECT_1,
												watermarkText , "Arial", 50, false, true,
												setRow, 10, setColumn, 1, 50, 500);

								com.aspose.cells.FillFormat wordArtFormat = wordart
										.getFill();

								wordArtFormat.setOneColorGradient(
										com.aspose.cells.Color.getLightGray(), 0.2,
										com.aspose.cells.GradientStyleType.HORIZONTAL, 2);

								wordArtFormat.setTransparency(0.5);

								// Lock Shape Aspects
								wordart.setLocked(true);
								wordart.setLockedProperty(
										com.aspose.cells.ShapeLockType.SELECTION, true);
								wordart.setLockedProperty(
										com.aspose.cells.ShapeLockType.SHAPE_TYPE, true);
								wordart.setLockedProperty(
										com.aspose.cells.ShapeLockType.MOVE, true);
								wordart.setLockedProperty(
										com.aspose.cells.ShapeLockType.RESIZE, true);
								wordart.setLockedProperty(
										com.aspose.cells.ShapeLockType.TEXT, true);
								// wordart.setX(10);

								// wordart.setX(10);
								// Integer width =(area[pageBreakCounter].EndRow*25);
								// wordart.setY(width);

								wordart.setRotationAngle(-55);

								com.aspose.cells.LineFormat lineFormat = wordart.getLine();
								lineFormat.setWeight(0.0);

							}

						}

						workbook.save("f:\\files\\ou1.xls", SaveFormat.EXCEL_97_TO_2003);
						workbook.save("f:\\files\\out2.xlsx");

If you still find the issue with latest version/fix, kindly do provide complete runnable code with template files (input and output files) to reproduce the issue, we will check it soon.
files1.zip (39.9 KB)