Skip to content

Commit 2592d23

Browse files
calumlockhart-bhpeterjamesnugent
authored andcommitted
Records an error if the excel file it is searching for doesn't exist
This will fix the problem for now, recommend that a more effective solution would be to also filter by file type to make sure that it is an excel file type being inserted into the function.
1 parent e19ef81 commit 2592d23

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

MidasCivil_Adapter/CRUD/Read/Results/ReadResults.cs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,28 +196,35 @@ private List<string> GetLoadcaseIDs(IResultRequest request)
196196

197197
private static string ExcelToCsv(string path)
198198
{
199-
string csvPath = GetCSVFile(path);
200-
if (!(File.Exists(csvPath)))
199+
string csvPath = GetCSVFile(path); ;
200+
if (!(File.Exists(path)))
201201
{
202-
Application excel = new Application();
203-
Workbook xlsFile = excel.Workbooks.Open(path);
204-
Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)xlsFile.Sheets[1];
205-
206-
sheet.SaveAs(
207-
csvPath,
208-
Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV,
209-
Type.Missing,
210-
Type.Missing,
211-
Type.Missing,
212-
Type.Missing,
213-
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared,
214-
Type.Missing,
215-
Type.Missing,
216-
Type.Missing
217-
);
218-
219-
xlsFile.Close();
202+
Engine.Reflection.Compute.RecordError("MidasCivil_Toolkit detects no Excel file, make sure you have exported the results from Midas.");
203+
}
204+
else
205+
{
206+
if (!(File.Exists(csvPath)))
207+
{
208+
Application excel = new Application();
209+
Workbook xlsFile = excel.Workbooks.Open(path);
210+
Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)xlsFile.Sheets[1];
211+
212+
sheet.SaveAs(
213+
csvPath,
214+
Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV,
215+
Type.Missing,
216+
Type.Missing,
217+
Type.Missing,
218+
Type.Missing,
219+
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared,
220+
Type.Missing,
221+
Type.Missing,
222+
Type.Missing
223+
);
224+
225+
xlsFile.Close();
220226

227+
}
221228
}
222229

223230
return csvPath;

0 commit comments

Comments
 (0)