Excel to image unnecessary whitespace

I am converting a sheet to an image like so:

static void TestAspose()
        {
            var book = new Aspose.Cells.Workbook(@"C:\Projects\WordTest\sample.xlsx");

            var sheet = book.Worksheets[0];
            sheet.PageSetup.LeftMargin = 0;
            sheet.PageSetup.RightMargin = 0;
            sheet.PageSetup.TopMargin = 0;
            sheet.PageSetup.BottomMargin = 0;
            var options = new Aspose.Cells.Rendering.ImageOrPrintOptions
            {
                OnePagePerSheet = true,
                ImageType = Aspose.Cells.Drawing.ImageType.Emf
            };

            var sr = new Aspose.Cells.Rendering.SheetRender(sheet, options);

            sr.ToImage(0, @"C:\Projects\WordTest\sample.emf");
            return;
}

The image that gets generated has whitespace to the right and bottom. How can I get rid of it during generation?

WordTest.7z (14.3 KB)

@RadAway,

Please try our latest version/fix: Aspose.Cells for .NET v21.8.5 (attached):
Aspose.Cells21.8.5 For .NetStandard20.Zip (5.6 MB)
Aspose.Cells21.8.5 For .Net2_AuthenticodeSigned.Zip (5.6 MB)
Aspose.Cells21.8.5 For .Net4.0.Zip (5.6 MB)

I have tested using your sample file and code it, works fine and as expected.

I tried 21.8.5 that you attached and I am still getting whitespace on the generated image.
sample.7z (6.3 KB)

Can you please share your result?
Also I am running on .NET Core 5.0

@RadAway,

Here you go, please find it attached.
sample.zip (11.6 KB)

I just tested on Windows8 in .NET2.0/4.0 common project. Could you test in common .NET project using .NET4.0 fix?

I am getting the same (incorrect) result using .NET Common 4.8 using the 21.8.5 .NET4 version that you supplied.
What do you suggest?

@RadAway,

It looks like you are using different display settings of OS on your machine. Aspose.Cells works flawlessly when using 100% display settings of OS. Please make sure you are using 100% display settings (screen resolution) and then try your scenario/case and let us know your results.

That did it. Wow, why would display scaling settings affect the way the product works? How can I work around this? I have no idea or control over what display scaling an end user might have on their machine.

@RadAway,

Aspose.Cells works perfectly in 100% display settings only when rendering images or PDF from Excel spreadsheets. To workaround it, you may simply add a line at the start of your program/code to ensure the code will use 100% display settings to get expected results:
CellsHelper.DPI = 96;

Let us know if you still find any issue.

I added the line that you suggested, and I am still having the same incorrect results with .NET Common and Core.

static void TestAspose()
        {
            CellsHelper.DPI = 96;
            var book = new Aspose.Cells.Workbook(@"C:\Projects\WordTest_NET\sample.xlsx");

            var sheet = book.Worksheets[0];
            sheet.PageSetup.LeftMargin = 0;
            sheet.PageSetup.RightMargin = 0;
            sheet.PageSetup.TopMargin = 0;
            sheet.PageSetup.BottomMargin = 0;
            var options = new Aspose.Cells.Rendering.ImageOrPrintOptions
            {
                OnePagePerSheet = true,
                ImageType = Aspose.Cells.Drawing.ImageType.Emf
            };

            var sr = new Aspose.Cells.Rendering.SheetRender(sheet, options);

            sr.ToImage(0, @"C:\Projects\WordTest_NET\sample.emf");
}

@RadAway,
We are looking into this issue and will share our feedback soon.

@RadAway,

By the way, while we evaluate your issue on our end, could you please give us the following details:

  • OS (with version details, edition and type)
  • Display (resolution) Settings or scaling (e.g. 100%, 125%, 150%, etc.)

Windows 10 Version 1909 (Build 18363.1734)
1920x1080
125% scaling

@RadAway,
We have tried number of options but could not reproduce this issue here. This issue is logged in our database for a detailed analysis. You will be notified here once any update is ready for sharing.

This issue is logged as:
CELLSNETCORE-226 - Unnecessary whitespace rendered during Excel to EMF conversion

I played around a bit with CellsHelper.DPI and it seems to have no visible effect.
By default when I run the program it’s already set to 96. I tried setting it to 76, and some other values, and it has absolutely no effect on the resulting image.

@RadAway,

Thanks for sharing your findings.

Please spare us little time to evaluate the issue in details. Hopefully, we will figure out your issue soon.

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

@RadAway

The issue is fixed v21.9.1.
Aspose.Cells21.9.1 For .Net2_AuthenticodeSigned.Zip (5.6 MB)
Aspose.Cells21.9.1 For .NetStandard20.Zip (5.6 MB)
Aspose.Cells21.9.1 For .Net4.0.Zip (5.6 MB)

Please let us know your feedback.

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