Search code examples
c#excel.net-coresyncfusion

Converting a .xlsx file to .csv using Syncfusion.XlsIO - Null reference exception


I have a file in blob storage that is in .xslx format and I am trying to convert it to .csv format using Syncfusion.XlsIO Nuget package.

I have tried the following:


        private async Task ConvertExcelToCsv()
        {
            var fileName = await _fileStore.GetContainerFileAsync(AppSettingsConstants.FileNames.Container, "myfile.xlsx");

            using (ExcelEngine excelEngine = new ExcelEngine())
            {
                var application = excelEngine.Excel;
                var workbook = application.Workbooks.Open(fileName.Name);
                var worksheet = workbook.Worksheets[1];
                worksheet.SaveAs("myfile.csv", ",");
            }
        }

When I debug, the fileName is retrieved successfully, but the application breaks on using (ExcelEngine excelEngine = new ExcelEngine()) with a NullReferenceException error.

Where am I going wrong here?


Solution

  • Thank you, it turned out I was missing a reference to System.Drawing nuget