We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Differences in Excel Image Rendering between ExcelInterop and Aspose

@Peyton.Xu

I tried using the following code with the nuget package 21.7 and 21.8 and both DID NOT give any issue while using the “emfonly” property. If its due to the proprty emfonly i fail to understand why its working with historical aspose prod packages.

static void Main(string[] args)
{
	FileStream fs;

	fs = File.Open(@"C:\Temp\book1.xlsx", FileMode.Open);
	Workbook wb = new Workbook(fs);
	var sheet = wb.Worksheets["Rendering"];
	var range = sheet.Workbook.Worksheets.GetRangeByName("ImageRange");
	CreateImageMetafileFromRange(sheet,range);
}

private static void CreateImageMetafileFromRange(Worksheet sheet, Range range)
{
	var path = Path.Combine(@"C:\Temp\" + Guid.NewGuid() + "-Aspose.emf");            
	var pgSetup = sheet.PageSetup;
	pgSetup.PrintArea = range.Address;
	pgSetup.LeftMargin = 1;
	pgSetup.TopMargin = 1;
	pgSetup.RightMargin = 1;
	pgSetup.BottomMargin = 1;
	var options = new ImageOrPrintOptions
	{
		OnlyArea = true,
		//IsOptimized = true,
		ImageType = Aspose.Cells.Drawing.ImageType.Emf,  
		EmfType = System.Drawing.Imaging.EmfType.EmfOnly
	};
	SheetRender sr = new SheetRender(sheet, options);
	sr.ToImage(0, path);
}

Regarding the Property “OnlyArea” - Ticket - (CELLSNET-48983 Sheet to Emf leaves the border edges drawn improperly and coming out of the edges while using the OnlyArea property) - this is not working when we use just the property standalone without the property “OnePAgePerSheet” , refer below code.

private static void Main(string[] args)
{
	var asposeLic = new License();
	asposeLic.SetLicense("Aspose.Cells.NET.lic");
	var fs = File.Open(@"C:\Temp\book1.xlsx", FileMode.Open);
	Workbook wb = new Workbook(fs);
	var sheet = wb.Worksheets["Rendering"];
	var range = sheet.Workbook.Worksheets.GetRangeByName("ImageRange");
	CreateImageMetafileFromRange(range);
	fs.Close();
}

private static void CreateImageMetafileFromRange(Range imageRange)
{
	var path = Path.Combine(@"C:\Temp\", Guid.NewGuid() + ".emf");

	var worksheet = imageRange.Worksheet;
	var pgSetUp = worksheet.PageSetup;
	pgSetUp.PrintArea = imageRange.Address;

	// Set all margins as 0
	pgSetUp.LeftMargin = 0.04;
	pgSetUp.RightMargin = 0.04;
	pgSetUp.TopMargin = 0.04;
	pgSetUp.BottomMargin = 0.04;

	// Set OnePagePerSheet, OnlyArea option as true
	var options = new ImageOrPrintOptions
	{
		ImageType = Aspose.Cells.Drawing.ImageType.Emf,
		OnlyArea = true,
		EmfType = EmfType.EmfOnly,
		IsOptimized = true
	};

	var sr = new SheetRender(worksheet, options);
	sr.ToImage(0, path);	
}

book1.zip (8.8 KB)
0605e74d-3caf-4edb-bb13-92f19df052c9.zip (6.3 KB)

@hi.shobhit82

In the old versions(e.g. 21.7, 21.8), The API SheetRender.ToImage doesn’t respond to the option ImageOrPrintOptions.EmfType, it always generates Emf image with EmfPlusDual Type.

@Peyton.Xu

Ok. Please go through this as well. Thanks.

@hi.shobhit82

The issue(CELLSNET-49049 Font is distorted while converting sheet to Emf image with EmfOnly option) is fixed in v21.8.6:
Aspose.Cells21.8.6 For .Net2_AuthenticodeSigned.Zip (5.6 MB)
Aspose.Cells21.8.6 For .Net4.0.Zip (5.6 MB)
Aspose.Cells21.8.6 For .NetStandard20.Zip (5.6 MB)

The option OnlyArea is designed to only output content area without margins(Margin set in PageSetup). However, if there is no margin, the border on the image edge will come out of the edges as you watched. So, also with the option OnePagePerSheet set, the margins(Margin set in PageSetup) will be output, and the borders on the image edge will be OK.

Now, only the image file size issue(CELLSNET-48532 Issue with the size of the image by Aspose.Cells while comparing it with the ExcelInterop image) can’t be totally fixed. If we have any update, we will let you know.

The issues you have found earlier (filed as CELLSNET-48609,CELLSNET-48983,CELLSNET-49049) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao

@Peyton.Xu

There is another issue with this fix - when we use the EMFOnly property , the font are not properly vertically aligned. i.e. the font which is vertically aligned in the center appears to be almost touching the upper border of the cell. Whereas if we do not use the EMFOnly the font is OK , but still not aligned accurately in the center as per the excel sheet , there are still minor shifting of the font on the upper side.

Please note that this is a big concern for us and is critical because we generate a regulatory report which is further submitted to the regulators, and if the fonts and data not aligned as intended its a big issue.

Please find attached a sample.

book1.zip (10.0 KB)
Using-EmfOnly-Property.zip (3.8 KB)
Without-Using-EmfOnly-Property.zip (5.3 KB)

Code Snippet to re-produce the issue


private static void Main(string[] args)
{
	var asposeLic = new License();
	asposeLic.SetLicense("Aspose.Cells.NET.lic");

	var fs = File.Open(@"C:\Temp\book1.xlsx", FileMode.Open);

	Workbook wb = new Workbook(fs);
	var sheet = wb.Worksheets["Rendering"];
	var range = sheet.Workbook.Worksheets.GetRangeByName("ImageRangeWithIndex");

	CreateImageMetafileFromRange(range);
	fs.Close();
}

private static void CreateImageMetafileFromRange(Range imageRange)
{
	var path = Path.Combine(@"C:\Temp\", Guid.NewGuid() + ".emf");

	var worksheet = imageRange.Worksheet;
	var pgSetUp = worksheet.PageSetup;
	pgSetUp.PrintArea = imageRange.Address;

	// Set all margins as 0
	pgSetUp.LeftMargin = 0.05;
	pgSetUp.RightMargin = 0.05;
	pgSetUp.TopMargin = 0.05;
	pgSetUp.BottomMargin = 0.05;

	// Set OnePagePerSheet, OnlyArea option as true
	var options = new ImageOrPrintOptions
	{
		ImageType = Aspose.Cells.Drawing.ImageType.Emf,
		//EmfType = EmfType.EmfOnly, //Uncomment this line to make the cell value a BIT centerly aligned in the final image output
		OnePagePerSheet = true,
		OnlyArea = true,
		IsOptimized = true
	};

	var sr = new SheetRender(worksheet, options);
	sr.ToImage(0, path);
}

Thanks & Regards
Shobhit

@hi.shobhit82,
We have tried the latest release but could not observe this issue. You may please ensure that you are using the latest version. If still issue is there, share the environment details with us. Also it is recommended that as this thread is getting too long, its better to create new thread for the issue (if any).
Without-Using-EmfOnly-Property_2.emf.zip (5.6 KB)
Using-EmfOnly-Property_2.emf.zip (3.4 KB)

@hi.shobhit82

I can see the text is not well center aligned in vertically in both your shared Emf images(with or without using EmfOnly option). It seems that it becomes a litte more worse while using EmfOnly option.
I can the font “Credit Suisse Type Light” is used in both source xlsx file and generated Emf images. We need the font file of “Credit Suisse Type Light” to improve the alignment.

However, if it is not possible to share the font file, please change the font of your source xlsx file to other fonts. e.g. “Calibri”, “Arial”, to make text be better aligned in the result Emf image.

@Peyton.Xu

I am trying to check with our compliance team to share the fonts. Will let you know about it.

Meanwhile I tried changing the font to Calibri and try , I still feel the fonts are not exactly aligned in the center even with the default fonts but better than the company font.

The code remains the same as i used previously and I am using the 21.9 prod nuget package of Aspose.Cells.

UsingEMFOnly.JPG (106.5 KB) -zoom’ed snap so you can see the alignment shifted upwards.
book1.zip (10.0 KB)

Thanks
Shobhit

@hi.shobhit82,

We will wait for the fonts, you may take your time.

Thanks for the template file and sample image. We will evaluate it and get back to you soon.

@hi.shobhit82

Because the row height is small, a litte offset(e.g. 1 pixel) in vertical alignment will cause big difference when you zoom in the result Emf image.
We consider it as as acceptable result.