Unable to get rows count of an excel sheet using OfficeOpenXml.Core.ExcelPackage in c#

In my .net core web api project i want to get rows count. I installed the nuget package OfficeOpenXml.Core.ExcelPackage and using this code

using OfficeOpenXml.Core.ExcelPackage;


    public static async Task<List<ImportedFileData>> getFileData(IFormFile incomingFile) {
        var importedFileData = new List<ImportedFileData>();
        try
        {
            using (var stream = new MemoryStream())
            {
                await incomingFile.CopyToAsync(stream);

                using (var package = new ExcelPackage(stream))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
                    var rowCount = worksheet.WorksheetXml.XPathSelectElements("//d:sheetData/d:row", worksheet.NameSpaceManager).Count();
                    Console.WriteLine("===row count===");
                    Console.WriteLine(rowCount);

                }
            }

        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        return importedFileData;
  }

Now when i try to get rows count using this code, so this error is printing on console

Exception thrown: 'System.Xml.XmlException' in System.Private.Xml.dll
The ':' character, hexadecimal value 0x3A, cannot be included in a name.

This is my excel file

enter image description here

Is there any thing i am missing? How can i get rows count of the excel file?



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)