Skip to content

Commit

Permalink
fixed issue with spreadsheet uo
Browse files Browse the repository at this point in the history
  • Loading branch information
DanWBR committed Apr 10, 2024
1 parent acba2aa commit 9c56db2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions DWSIM.UnitOperations/UnitOperations/Spreadsheet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,8 @@ Namespace UnitOperations
Loop While ParName <> ""
ParamsLoaded = True

'=============== clean up Excel stuff ================================================================
mybook.Close(saveChanges:=True)
xcl.Quit()
'xcl.Dispose()

MassBal = 100 * (Wout - Win) / (Win)
If Math.Abs(MassBal) > 0.001 Then
Expand Down Expand Up @@ -739,15 +737,29 @@ Namespace UnitOperations
End If

End Sub

Public Sub ReadExcelParams()

'read input and output parameters from associated Excel table

If Not ParamsLoaded Then

If FileIsEmbedded Then

If Not FlowSheet.FileDatabaseProvider.CheckIfExists(EmbeddedFileName) Then Exit Sub

Else

If Not File.Exists(Filename) Then Exit Sub

End If

Dim excelType As Type = Nothing

If Not Calculator.IsRunningOnMono Then excelType = Type.GetTypeFromProgID("Excel.Application")

If Not Calculator.IsRunningOnMono And Not excelType Is Nothing Then

Dim excelProxy As Object = Activator.CreateInstance(excelType)

Using xcl As New Excel.Application(Nothing, excelProxy)
Expand All @@ -767,15 +779,17 @@ Namespace UnitOperations
Dim tmpfile As String = ""

If FileIsEmbedded Then
If Not FlowSheet.FileDatabaseProvider.CheckIfExists(EmbeddedFileName) Then Exit Sub

tmpfile = Path.ChangeExtension(SharedClasses.Utility.GetTempFileName(), Path.GetExtension(EmbeddedFileName))
FlowSheet.FileDatabaseProvider.ExportFile(EmbeddedFileName, tmpfile)
'Load Excel definition file
mybook = xcl.Workbooks.Open(tmpfile, True, True)

Else
If Not File.Exists(Filename) Then Exit Sub

'Load Excel definition file
mybook = xcl.Workbooks.Open(Filename, True, True)

End If

Dim mysheetIn As Excel.Worksheet = mybook.Sheets("Input")
Expand Down Expand Up @@ -827,10 +841,9 @@ Namespace UnitOperations
End If
Loop While ParName <> ""

mybook.Close(False)
mybook.Close(saveChanges:=False)

xcl.Quit()
xcl.Dispose()

ParamsLoaded = True

Expand Down

0 comments on commit 9c56db2

Please sign in to comment.