Regarding watermark text in footer of Excel is overlapping using Aspose Cells for Java API

Hi
We have a license with Aspose and the order id is 230926145941
The watermark is overlapping in Excel in the footer using Aspose Cells for Java API.
Uploaded the sample xls file.
xls.zip (27.9 KB)

You can see the watermark text “VIASAT PROPRIETARY - L3HARRIS’ RIGHTS DEFINED UNDER THE ADA AND IP/SDR LICENSE AGREEMENTS DATED 1/3/2023” is overlapping in the footer.

How to make the watermark text not overlap?

Thanks
Rama

Pasting the code used to watermark the excel file

private boolean watermarkTextExcelFile (File excelFile, String watermarkText, String fileSuffix, String outputDirectory) throws Exception {

	boolean watermarkedFile = false;

	String fileName = "";
	try {

		fileName = excelFile.getName();
		String filePath = excelFile.getPath();
		String fileExtension = ".xlsx";
		if (!fileName.endsWith(".xlsx")) {
			fileExtension = ".xls";
		}

		//to apply license
		com.aspose.cells.License license = new com.aspose.cells.License();
		license.setLicense("Aspose.Total.Java.lic");
		String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);

		// Load the Excel file
		Workbook workbook = new Workbook(filePath);

		//WorksheetCollection worksheets = workbook.getWorksheets();
		int worksheetCount = 100;
		for (int i = 0; i < worksheetCount; i++) {

			// Get the first default sheet
			Worksheet sheet = null;

			try {
				sheet = workbook.getWorksheets().get(i);
			}
			catch (Exception ex) {
				//	logger.error("watermarkTextExcelFile load sheet ex:" + ex.getMessage());
				errlog.error("watermarkTextExcelFile load sheet ex:" + ex.getMessage() + ": " + fileName);

			}

			if(sheet != null) {
				PageSetup pageSetup = sheet.getPageSetup();
				pageSetup.setFooter(2, watermarkText); // 2 represents the section where you want to add the watermark (Center section in the footer)
			
			}
			else {
				// no sheet
				break;
			}
		}

		// Save the watermarked Excel file
		String watermarkedFilePath = outputDirectory + fileSeparator + fileNameWithOutExt + fileSuffix + fileExtension;
		workbook.save(watermarkedFilePath);

		//	logger.debug("watermarkedFilePath: " + watermarkedFilePath);
		infolog.info("watermarkedFilePath: " + watermarkedFilePath);

		watermarkedFile = true;
	}
	catch (Exception ex) {
		//	logger.error("watermarkTextWordFile ex:", ex);
		errlog.error("watermarkTextExcelFile ex:" + ex + ":" + fileName);

	}

	return watermarkedFile;
}

@Rama_Menon,

I have reviewed your Excel file and found that in the first worksheet, the data table extends up to the 44th row, which does not provide enough space for the long footer text to be set. This causes the footer text to overlap the page contents. You can test this scenario in MS Excel manually and will also find that the footer text overlaps the page contents. Therefore, this is not an issue with Aspose.Cells for Java. I noticed that the footer margin is also set to “0.65”, which adds more distance from the bottom and causes the overlap with the original body contents. To address this issue, you should set the footer margin to a minimum value or “0” as a safer option. You can use the following line of code (in bold) in your code segment to resolve this issue.


if(sheet != null)
{
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setFooterMargin(0);
pageSetup.setFooter(2, watermarkText); // 2 represents the section where you want to add the watermark (Center section in the footer)

}

Hope, this helps a bit.