HydrologicEngineeringCenter / ExcelToCWMS

1 stars 2 forks source link

Allow for parsing the input xlsx sheet when open by user #13

Closed Tich1212 closed 3 years ago

Tich1212 commented 3 years ago

System.IO.IOException: 'The process cannot access the file 'C:\Users\q0hecemt\source\repos\ExcelToCWMS\ExcelToCWMSTests\bin\Debug\input.xlsx' because it is being used by another process.'

This exception was originally thrown at this call stack: [External Code] ExcelToCWMS.ClosedXML.GetDataTable(string) in ClosedXML.cs ExcelToCWMS.ProcessDataTable.GetTimeSeriesFromExcel(string, string, System.DateTime, System.DateTime) in ProcessDataTable.cs ExcelToCWMS.Tests.ProcessDataTableTests.GetTimeSeriesFromExcelTest() in ProcessDataTableTests.cs

Tich1212 commented 3 years ago

For now I am just catching the exception, providing a message, and exiting.

catch (Exception e) {
                Console.WriteLine(e.Message +"\n");
                Console.WriteLine("An issue occurred reading the xlsx file, \n" +
                    "Please save and close the file then try again");
                Console.WriteLine("Press ENTER to exit.........");
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                while (keyInfo.Key != ConsoleKey.Enter)
                    keyInfo = Console.ReadKey();
                System.Environment.Exit(0);
                return rval; //Making compiler happy 
}
Tich1212 commented 3 years ago

Instead of an exit, maybe we could have the user hit enter to try and read it again.

Tich1212 commented 3 years ago

Addressed with Pull Request #15

How: If the given excel fil is open we make a copy of the excel file in the user's temp directory and read that one instead