While converting excel range into image. Getting some id and time stamp into it

Hi Team.

I am converting a range address into an image using a base64 string . However, whenever I retrieve the base64 string and save as png formate. I am facing issue.
In that image I’m getting some kind of id and Timestamp in that.
I am attaching problematic image as ActualResult.png and expected image as ExpectedResult.png .

Here is my code snippet

public async Task<dynamic> GetExcelRangeAsImage()
{
    string excelPath ="my excel file path";
	if (!string.IsNullOrEmpty(excelPath))
	{
		using (Aspose.Cells.Workbook wblob = new Aspose.Cells.Workbook(excelPath))
		{
			Aspose.Cells.Worksheet worksheet = wblob.Worksheets["Consolidado"];
			if (worksheet != null)
			{
				worksheet.PageSetup.PrintArea = "A6:T10";
				// Set all margins as 0
				worksheet.PageSetup.LeftMargin = 0;
				worksheet.PageSetup.RightMargin = 0;
				worksheet.PageSetup.TopMargin = 0;
				worksheet.PageSetup.BottomMargin = 0;
 
				ImageOrPrintOptions options = new ImageOrPrintOptions();
				options.OnePagePerSheet = true;
				options.ImageType = ImageType.Jpeg;
				options.HorizontalResolution = 200;
				options.VerticalResolution = 200;
				SheetRender sr = new SheetRender(worksheet, options);
				byte[] bytes = null;
				using (MemoryStream st = new MemoryStream())
				{
					sr.ToImage(0, st);
					bytes = st.ToArray();
				}
				    File.WriteAllBytes(@"C:\Users\abc\Desktop\Image.png", bytes);
			}
		}
	}
}

ImageIssue.zip (1.0 MB)

@Jayshiv,

Thanks for the template XLSX file.

After an initial testing, I was able to reproduce the issue as you mentioned by using your template XLSX file. I found that while converting Excel range into image, some id and time stamp are rendered unnecessarily into it.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-56191

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Jayshiv ,

The id and time stamp are the Header/Footer of the sheet. Please clear Header/Footer before rendering to image:

//Clear all header footer
worksheet.PageSetup.ClearHeaderFooter();
1 Like

Yes It’s working properly after removing header footer.
Thanks @peyton.xu and @amjad.sahi for your quick response.

@Jayshiv,

Thanks for your confirmation.

Good to know that by removing headers/footers in the Excel spreadsheet, as suggested, you were able to sort out your issue. Please feel free to write back to us if you have further queries or comments. We will be happy to assist you soon.

1 Like