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

Free Support Forum - aspose.com

ArgumentOutOfRangeException when converting excel

Hi ,

im using Aspose cells version 20.8.0.0
when converting the attached Excel that contains pictures the operation fails ,
all other excels i’ve tested are ok,

please download file from here : https://transferxl.com/08jrB1gx3t5mxT

here’s the code sample im using

using System.Drawing;
using System.Drawing.Imaging;
using Aspose.Cells;

        try
        {
            int jpegQuality = 90;

            if (_file.ToLower().EndsWith("xls") | _file.ToLower().EndsWith("xlsx") | _file.ToLower().EndsWith("csv") | _file.ToLower().EndsWith("mht"))
            {
                Aspose.Cells.Workbook work = new Aspose.Cells.Workbook(_file);

                foreach (Worksheet WSH1 in work.Worksheets)
                {
                    // Convert VML shapes.
                    foreach (Aspose.Cells.Drawing.Picture vmlShape in WSH1.Pictures)
                    {

                        try
                        {
                            Aspose.Cells.Rendering.ImageOrPrintOptions IOR1 = new Aspose.Cells.Rendering.ImageOrPrintOptions();
                            IOR1.SaveFormat = Aspose.Cells.SaveFormat.Auto;
                            byte[] originalBytes = vmlShape.Data;
                            Aspose.Cells.Drawing.ImageType imageType = vmlShape.ImageType;
                            if (vmlShape == null)
                                continue;

                            if (originalBytes == null)
                                continue;

                            try
                            {


                                using (System.Drawing.Image srcImage = vmlShape.ToImage(IOR1))
                                {

                                    using (Bitmap dstImage = new Bitmap(vmlShape.OriginalWidth, vmlShape.OriginalHeight))
                                    {
                                        using (Graphics gr = Graphics.FromImage(dstImage))
                                        {
                                            gr.DrawImage(srcImage, 0, 0, vmlShape.OriginalWidth, vmlShape.OriginalHeight);
                                        }

                                        ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
                                        ImageCodecInfo enc = null;
                                        System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Png;
                                        try
                                        {
                                            for (int i = 0; i < encoders.Length; i++)
                                            {
                                                if (encoders[i].FormatID == format.Guid)
                                                    enc = encoders[i];
                                            }

                                            throw new Exception("Cannot find a codec.");
                                        }
                                        catch { }

                              
                                        EncoderParameters encoderParams = new EncoderParameters();
                                        encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jpegQuality);

                                        MemoryStream dstStream = new MemoryStream();
                                        dstImage.Save(dstStream, enc, encoderParams);
                                        dstStream.Position = 0;
                                        vmlShape.Data = dstStream.ToArray();
                                    }
                                }
                            }
                            catch { }

                        }


                        catch (Exception)
                        {

                            throw;
                        }

                    }
                }
                work.Save(_file + ".Xlsx", Aspose.Cells.SaveFormat.Xlsx);
            }
        }
        catch { }

@Austin_Powers,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-47580 - ArgumentOutOfRangeException when converting excel

@Austin_Powers,

This is to inform you that we have fixed your issue now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

The issues you have found earlier (filed as CELLSNET-47580) have been fixed in Aspose.Cells for .NET v20.9. This message was posted using Bugs notification tool by Amjad_Sahi
You may also get the new version @ nuget repos. (https://www.nuget.org/packages/Aspose.Cells/20.9.0)