Right now i am getting the data from excel and looping through the rows and based on condition i am processing the results like storing the result in an object for further processing.
The excel sheet is about 20 MB and the record count is closely to 7000 and i am using open xml to grab the data from excel file like as mentioned in below code.
string filePath = @"C:\weather-Data\DesignConditions_p.xlsx";
using FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using SpreadsheetDocument doc = SpreadsheetDocument.Open(fs, false);
WorkbookPart workbookPart = doc.WorkbookPart;
SharedStringTablePart sstpart = workbookPart.GetPartsOfType<SharedStringTablePart>().First();
SharedStringTable sst = sstpart.SharedStringTable;
Sheet firstSheet = workbookPart.Workbook.Descendants<Sheet>().First();
Worksheet sheet = ((WorksheetPart)workbookPart.GetPartById(firstSheet.Id)).Worksheet;
var rows = sheet.Descendants<Row>();
var weatherDataList = new List<WeatherStation>();
foreach (Row row in rows.Skip(5)) // it is taking almost more than 60 minutes to process and enter into the if loop below (country.Equals("USA"))
{
var weatherData = new WeatherStation();
string country = GetCellValue(filePath, "Annual", $"B{row.RowIndex.ToString()}");
if (country.Equals("USA"))
{
weatherData.CountryAbbreviation = country;
weatherData.StateAbbreviation = GetCellValue(filePath, "Annual", $"C{row.RowIndex.ToString()}");
weatherData.Number = GetCellValue(filePath, "Annual", $"E{row.RowIndex.ToString()}");
......
.......
}
}
Could any one please point me in the right direction to optimize the processing time while reading the data from excel , I am using .Net Core for this application
Thanks in advance.