Exception happened when converting to image

Hello team,

PQ4278.zip (16.6 KB)
I have converted PQ4278.xlsx to image using Aspose 17.8 however exception has happened at new Workbook(docStream).

This is my code

public static List ConvertExcelToImage(string docName, MemoryStream docStream, Dictionary<string, string> config)
{
try
{
var pageInfoList = new List();

            // Get config setting
            string docRootDir = config["DocumentsFilePath"];
            int dpi = int.Parse(config["ImageDPI"]);
            int thumbMaxH = int.Parse(config["ThumbnailMaxHeight"]);
            int thumbMaxW = int.Parse(config["ThumbnailMaxWidth"]);
            int maxPageNum = int.Parse(config["DocumentMaxPageNum"]);
            double readScale = double.Parse(config["ImageReadScale"]);
            int readDpi = Convert.ToInt32(dpi * readScale);

            // Create images directory
            string pageImgDir = docRootDir;
            if (!Directory.Exists(pageImgDir))
                Directory.CreateDirectory(pageImgDir);

            // Get the encoder of JPEG
            ImageCodecInfo jpgEncoder = GetCodecInfo();
            //EncoderParameters encParams = GetEncoderParams();

            EncoderParameters encParams = GetEncoderParams(int.Parse(config["ImageJpegQuality"]));

            // Instantiate the License class
            Aspose.Cells.License license = new Aspose.Cells.License();
            license.SetLicense("Aspose.Total.lic");

            // Convert .doc and .docx file to PDF.
            Workbook book = new Workbook(docStream);

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            //Specify the image format
            imgOptions.ImageFormat = ImageFormat.Png;
            imgOptions.VerticalResolution = readDpi;
            imgOptions.HorizontalResolution = readDpi;

            int totalPageCount = 0;
            foreach (Worksheet sheet in book.Worksheets)
            {
                //Render the sheet with respect to specified image/print options
                SheetRender sr = new SheetRender(sheet, imgOptions);

                for (int i = 0; i < sr.PageCount; i++)
                {
                    totalPageCount++;

                    if (totalPageCount <= maxPageNum)
                    {
                        //Render the image for the sheet
                        string imgFile = string.Format("{0}_{1:D8}.jpg",
                                Path.GetFileNameWithoutExtension(docName), totalPageCount);
                        string imgPath = Path.Combine(pageImgDir, imgFile);
                        using (Bitmap bitmap = sr.ToImage(i))
                        {
                            // Export image file
                            bitmap.SetResolution(dpi, dpi);
                            bitmap.Save(imgPath, jpgEncoder, encParams);

                            // Add  PageInfo List
                            pageInfoList.Add(imgPath);
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                if (totalPageCount >= maxPageNum) break;
            }

            // return results with flag of max page limit over
            return pageInfoList;
        }
        finally
        {
        }
    }

They are parameters

            // Get config setting
               Create Appseting key value for async function
               Dictionary<string, string> config = new Dictionary<string, string>();

               config.Add("DocumentsFilePath", outDir);
               config.Add("ImageDPI", "96");
               config.Add("ImageReadScale", "1.25");
               config.Add("ThumbnailMaxHeight", "252");
               config.Add("ThumbnailMaxWidth", "210");
               config.Add("ImageJpegQuality", "80");
               config.Add("DocumentMaxPageNum", "1000");

Thank you,
PFU DSOL2

@PFU.DSOL2

Thanks for using Aspose APIs.

We were able to observe this issue using the following code. We have logged the issue in our database for investigation and for a fix. Once, the issue is resolved or we have some other news for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-45635 - Input string was not in a correct format - Exception on opening Excel file

C#

Workbook wb = new Workbook("PQ4278.xlsx");

Exception:

System.FormatException was unhandled
  HResult=-2146233033
  Message=Input string was not in a correct format.
  Source=mscorlib
  StackTrace:
       at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
       at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
       at System.Int32.Parse(String s, IFormatProvider provider)
       at     . (  ​   ,       )
       at     . (  ​   )
       at     . (  ​   , FillFormat  )
       at     . (  ​   , TextOptions  , Hashtable  , Boolean  )
       at     . (  ​   , FontSetting  , Hashtable  )
       at     . (TextParagraph  )
       at     . ()
       at     .  (  ​   ,       )
       at     . (  ​   , Int32  , Boolean  )
       at     .  (  ​   ,       )
       at     . (  ​   , Int32  , Boolean  )
       at     . (Boolean  )
       at     . (      , String  , String  , Boolean  )
       at     . (      , String  )
       at     .  ()
       at     . ()
       at     . (Workbook  , LoadOptions  )
       at Aspose.Cells.Workbook. (Stream  , LoadOptions  , Boolean  )
       at Aspose.Cells.Workbook. (String  , LoadOptions  )
       at Aspose.Cells.Workbook..ctor(String file)
       at CellsNet.Program.f1() in F:\Download\Misc\Aspose\NetProjects\AsposeSol\CellsNet\Program.cs:line 51
       at CellsNet.Program.Main(String[] args) in F:\Download\Misc\Aspose\NetProjects\AsposeSol\CellsNet\Program.cs:line 32
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

@PFU.DSOL2

This is to inform you that we have fixed your issue CELLSNET-45635 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

@PFU.DSOL2

Please download and try the following fix and let us know your feedback.

Exception has gone. Thank you.

@PFU.DSOL2

Thanks for your feedback and using Aspose.Cells.

It is good to know that your exception issue is resolved with the latest fix. Let us know if you encounter any other issue, we will be glad to look into it and help you further.

The issues you have found earlier (filed as CELLSNET-45635) have been fixed in Aspose.Cells for .NET 17.9.