@@ -21,6 +21,8 @@ Namespace ExcelOpsTests.Engines
2121
2222#Disable Warning CA1716 ' Bezeichner dürfen nicht mit Schlüsselwörtern übereinstimmen
2323 Protected MustOverride Function _CreateInstance(file As String , mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean , passwordForOpening As String , disableCalculationEngine As Boolean ) As T
24+ Protected MustOverride Function _CreateInstance(data As Byte (), passwordForOpening As String , disableCalculationEngine As Boolean ) As T
25+ Protected MustOverride Function _CreateInstance(data As System.IO.Stream, passwordForOpening As String , disableCalculationEngine As Boolean ) As T
2426#Enable Warning CA1716 ' Bezeichner dürfen nicht mit Schlüsselwörtern übereinstimmen
2527
2628 ''' <summary>
@@ -63,6 +65,88 @@ Namespace ExcelOpsTests.Engines
6365 Return Me .CreateInstance(file, mode, [readOnly], passwordForOpening, False )
6466 End Function
6567
68+ ''' <summary>
69+ ''' Create a new excel engine instance (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on)
70+ ''' </summary>
71+ ''' <param name="data"></param>
72+ ''' <param name="passwordForOpening"></param>
73+ ''' <returns></returns>
74+ Protected Function CreateInstance(data As Byte (), passwordForOpening As String ) As T
75+ Return Me .CreateInstance(data, passwordForOpening, False )
76+ End Function
77+
78+ ''' <summary>
79+ ''' Create a new excel engine instance (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on)
80+ ''' </summary>
81+ ''' <param name="data"></param>
82+ ''' <param name="passwordForOpening"></param>
83+ ''' <param name="disableCalculationEngine"></param>
84+ ''' <returns></returns>
85+ Protected Function CreateInstance(data As Byte (), passwordForOpening As String , disableCalculationEngine As Boolean ) As T
86+ Try
87+ Return _CreateInstance(data, passwordForOpening, disableCalculationEngine)
88+ Catch ex As Exception
89+ If ex.GetType() Is GetType (PlatformNotSupportedException) Then
90+ Throw
91+ ElseIf ex.GetType() Is GetType (CompuMaster.ComInterop.ComApplicationNotAvailableException) Then
92+ Throw
93+ Else
94+ Dim InnerEx As Exception = ex.InnerException
95+ Do While InnerEx IsNot Nothing
96+ If InnerEx.GetType() Is GetType (PlatformNotSupportedException) Then
97+ Throw InnerEx
98+ ElseIf InnerEx.GetType() Is GetType (CompuMaster.ComInterop.ComApplicationNotAvailableException) Then
99+ Throw InnerEx
100+ Else
101+ InnerEx = InnerEx.InnerException
102+ End If
103+ Loop
104+ End If
105+ Throw
106+ End Try
107+ End Function
108+
109+ ''' <summary>
110+ ''' Create a new excel engine instance (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on)
111+ ''' </summary>
112+ ''' <param name="data"></param>
113+ ''' <param name="passwordForOpening"></param>
114+ ''' <returns></returns>
115+ Protected Function CreateInstance(data As System.IO.Stream, passwordForOpening As String ) As T
116+ Return Me .CreateInstance(data, passwordForOpening, False )
117+ End Function
118+
119+ ''' <summary>
120+ ''' Create a new excel engine instance (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on)
121+ ''' </summary>
122+ ''' <param name="data"></param>
123+ ''' <param name="passwordForOpening"></param>
124+ ''' <param name="disableCalculationEngine"></param>
125+ ''' <returns></returns>
126+ Protected Function CreateInstance(data As System.IO.Stream, passwordForOpening As String , disableCalculationEngine As Boolean ) As T
127+ Try
128+ Return _CreateInstance(data, passwordForOpening, disableCalculationEngine)
129+ Catch ex As Exception
130+ If ex.GetType() Is GetType (PlatformNotSupportedException) Then
131+ Throw
132+ ElseIf ex.GetType() Is GetType (CompuMaster.ComInterop.ComApplicationNotAvailableException) Then
133+ Throw
134+ Else
135+ Dim InnerEx As Exception = ex.InnerException
136+ Do While InnerEx IsNot Nothing
137+ If InnerEx.GetType() Is GetType (PlatformNotSupportedException) Then
138+ Throw InnerEx
139+ ElseIf InnerEx.GetType() Is GetType (CompuMaster.ComInterop.ComApplicationNotAvailableException) Then
140+ Throw InnerEx
141+ Else
142+ InnerEx = InnerEx.InnerException
143+ End If
144+ Loop
145+ End If
146+ Throw
147+ End Try
148+ End Function
149+
66150 ''' <summary>
67151 ''' Create a new excel engine instance (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on)
68152 ''' </summary>
@@ -202,6 +286,40 @@ Namespace ExcelOpsTests.Engines
202286
203287 End Sub
204288
289+ <Test> Public Sub LoadFileFromByteArray()
290+ Dim Wb As T
291+ 'Testfile without password
292+ Dim TestFile As String = TestEnvironment.FullPathOfExistingTestFile( "test_data" , "ExcelOpsGrund01.xlsx" )
293+ Dim Data As Byte () = System.IO.File.ReadAllBytes(TestFile)
294+ If GetType (T) Is GetType (MsExcelDataOperations) Then
295+ 'known to fail because no support for reading files from in-memory
296+ Assert.Throws( Of NotSupportedException)( Sub ()
297+ Me .CreateInstance(Data, "" )
298+ End Sub )
299+ Else
300+ Wb = Me .CreateInstance(Data, "" )
301+ Assert.AreEqual( "Grunddaten" , Wb.SheetNames( 0 ))
302+ Assert.That(Wb.ReadOnly, [Is].True)
303+ End If
304+ End Sub
305+
306+ <Test> Public Sub LoadFileFromStream()
307+ Dim Wb As T
308+ 'Testfile without password
309+ Dim TestFile As String = TestEnvironment.FullPathOfExistingTestFile( "test_data" , "ExcelOpsGrund01.xlsx" )
310+ Dim Data As System.IO.Stream = New System.IO.FileStream(TestFile, System.IO.FileMode.Open)
311+ If GetType (T) Is GetType (MsExcelDataOperations) Then
312+ 'known to fail because no support for reading files from in-memory
313+ Assert.Throws( Of NotSupportedException)( Sub ()
314+ Me .CreateInstance(Data, "" )
315+ End Sub )
316+ Else
317+ Wb = Me .CreateInstance(Data, "" )
318+ Assert.AreEqual( "Grunddaten" , Wb.SheetNames( 0 ))
319+ Assert.That(Wb.ReadOnly, [Is].True)
320+ End If
321+ End Sub
322+
205323 <Test> Public Sub PasswordForOpening()
206324 Dim Wb As T
207325 'Testfile without password
@@ -518,23 +636,23 @@ Namespace ExcelOpsTests.Engines
518636 End If
519637
520638 eppeo.SelectSheet( 0 )
521- eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Grunddaten.0.xlsx" ), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)
522- System.Console.WriteLine( "OUT: " & eppeo.FilePath)
523- Assert.That(eppeo.SelectedSheetName, [Is].EqualTo( "Grunddaten" ))
524-
525- eppeo = Me .CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True , Nothing )
526- eppeo.SelectSheet( 1 )
527- eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Ausgewählt.1.xlsx" ), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)
528- System.Console.WriteLine( "OUT: " & eppeo.FilePath)
529- Assert.That(eppeo.SelectedSheetName, [Is].EqualTo( "Ausgewählt" ))
530-
531- eppeo = Me .CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True , Nothing )
532- eppeo.SelectSheet( 2 )
533- eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Kostenplanung.2.xlsx" ), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)
534- System.Console.WriteLine( "OUT: " & eppeo.FilePath)
535- Assert.That(eppeo.SelectedSheetName, [Is].EqualTo( "Kostenplanung" ))
536-
537- eppeo.SelectSheet( "Grunddaten" )
639+ eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Grunddaten.0.xlsx" ), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)
640+ System.Console.WriteLine( "OUT: " & eppeo.FilePath)
641+ Assert.That(eppeo.SelectedSheetName, [Is].EqualTo( "Grunddaten" ))
642+
643+ eppeo = Me .CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True , Nothing )
644+ eppeo.SelectSheet( 1 )
645+ eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Ausgewählt.1.xlsx" ), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)
646+ System.Console.WriteLine( "OUT: " & eppeo.FilePath)
647+ Assert.That(eppeo.SelectedSheetName, [Is].EqualTo( "Ausgewählt" ))
648+
649+ eppeo = Me .CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True , Nothing )
650+ eppeo.SelectSheet( 2 )
651+ eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Kostenplanung.2.xlsx" ), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)
652+ System.Console.WriteLine( "OUT: " & eppeo.FilePath)
653+ Assert.That(eppeo.SelectedSheetName, [Is].EqualTo( "Kostenplanung" ))
654+
655+ eppeo.SelectSheet( "Grunddaten" )
538656 eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Grunddaten.xlsx" ), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)
539657 System.Console.WriteLine( "OUT: " & eppeo.FilePath)
540658 Assert.That(eppeo.SelectedSheetName, [Is].EqualTo( "Grunddaten" ))
0 commit comments