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

Free Support Forum - aspose.com

Convert string to numeric value using ConvertStringToNumericValue in .NET

We are upgrading to Aspose.Cells for .NET 21.8. For some reason the ConvertStringtoNumeric() function is throwing the following error. I’ve tried looking everywhere and cannot find a solution. Note this code works fine in Aspose.Cells.21.4.0.

Object reference not set to an instance of an object.
at Aspose.Cells.Cells.ConvertStringToNumericValue()


    var fileName = report.CreateFileName();
    var templateName = report.DownloadFile(@"xxx\Purchase Freq v1.xlsx", fileName);
    var workbook = new Workbook(templateName);

    var dtItems = report.ResultDataSet.Tables[0];
    var xlSheet = workbook.Worksheets["Data"];

    //setup, pulling info from end workbook template
    var printRow = 1;
    var styleRange = xlSheet.Cells.CreateRange(printRow, 0, 1, 7);

    var basketColEndRow = 3;

    foreach (DataRow dRow in dtItems.Rows)
        var itemNbr = dRow[0].ToString();
        var itemDesc = dRow[1].ToString();
        var itemWeek = dRow[2].ToString();
        var itemPath = dRow[3].ToString();

            var scWorkbook = new Workbook();

        if (itemPath.Contains(".zip"))
            string zipPath = itemPath;

            var fileNamexx = new Guid().ToString();
            using (var file = System.IO.File.OpenRead(zipPath))
            using (var zip = new System.IO.Compression.ZipArchive(file, System.IO.Compression.ZipArchiveMode.Read))
            using (var stream = zip.Entries.First().Open())
            using (var fileStream = new System.IO.FileStream(fileNamexx,System.IO.FileMode.Create))
                scWorkbook = new Workbook(fileStream);
            scWorkbook = new Workbook(itemPath);

            //tender sheet data
            var scSheet = scWorkbook.Worksheets["Purchase Freq"];
            if (scSheet != null)
                var endRow = scSheet.Cells.MaxRow;

                for(int irow = 1 ; irow <= endRow ; irow++)
                    //only import the "Repurchase Within..." stuff..
                    if (scSheet.Cells[irow, 0].Value != null && scSheet.Cells[irow, 0].Value.ToString().Contains("Repurchase Within"))
                        var targetRange = xlSheet.Cells.CreateRange(printRow, 0, 1, 7);

                        xlSheet.Cells[printRow, 0].Value = itemNbr;
                        xlSheet.Cells[printRow, 1].Value = itemDesc;
                        xlSheet.Cells[printRow, 2].Value = itemWeek;

                        for (int icol = 0; icol <= basketColEndRow; icol++)
                            xlSheet.Cells[printRow,icol + 3].Value = scSheet.Cells[irow, icol].Value;


    if (printRow == 1)
        report.ReportOptions.ErrorMessage = "No data returned";
        return string.Empty;



    return templateName;

You may share your template Excel file and also the updated runnable code that can be executed here without any missing reference for our analysis. Once the required information is received, we will reproduce this issue here and share our feedback accordingly.

Thanks for the quick reply. Sorry I got the versions mixed up. We were going from a very old version to 21.4. We found out there is a bug with this method in that version. So we just tried with 21.8 and it works with no issues.



Good to know that the latest version fixes your issue. Feel free to contact us any time if you have further queries or issue, we will be happy to assist you soon.