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

Free Support Forum - aspose.com

Missing overloads for SheetRender.ToImage() in .NET Standard

Hello,

We’re using the .NET Standard 2.0 variant of Aspose.Cells (v21.12.0).

It appears that some overloads for the SheetRender class are missing. According to the API documentation, there should be five overloads for the ToImage method:

ToImage(Int32) Render certain page to a Bitmap object.
ToImage(Int32, Stream) Render certain page to a stream.
ToImage(Int32, String) Render certain page to a file.
ToImage(Int32, Graphics, Single, Single) Render certain page to a Graphics
ToImage(Int32, Graphics, Single, Single, Single, Single) Render certain page to a Graphics

However, only the second and third methods are available (to stream and to file). The first, fourth and fifth methods are not available (to bitmap and to graphics).

It can be tested with the following code:

Workbook workbook = new Workbook("Test.xlsx");
Worksheet sheet = workbook.Worksheets[0];

ImageOrPrintOptions options = new ImageOrPrintOptions();
options.ImageType = ImageType.Png;

var sr = new SheetRender(sheet, options);

// Missing overload #1
Bitmap bitmap = sr.ToImage(0);

// Missing overload #2
Graphics g1 = Graphics.FromImage(new Bitmap(800, 600));
sr.ToImage(0, g1, 0, 0);

// Missing overload #3
Graphics g2 = Graphics.FromImage(new Bitmap(800, 600));
sr.ToImage(0, g2, 0, 0, 500, 400);

Is there something wrong in our code? Or can you add the missing methods?

@perfectxl,

Yes, not all overloads are supported in .NET Standard version of the library. These are supported in regular .NET framework versions only.

Thanks for the explanation. Is there a time frame when these method overloads will be supported? We need them to process the bitmap/graphic image generated by the SheetRender.

@perfectxl,

I have logged a ticket with an id “CELLSNETCORE-358” for your issue/requirements. We will investigate and look into details of it.

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

Hi @perfectxl
“System.Drawing.Bitmap” or “System.Drawing.Graphics” are not in standard library in .netstandard or .net6 ( They are implemented through system.drawing.common),so we removed these public methods about them in .netstandard and .net6, we will add a document to list the differences between .net and .netstandard version.
If you want to load the saved image to Bitmap or Graphics,please try the following code to implement the corresponding function:

       // Missing overload #1
        using (Stream stream = new MemoryStream())
        {
            //Bitmap bitmap = sr.ToImage(0);
            sr.ToImage(0, stream);
            Bitmap bitmap = new Bitmap(stream);
            bitmap.Save("01.bmp");
            // Missing overload #2
            //Graphics g1 = Graphics.FromImage(new Bitmap(800, 600));
            //sr.ToImage(0, g1, 0, 0);
            Graphics g1 = Graphics.FromImage(bitmap);
            // Missing overload #3
            //Graphics g2 = Graphics.FromImage(new Bitmap(800, 600));
            //sr.ToImage(0, g2, 0, 0, 500, 400);
            Graphics g2 = Graphics.FromImage(bitmap);
        }

Thank you. This is a sufficient workaround for us.

@perfectxl,

You are welcome.