Space between cell and text not taken into account when converting to image

Hi,

Using the following code:

    var book = new Workbook("test.xlsx");
    Worksheet sheet = book.Worksheets[0]; 
    var options = new ImageOrPrintOptions
    {
        ImageFormat = ImageFormat.Emf,
        OnePagePerSheet = true

    };
    SheetRender sr = new SheetRender(sheet, options);
    sr.ToImage(0, output);

asd.zip (20.3 KB)

Aspose produces an image where there is no space between the text and the border below.
Word adds some spacing as shown in the docx attached.

Cheers,

Hi,

Thanks for the template file, sample code and screenshot.

After an initial test, I observed the issue as you mentioned by using your sample code with your template file. I found that there is no space between the text and the border below when rendering Sheet to image file format. The space can be visible when taking the print preview of the sheet and zooming in a bit in MS Excel. But there is no space b/w the text and shaded area (g, y and p chars are touching the border below), see the screenshot for your reference:

I have logged a ticket with an id “CELLSNET-45451” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

Thank you.

Hi,

Our product team has evaluated your issue “CELLSNET-45451” in details.
Well, comparing the output with the print view in Microsoft Excel manually, we found there is only 1 pixel difference in vertical location. I am afraid, we cannot fix it for now. A workaround can be increasing the row height with 1 pixel, then the output image will be ok.

Thank you.

Hi,

Increasing the row height does indeed stop the text from being cut off.
The point is that this should not be needed as the text is not cut off when viewing in Excel or when copied as an image from Excel to Word (using ‘Copy as Picture’ -> ‘Show as printed’).

When automating the creation of images one assumes that what you see in Excel is what will be produced by Aspose and there is no way to tell whether the height will cause an issue with Aspose or not until after it was created.
I expect the Aspose output to be the same as the one produced by Office.

Cheers,

Hi,

Thanks for sharing further details.

I think your comments make sense. I have logged your concerns against your issue “CELLSNET-45451” into our database. Our concerned developer will evaluate it further.

Once we have any new information or update, we will share it with you.

Thank you.

Hi,

We have received the notification that this ticket has been raised to enterprise support and the fix was actually included 18.3.0.

In fact, we have tested the issue in 18.3.0 before raising the enterprise ticket and noticed the behaviour was indeed better but still had inconsistency under certain circumstances.

Using the test files provided in the intial post and the code below:

var workbook = new Workbook(@“test.xlsx”);
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Emf,
OnlyArea = false,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
OnePagePerSheet = true
};
var sheet = workbook.Worksheets[0];
sheet.PageSetup.LeftMargin =
sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;
SheetRender render = new SheetRender(sheet, options);
render.ToImage(0, @“out183test.emf”);

Paste the output emf file to word, and zoom in at 280%, you will notice the text has still been cut off.

I’ve attached a screenshot and again the test files for your reference. Could you please take a further look at this?Comparison.zip (24.1 KB)screenshot.png (44 KB)

@ServerSide527,

Thanks for the screenshot, template file, comparison document and output image.

You are right. Using Aspose.Cells for .NET v18.3, it works better but still the issue exists with the output image when we set the zoom level (after taking the image (using his sample code segment and file)) of the Word page to 280% manually in MS Excel. Even the issue can be seen when setting the zoom level starting from 280% up to 300% or so. I have recorded your findings against your issue “CELLSNET-45451” into our database. We will try to figure it out soon.

PS. Since you are availing Enterprise support service for the underlying issue, so you may continue/follow up in your Enterprise thread.

@ServerSide527,

First of all, there is a minor issue, when OnePagePerSheet is set to true and CenterHorizontally/CenterVertically is true in the source file, the margin are still being recalculated. So, there are still margins in the output image even all margins are set to zero. This is not right. We will fix this issue soon.
You may use the following sample code to avoid the issue now:
e.g
Sample code:

   sheet.PageSetup.CenterHorizontally = false;
    sheet.PageSetup.CenterVertically = false;

Secondly, Microsoft Excel option “Copy as picture->As shown when printed” seems ignore the zoom level in page setup (the original zoom is 72 in your source file). You may use the following code to set the zoom level to 100 to get image with same size as Microsoft Excel “Copy as picture->As shown when printed”:
i.e.,

 sheet.PageSetup.Zoom = 100;

So, the whole code will be like following:
e.g
Sample code:

    Workbook workbook = new Workbook(@"test.xlsx");

    var options = new ImageOrPrintOptions
    {
        ImageFormat = ImageFormat.Emf,
        OnlyArea = false,
        TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
        OnePagePerSheet = true
    };

    var sheet = workbook.Worksheets[0];

    //Microsoft Excel "Copy as picture->As shown when printed" seems ignore the zoom in page setup.
    sheet.PageSetup.Zoom = 100;

    sheet.PageSetup.LeftMargin =
        sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;

    //There is a minor issue, when OnePagePerSheet is set to true and CenterHorizontally/CenterVertically is true in the source file, the margin still being recalculated. 
    //So, there are still margins in the output image even all margins are set to zero. This is not right. We will fix it.
    //using the code to avoid the issue now.
    sheet.PageSetup.CenterHorizontally = false;
    sheet.PageSetup.CenterVertically = false;

    SheetRender sr = new SheetRender(sheet, options);
    sr.ToImage(0, @"out183test.emf");

The generated image should be ok. If you still find the issue, please highlight it.

@ServerSide527,

Please try our latest version/fix:

When OnePagePerSheet is set to true and CenterHorizontally/CenterVertically is also true in the source file, the margin are still recalculated. So, there are still margins in the output image even all margins are set to zero. This is not right. We will fix it. Please try using the following lines of code to avoid the issue for now:
sheet.PageSetup.CenterHorizontally = false;
sheet.PageSetup.CenterVertically = false;

Hope, this helps a bit.