From 49982e0643320f49da3d14880f5e660b037aecf7 Mon Sep 17 00:00:00 2001 From: Jochen Wezel Date: Thu, 18 Dec 2025 14:02:01 +0100 Subject: [PATCH 1/7] introduced Options class for #11 * introduced Options class * marked old API as obsolete --- .../AssemblyInfo.vb | 8 + ...pplusFreeExcelDataOperations.SharedCode.vb | 23 +- .../EpplusFreeExcelDataOperations.vb | 56 +++- ExcelOps-EpplusPolyform/AssemblyInfo.vb | 8 + ...sPolyformExcelDataOperations.SharedCode.vb | 25 +- .../EpplusPolyformExcelDataOperations.vb | 88 +++++- ExcelOps-FreeSpireXls/AssemblyInfo.vb | 9 + .../FreeSpireXlsDataOperations.SharedCode.vb | 19 +- .../FreeSpireXlsDataOperations.vb | 68 +++- ExcelOps-MicrosoftExcel/AssemblyInfo.vb | 3 + .../ComWrappers/MsExcelTools.vb | 5 +- .../ExcelOpsLowLevel/MsExcelDataOperations.vb | 127 +++++++- ExcelOps-SpireXls/AssemblyInfo.vb | 4 + .../SpireXlsDataOperations.SharedCode.vb | 19 +- ExcelOps-SpireXls/SpireXlsDataOperations.vb | 68 +++- .../MsVsEpplusTools.vb | 7 +- .../ExcelDataOperationsBase.vb | 295 ++++++++++++++---- .../ExcelDataOperationsOptions.vb | 133 ++++++++ .../ExcelEngineDefaultOptions.vb | 36 +++ .../FreeSpireXlsOpsTest.vb | 15 +- .../MsExcelCalcTestFreeSpireXls.vb | 2 +- .../SpecialFeature_SaveToHtml.vb | 6 +- .../ExcelOpsTests.Engines/SpireXlsOpsTest.vb | 16 +- .../MsExcelCalcTestSpireXls.vb | 2 +- .../SpecialFeature_SaveToHtml.vb | 6 +- .../CmDataXlsEpplusPolyformEditionTest.vb | 9 + .../EpplusFreeFixCalcsEditionOpsTest.vb | 12 +- .../EpplusPolyformEditionOpsTest.vb | 15 +- .../ExcelOpsTests.Engines/ExcelOpsTestBase.vb | 246 ++++++++------- .../ExcelOpsTests.Engines/MsExcelOpsTest.vb | 13 +- .../MsExcelAppReleaseTest.vb | 8 +- .../MsExcelCalcTestEpplusFree.vb | 2 +- .../MsExcelCalcTestEpplusPolyform.vb | 2 +- README.md | 8 +- TestAndDemoExcelOps/Program.cs | 8 +- 35 files changed, 1071 insertions(+), 300 deletions(-) create mode 100644 ExcelOps-EpplusFreeFixCalcsEdition/AssemblyInfo.vb create mode 100644 ExcelOps-EpplusPolyform/AssemblyInfo.vb create mode 100644 ExcelOps-FreeSpireXls/AssemblyInfo.vb create mode 100644 ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb create mode 100644 ExcelOps/ExcelOpsLowLevel/ExcelEngineDefaultOptions.vb diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/AssemblyInfo.vb b/ExcelOps-EpplusFreeFixCalcsEdition/AssemblyInfo.vb new file mode 100644 index 0000000..9ad65c4 --- /dev/null +++ b/ExcelOps-EpplusFreeFixCalcsEdition/AssemblyInfo.vb @@ -0,0 +1,8 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + + + + + \ No newline at end of file diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb index d2235cf..9956f60 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb @@ -927,18 +927,27 @@ Namespace ExcelOps End Sub ''' - ''' Is the Excel engine allowed to automatically/continuously calculate on every change or does the user has to manually force a recalculation (typically by pressing F9 key in MS Excel) + ''' If enabled, the calculation engine will do a full recalculation after every modification. + ''' If disabled, the calculation engine is not allowed to automatically/continuously calculate on every change and the user has to manually force a recalculation (typically by pressing F9 key in MS Excel). ''' ''' - Public Overrides Property AutoCalculationEnabled As Boolean + ''' Please note: this property is a workbook property (not an engine property!) + Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean Get - Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic) + If Me._WorkbookPackage IsNot Nothing Then + Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic) + Else + Return MyBase.AutoCalculationEnabledWorkbookSetting + End If End Get Set(value As Boolean) - If value Then - Me.Workbook.CalcMode = ExcelCalcMode.Automatic - Else - Me.Workbook.CalcMode = ExcelCalcMode.Manual + MyBase.AutoCalculationEnabledWorkbookSetting = value + If Me._WorkbookPackage IsNot Nothing Then + If value Then + Me.Workbook.CalcMode = ExcelCalcMode.Automatic + Else + Me.Workbook.CalcMode = ExcelCalcMode.Manual + End If End If End Set End Property diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb index efd881a..fadd6a7 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb @@ -19,9 +19,49 @@ Namespace ExcelOps Public Class EpplusFreeExcelDataOperations Inherits ExcelDataOperationsBase + Protected Overrides ReadOnly Property DefaultCalculationOptions As ExcelEngineDefaultOptions + Get + Return New ExcelEngineDefaultOptions(False, True) + End Get + End Property + + ''' + ''' Create or open a workbook (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on) + ''' + ''' Path to a file which shall be loaded or null if a new workbook shall be created + ''' Open an existing file or (re)create a new file + ''' File and engine options + ''' + ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. + ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. + ''' + Public Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(file, mode, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As Byte(), options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As System.IO.Stream, options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + ''' ''' Create or open a workbook ''' + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(file, mode, Not disableInitialCalculation, False, [readOnly], passwordForOpening) End Sub @@ -29,6 +69,8 @@ Namespace ExcelOps ''' ''' Create or open a workbook ''' + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, False, True, [readOnly], passwordForOpening) End Sub @@ -36,6 +78,8 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, False, True, passwordForOpening) End Sub @@ -43,6 +87,8 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, True, passwordForOpening) End Sub @@ -50,6 +96,8 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, False, True, passwordForOpening) End Sub @@ -57,6 +105,8 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, True, passwordForOpening) End Sub @@ -64,14 +114,16 @@ Namespace ExcelOps ''' ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' - Public Sub New() - Me.New(Nothing) + Friend Sub New() + MyBase.New(New ExcelDataOperationsOptions) End Sub ''' ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' ''' Pre-define encryption password on future save actions + + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(False, True, True, passwordForOpeningOnNextTime) End Sub diff --git a/ExcelOps-EpplusPolyform/AssemblyInfo.vb b/ExcelOps-EpplusPolyform/AssemblyInfo.vb new file mode 100644 index 0000000..9ad65c4 --- /dev/null +++ b/ExcelOps-EpplusPolyform/AssemblyInfo.vb @@ -0,0 +1,8 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + + + + + \ No newline at end of file diff --git a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb index e7fbc2c..07519cf 100644 --- a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb +++ b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb @@ -513,7 +513,7 @@ Namespace ExcelOps Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False 'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad - Me.Workbook.FullCalcOnLoad = FULL_CALC_ON_LOAD 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too + Me.Workbook.FullCalcOnLoad = Me.AutoCalculationOnLoad 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too Me.Workbook.Worksheets.Add("Sheet1") End Sub @@ -526,7 +526,7 @@ Namespace ExcelOps Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False 'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad - Me.Workbook.FullCalcOnLoad = FULL_CALC_ON_LOAD 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too + Me.Workbook.FullCalcOnLoad = Me.AutoCalculationOnLoad 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too End Sub Protected Overrides Sub LoadWorkbook(data As Byte()) @@ -545,7 +545,7 @@ Namespace ExcelOps Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False 'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad - Me.Workbook.FullCalcOnLoad = FULL_CALC_ON_LOAD 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too + Me.Workbook.FullCalcOnLoad = Me.AutoCalculationOnLoad 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too End Sub ''' @@ -930,15 +930,22 @@ Namespace ExcelOps ''' Is the Excel engine allowed to automatically/continuously calculate on every change or does the user has to manually force a recalculation (typically by pressing F9 key in MS Excel) ''' ''' - Public Overrides Property AutoCalculationEnabled As Boolean + Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean Get - Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic) + If Me._WorkbookPackage IsNot Nothing Then + Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic) + Else + Return MyBase.AutoCalculationEnabledWorkbookSetting + End If End Get Set(value As Boolean) - If value Then - Me.Workbook.CalcMode = ExcelCalcMode.Automatic - Else - Me.Workbook.CalcMode = ExcelCalcMode.Manual + MyBase.AutoCalculationEnabledWorkbookSetting = value + If Me._WorkbookPackage IsNot Nothing Then + If value Then + Me.Workbook.CalcMode = ExcelCalcMode.Automatic + Else + Me.Workbook.CalcMode = ExcelCalcMode.Manual + End If End If End Set End Property diff --git a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb index 2b2560f..037901f 100644 --- a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb +++ b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb @@ -22,6 +22,12 @@ Namespace ExcelOps Public Class EpplusPolyformExcelDataOperations Inherits ExcelDataOperationsBase + Protected Overrides ReadOnly Property DefaultCalculationOptions As ExcelEngineDefaultOptions + Get + Return New ExcelEngineDefaultOptions(True, False) + End Get + End Property + ''' ''' The license context for Epplus (see its polyform license) ''' @@ -42,9 +48,53 @@ Namespace ExcelOps End If End Sub + ''' + ''' Create or open a workbook (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on) + ''' + ''' Path to a file which shall be loaded or null if a new workbook shall be created + ''' Open an existing file or (re)create a new file + ''' File and engine options + ''' + ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. + ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. + ''' + Public Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(file, mode, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As Byte(), options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As System.IO.Stream, options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + ''' ''' Create or open a workbook ''' + + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(file, mode, Not disableInitialCalculation, disableCalculationEngine, [readOnly], passwordForOpening) + ValidateLicenseContext(Me) + End Sub + + ''' + ''' Create or open a workbook + ''' + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(file, mode, Not disableInitialCalculation, False, [readOnly], passwordForOpening) ValidateLicenseContext(Me) @@ -53,6 +103,8 @@ Namespace ExcelOps ''' ''' Create or open a workbook ''' + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, True, False, [readOnly], passwordForOpening) ValidateLicenseContext(Me) @@ -61,6 +113,8 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) ValidateLicenseContext(Me) @@ -69,6 +123,18 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) + ValidateLicenseContext(Me) + End Sub + + ''' + ''' Open a workbook + ''' + + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) ValidateLicenseContext(Me) @@ -77,6 +143,8 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) ValidateLicenseContext(Me) @@ -85,6 +153,18 @@ Namespace ExcelOps ''' ''' Open a workbook ''' + + + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) + ValidateLicenseContext(Me) + End Sub + + ''' + ''' Open a workbook + ''' + + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) ValidateLicenseContext(Me) @@ -93,14 +173,16 @@ Namespace ExcelOps ''' ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' - Public Sub New() - Me.New(Nothing) + Friend Sub New() + MyBase.New(New ExcelDataOperationsOptions) End Sub ''' ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' ''' Pre-define encryption password on future save actions + + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(False, True, True, passwordForOpeningOnNextTime) ValidateLicenseContext(Me) @@ -112,8 +194,6 @@ Namespace ExcelOps End Get End Property - Private Const FULL_CALC_ON_LOAD As Boolean = True - Private _WorkbookPackage As OfficeOpenXml.ExcelPackage Public ReadOnly Property WorkbookPackage As OfficeOpenXml.ExcelPackage Get diff --git a/ExcelOps-FreeSpireXls/AssemblyInfo.vb b/ExcelOps-FreeSpireXls/AssemblyInfo.vb new file mode 100644 index 0000000..433f6fe --- /dev/null +++ b/ExcelOps-FreeSpireXls/AssemblyInfo.vb @@ -0,0 +1,9 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + + + + + + \ No newline at end of file diff --git a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.SharedCode.vb b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.SharedCode.vb index 7086f0c..32aa806 100644 --- a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.SharedCode.vb +++ b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.SharedCode.vb @@ -588,15 +588,22 @@ Namespace ExcelOps ''' Is the Excel engine allowed to automatically/continuously calculate on every change or does the user has to manually force a recalculation (typically by pressing F9 key in MS Excel) ''' ''' - Public Overrides Property AutoCalculationEnabled As Boolean + Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean Get - Return (Me.Workbook.CalculationMode = ExcelCalculationMode.Auto) + If Me._Workbook IsNot Nothing Then + Return (Me.Workbook.CalculationMode = ExcelCalculationMode.Auto) + Else + Return MyBase.AutoCalculationEnabledWorkbookSetting + End If End Get Set(value As Boolean) - If value Then - Me.Workbook.CalculationMode = ExcelCalculationMode.Auto - Else - Me.Workbook.CalculationMode = ExcelCalculationMode.Manual + MyBase.AutoCalculationEnabledWorkbookSetting = value + If Me._Workbook IsNot Nothing Then + If value Then + Me.Workbook.CalculationMode = ExcelCalculationMode.Auto + Else + Me.Workbook.CalculationMode = ExcelCalculationMode.Manual + End If End If End Set End Property diff --git a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb index 08e0a86..8cc269c 100644 --- a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb +++ b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb @@ -21,6 +21,44 @@ Namespace ExcelOps Public Class FreeSpireXlsDataOperations Inherits ExcelDataOperationsBase + Protected Overrides ReadOnly Property DefaultCalculationOptions As ExcelEngineDefaultOptions + Get + Return New ExcelEngineDefaultOptions(False, False) + End Get + End Property + + ''' + ''' Create or open a workbook (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on) + ''' + ''' Path to a file which shall be loaded or null if a new workbook shall be created + ''' Open an existing file or (re)create a new file + ''' File and engine options + ''' + ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. + ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. + ''' + Public Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(file, mode, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As Byte(), options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As System.IO.Stream, options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + ''' ''' 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) ''' @@ -32,8 +70,10 @@ Namespace ExcelOps ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' - Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) - MyBase.New(file, mode, Not disableInitialCalculation, False, [readOnly], passwordForOpening) + + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(file, mode, Not disableInitialCalculation, disableCalculationEngine, [readOnly], passwordForOpening) End Sub ''' @@ -47,24 +87,34 @@ Namespace ExcelOps ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, True, False, [readOnly], passwordForOpening) End Sub + + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) End Sub - Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean) - MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) + + + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) End Sub + + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) End Sub - Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean) - MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) + + + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) End Sub ''' @@ -74,8 +124,8 @@ Namespace ExcelOps ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' - Public Sub New() - Me.New(Nothing) + Friend Sub New() + MyBase.New(New ExcelDataOperationsOptions) End Sub ''' @@ -86,6 +136,8 @@ Namespace ExcelOps ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' + + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(True, False, True, passwordForOpeningOnNextTime) End Sub diff --git a/ExcelOps-MicrosoftExcel/AssemblyInfo.vb b/ExcelOps-MicrosoftExcel/AssemblyInfo.vb index db83b81..9ad65c4 100644 --- a/ExcelOps-MicrosoftExcel/AssemblyInfo.vb +++ b/ExcelOps-MicrosoftExcel/AssemblyInfo.vb @@ -2,4 +2,7 @@ Imports System.Reflection Imports System.Runtime.InteropServices + + + \ No newline at end of file diff --git a/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb b/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb index f5f32fc..4972bd8 100644 --- a/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb +++ b/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb @@ -1,4 +1,5 @@ -Imports CompuMaster.Excel.MsExcelCom +Imports CompuMaster.Excel.ExcelOps +Imports CompuMaster.Excel.MsExcelCom Namespace Global.CompuMaster.Excel.MsExcelCom @@ -32,7 +33,7 @@ Namespace Global.CompuMaster.Excel.MsExcelCom If MsExcelApp Is Nothing Then MsExcelApp = New MsExcelApplicationWrapper() End If - Dim wb As New ExcelOps.MsExcelDataOperations(filePath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, False, passwordForOpening) + Dim wb As New ExcelOps.MsExcelDataOperations(filePath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Try wb.RecalculateAll() wb.Save() diff --git a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb index a7c30cc..a58d2af 100644 --- a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb +++ b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb @@ -40,6 +40,12 @@ Namespace Global.CompuMaster.Excel.ExcelOps End If End Sub + Protected Overrides ReadOnly Property DefaultCalculationOptions As ExcelEngineDefaultOptions + Get + Return New ExcelEngineDefaultOptions(False, False) + End Get + End Property + ''' ''' Class for holding a reference to Excel.Application (ATTENTION: watch for advised Try-Finally pattern!) ''' @@ -53,6 +59,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' + + Public Sub New(passwordForOpeningOnNextTime As String) Me.New(Nothing, OpenMode.CreateFile, False, True, passwordForOpeningOnNextTime) End Sub @@ -70,8 +78,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - Public Sub New() - Me.New(Nothing) + Friend Sub New() + MyBase.New(New ExcelDataOperationsOptions) End Sub ''' @@ -87,6 +95,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, New MsExcelApplicationWrapper, False, [readOnly], passwordForOpening) End Sub @@ -104,6 +114,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' + + Public Sub New(file As String, mode As OpenMode, unprotectWorksheets As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, New MsExcelApplicationWrapper, unprotectWorksheets, [readOnly], passwordForOpening) End Sub @@ -122,7 +134,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - + ' + Public Sub New(file As String, mode As OpenMode, msExcelApp As MsExcelApplicationWrapper, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, msExcelApp, True, [readOnly], passwordForOpening) Me._MsExcelAppInstance = msExcelApp @@ -142,6 +155,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' + + Public Sub New(file As String, mode As OpenMode, msExcelApp As MsExcelApplicationWrapper, unprotectWorksheets As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, msExcelApp, unprotectWorksheets, [readOnly], passwordForOpening, False) End Sub @@ -161,6 +176,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' + + Public Sub New(file As String, mode As OpenMode, msExcelApp As MsExcelApplicationWrapper, unprotectWorksheets As Boolean, [readOnly] As Boolean, passwordForOpening As String, disableAutoCalculation As Boolean) #Disable Warning IDE0060 ' Nicht verwendete Parameter entfernen #Enable Warning IDE0060 ' Nicht verwendete Parameter entfernen @@ -172,9 +189,9 @@ Namespace Global.CompuMaster.Excel.ExcelOps End If Select Case mode Case OpenMode.OpenExistingFile - Me.LoadAndInitializeWorkbookFile(file) + Me.LoadAndInitializeWorkbookFile(file, ConvertToUnvalidatedOptions(Not disableAutoCalculation, False, [readOnly], passwordForOpening)) Case OpenMode.CreateFile - Me.CreateAndInitializeWorkbookFile(file) + Me.CreateAndInitializeWorkbookFile(file, ConvertToUnvalidatedOptions(Not disableAutoCalculation, False, [readOnly], passwordForOpening)) Me.ReadOnly = [readOnly] OrElse (file = Nothing) Case Else Throw New ArgumentOutOfRangeException(NameOf(mode)) @@ -184,6 +201,79 @@ Namespace Global.CompuMaster.Excel.ExcelOps End If End Sub + ''' + ''' Class for holding a reference to Excel.Application (ATTENTION: watch for advised Try-Finally pattern!) + ''' + ''' Use with pattern + ''' + ''' Dim MsExcelOps As New MsExcelDataOperations(fileName) + ''' Try + ''' '... + ''' Finally + ''' MsExcelOps.CloseExcelAppInstance() + ''' End Try + ''' + ''' + Public Sub New(file As String, mode As OpenMode, options As ExcelOps.ExcelDataOperationsOptions) + Me.New(file, mode, New MsExcelApplicationWrapper, False, options) + End Sub + + ''' + ''' Class for holding a reference to Excel.Application (ATTENTION: watch for advised Try-Finally pattern!) + ''' + ''' Use with pattern + ''' + ''' Dim MsExcelOps As New MsExcelDataOperations(fileName) + ''' Try + ''' '... + ''' Finally + ''' MsExcelOps.CloseExcelAppInstance() + ''' End Try + ''' + ''' + Public Sub New(file As String, mode As OpenMode, unprotectWorksheets As Boolean, options As ExcelOps.ExcelDataOperationsOptions) + Me.New(file, mode, New MsExcelApplicationWrapper, unprotectWorksheets, options) + End Sub + + ''' + ''' MS Excel Interop provider (ATTENTION: watch for advised Try-Finally pattern for successful application process stop!) incl. unprotection of sheets + ''' + ''' Use with pattern + ''' + ''' Dim MsExcelApp As New MsExcelDataOperations.MsAppInstance + ''' Try + ''' '... + ''' Finally + ''' MsExcelDataOperations.PrepareCloseExcelAppInstance(MSExcelApp) + ''' MsExcelDataOperations.SafelyCloseExcelAppInstance(MSExcelApp) + ''' End Try + ''' + ''' + Public Sub New(file As String, mode As OpenMode, msExcelApp As MsExcelApplicationWrapper, unprotectWorksheets As Boolean, options As ExcelOps.ExcelDataOperationsOptions) +#Disable Warning IDE0060 ' Nicht verwendete Parameter entfernen +#Enable Warning IDE0060 ' Nicht verwendete Parameter entfernen + MyBase.New(options) + Me._MsExcelAppInstance = msExcelApp + Me._Workbooks = New MsExcelWorkbooksWrapper(msExcelApp, msExcelApp.ComObjectStronglyTyped.Workbooks) + Select Case mode + Case OpenMode.OpenExistingFile + Me.LoadAndInitializeWorkbookFile(file, options) + Case OpenMode.CreateFile + Me.CreateAndInitializeWorkbookFile(file, options) + Me.ReadOnly = [ReadOnly] OrElse (file = Nothing) + Case Else + Throw New ArgumentOutOfRangeException(NameOf(mode)) + End Select + If unprotectWorksheets = True Then + Me.UnprotectSheets() + End If + End Sub + + Protected Overrides Sub ValidateLoadOptions(options As ExcelDataOperationsOptions) + If options.DisableCalculationEngine.Value = True Then Throw New NotSupportedException("MS Excel doesn't support disabling of calculation engine") + MyBase.ValidateLoadOptions(options) + End Sub + '''' '''' MS Excel Interop provider (ATTENTION: watch for advised Try-Finally pattern for successful application process stop!) '''' @@ -300,15 +390,28 @@ Namespace Global.CompuMaster.Excel.ExcelOps End Get End Property - Public Overrides Property AutoCalculationEnabled As Boolean + ''' + ''' If enabled, the calculation engine will do a full recalculation after every modification. + ''' If disabled, the calculation engine is not allowed to automatically/continuously calculate on every change and the user has to manually force a recalculation (typically by pressing F9 key in MS Excel). + ''' + ''' + ''' Please note: this property is a workbook property (not an engine property!) + Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean Get - Return (Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationAutomatic) + If Me.MsExcelAppInstance IsNot Nothing AndAlso Me.MsExcelAppInstance.ComObjectStronglyTyped IsNot Nothing Then + Return (Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationAutomatic) + Else + Return MyBase.AutoCalculationEnabledWorkbookSetting + End If End Get Set(value As Boolean) - If value Then - Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationAutomatic - Else - Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationManual + MyBase.AutoCalculationEnabledWorkbookSetting = value + If Me.MsExcelAppInstance IsNot Nothing AndAlso Me.MsExcelAppInstance.ComObjectStronglyTyped IsNot Nothing Then + If value Then + Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationAutomatic + Else + Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationManual + End If End If End Set End Property @@ -1103,7 +1206,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps Me.Close() '2. Reload - Me.LoadAndInitializeWorkbookFile(TempFile) + Me.LoadAndInitializeWorkbookFile(TempFile, Me.LoadOptions) '3. Reset FileName property 'Me.WorkbookFilePath = PreservedFileName or Me.SetWorkbookFilePath(PreservedFileName) or similar not available for MS Excel via COM diff --git a/ExcelOps-SpireXls/AssemblyInfo.vb b/ExcelOps-SpireXls/AssemblyInfo.vb index 3400b3e..5dc7be3 100644 --- a/ExcelOps-SpireXls/AssemblyInfo.vb +++ b/ExcelOps-SpireXls/AssemblyInfo.vb @@ -2,4 +2,8 @@ Imports System.Reflection Imports System.Runtime.InteropServices + + + + \ No newline at end of file diff --git a/ExcelOps-SpireXls/SpireXlsDataOperations.SharedCode.vb b/ExcelOps-SpireXls/SpireXlsDataOperations.SharedCode.vb index cbc15ea..1b5b097 100644 --- a/ExcelOps-SpireXls/SpireXlsDataOperations.SharedCode.vb +++ b/ExcelOps-SpireXls/SpireXlsDataOperations.SharedCode.vb @@ -588,15 +588,22 @@ Namespace ExcelOps ''' Is the Excel engine allowed to automatically/continuously calculate on every change or does the user has to manually force a recalculation (typically by pressing F9 key in MS Excel) ''' ''' - Public Overrides Property AutoCalculationEnabled As Boolean + Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean Get - Return (Me.Workbook.CalculationMode = ExcelCalculationMode.Auto) + If Me._Workbook IsNot Nothing Then + Return (Me.Workbook.CalculationMode = ExcelCalculationMode.Auto) + Else + Return MyBase.AutoCalculationEnabledWorkbookSetting + End If End Get Set(value As Boolean) - If value Then - Me.Workbook.CalculationMode = ExcelCalculationMode.Auto - Else - Me.Workbook.CalculationMode = ExcelCalculationMode.Manual + MyBase.AutoCalculationEnabledWorkbookSetting = value + If Me._Workbook IsNot Nothing Then + If value Then + Me.Workbook.CalculationMode = ExcelCalculationMode.Auto + Else + Me.Workbook.CalculationMode = ExcelCalculationMode.Manual + End If End If End Set End Property diff --git a/ExcelOps-SpireXls/SpireXlsDataOperations.vb b/ExcelOps-SpireXls/SpireXlsDataOperations.vb index 02beff6..b11596e 100644 --- a/ExcelOps-SpireXls/SpireXlsDataOperations.vb +++ b/ExcelOps-SpireXls/SpireXlsDataOperations.vb @@ -16,6 +16,44 @@ Namespace ExcelOps Public Class SpireXlsDataOperations Inherits ExcelDataOperationsBase + Protected Overrides ReadOnly Property DefaultCalculationOptions As ExcelEngineDefaultOptions + Get + Return New ExcelEngineDefaultOptions(False, False) + End Get + End Property + + ''' + ''' Create or open a workbook (reminder: set System.Threading.Thread.CurrentThread.CurrentCulture as required BEFORE creating the instance to ensure the engine uses the correct culture later on) + ''' + ''' Path to a file which shall be loaded or null if a new workbook shall be created + ''' Open an existing file or (re)create a new file + ''' File and engine options + ''' + ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. + ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. + ''' + Public Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(file, mode, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As Byte(), options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Public Sub New(data As System.IO.Stream, options As ExcelDataOperationsOptions) + MyBase.New(data, options) + End Sub + ''' ''' 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) ''' @@ -24,8 +62,10 @@ Namespace ExcelOps ''' ''' ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ - Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) - MyBase.New(file, mode, Not disableInitialCalculation, False, [readOnly], passwordForOpening) + + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(file, mode, Not disableInitialCalculation, disableCalculationEngine, [readOnly], passwordForOpening) If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub @@ -37,33 +77,43 @@ Namespace ExcelOps ''' ''' ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ + + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, True, False, [readOnly], passwordForOpening) If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub + + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) End Sub - Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean) - MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) + + + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) End Sub + + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) End Sub - Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean) - MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) + + + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) End Sub ''' ''' 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) ''' ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ - Public Sub New() - Me.New(Nothing) + Friend Sub New() + MyBase.New(New ExcelDataOperationsOptions) End Sub ''' @@ -71,6 +121,8 @@ Namespace ExcelOps ''' ''' ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ + + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(True, False, True, passwordForOpeningOnNextTime) If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") diff --git a/ExcelOps-Tools-MsAndEpplusFreeFixCalcsEdition/MsVsEpplusTools.vb b/ExcelOps-Tools-MsAndEpplusFreeFixCalcsEdition/MsVsEpplusTools.vb index 50bcdcb..2e76ce1 100644 --- a/ExcelOps-Tools-MsAndEpplusFreeFixCalcsEdition/MsVsEpplusTools.vb +++ b/ExcelOps-Tools-MsAndEpplusFreeFixCalcsEdition/MsVsEpplusTools.vb @@ -24,8 +24,9 @@ Namespace ExcelOps ''' ''' Public Shared Sub OpenAndClearCalculatedValuesToForceRecalculationOnNextOpeningWithMsExcelAndCloseExcelWorkbookWithEpplus(path As String, passwordForOpening As String) - Dim Wb As New ExcelOps.EpplusFreeExcelDataOperations(path, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, passwordForOpening) With { - .RecalculationRequired = True + Dim Wb As New ExcelOps.EpplusFreeExcelDataOperations(path, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) With { + .RecalculationRequired = True, + .PasswordForOpening = passwordForOpening } Wb.SaveAs(Wb.FilePath, ExcelOps.ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.AlwaysResetCalculatedValuesForForcedCellRecalculation) Wb.Close() @@ -50,7 +51,7 @@ Namespace ExcelOps Dim MsExcelWb As ExcelOps.MsExcelDataOperations = Nothing Try MSExcel = New MsExcelCom.MsExcelApplicationWrapper - MsExcelWb = New ExcelOps.MsExcelDataOperations(path, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, False, passwordForOpening) + MsExcelWb = New ExcelOps.MsExcelDataOperations(path, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite, passwordForOpening)) MsExcelWb.RecalculateAll() MsExcelWb.Save() MsExcelWb.Close() diff --git a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb index 3f6e9c3..d69d037 100644 --- a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb @@ -1,5 +1,6 @@ Option Explicit On Option Strict On + Imports System.IO Imports System.Text @@ -15,6 +16,95 @@ Namespace ExcelOps CreateFile = 1 End Enum + ''' + ''' Create or open a workbook + ''' + ''' Path to a file which shall be loaded or null if a new workbook shall be created + ''' Open an existing file or (re)create a new file + ''' File and engine options + Protected Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) + Me.New(options) + If mode = OpenMode.OpenExistingFile AndAlso file = Nothing Then + Throw New ArgumentNullException(NameOf(file), "File path must be provided when opening an existing file") + End If + Select Case mode + Case OpenMode.OpenExistingFile + Me.LoadAndInitializeWorkbookFile(file, options) + Case OpenMode.CreateFile + Me.CreateAndInitializeWorkbookFile(file, options) + Me.ReadOnly = [ReadOnly] OrElse (file = Nothing) + Case Else + Throw New ArgumentOutOfRangeException(NameOf(mode)) + End Select + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Protected Sub New(data As Byte(), options As ExcelDataOperationsOptions) + Me.New(options) + Me.LoadAndInitializeWorkbookFile(data, options) + End Sub + + ''' + ''' Open a workbook + ''' + ''' + ''' File and engine options + Protected Sub New(data As System.IO.Stream, options As ExcelDataOperationsOptions) + Me.New(options) + Me.LoadAndInitializeWorkbookFile(data, options) + End Sub + + ''' + ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) + ''' + ''' File and engine options + Protected Sub New(options As ExcelDataOperationsOptions) + If options Is Nothing Then Throw New ArgumentNullException(NameOf(options)) + Dim ValidatedOptions As ExcelDataOperationsOptions = options.ApplyDefaultsFromEngineAndValidate(Me.DefaultCalculationOptions) + Me.ValidateLoadOptions(ValidatedOptions) + Me.LoadOptions = ValidatedOptions + Me.CalculationModuleDisabled = ValidatedOptions.DisableCalculationEngine.Value + Me.AutoCalculationOnLoad = Not ValidatedOptions.DisableInitialCalculation.Value + If ValidatedOptions.DisableAutoCalculationInWorkbook.HasValue Then + Me.AutoCalculationEnabledWorkbookSetting = Not ValidatedOptions.DisableAutoCalculationInWorkbook.Value + End If + Me.ReadOnly = (ValidatedOptions.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly) + Me.PasswordForOpening = ValidatedOptions.PasswordForOpening + End Sub + + Protected Overridable Sub ValidateLoadOptions(options As ExcelDataOperationsOptions) + 'nothing to do here + 'but override possible to check in engine for unsupported options (e.g. MS Excel doesn't support disabling of whole calculation module) + End Sub + + Protected ReadOnly Property LoadOptions As ExcelDataOperationsOptions + + ''' + ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) + ''' + Private Sub New() + Me.New(New ExcelDataOperationsOptions) + End Sub + + ''' + ''' Default options for calculation behavior of the engine + ''' + ''' + Protected Friend MustOverride ReadOnly Property DefaultCalculationOptions() As ExcelEngineDefaultOptions + + Protected Shared Function ConvertToUnvalidatedOptions(autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, [readOnly] As Boolean, passwordForOpening As String) As ExcelDataOperationsOptions + Return New ExcelDataOperationsOptions(If([readOnly], ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly, ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite), + passwordForOpening, + Not autoCalculationOnLoad, + calculationModuleDisabled, + calculationModuleDisabled) + + End Function + ''' ''' Create or open a workbook ''' @@ -24,7 +114,10 @@ Namespace ExcelOps ''' ''' ''' + + Protected Sub New(file As String, mode As OpenMode, autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, [readOnly] As Boolean, passwordForOpening As String) + Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, [readOnly], passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) Me.AutoCalculationOnLoad = autoCalculationOnLoad Me.CalculationModuleDisabled = calculationModuleDisabled @@ -32,9 +125,9 @@ Namespace ExcelOps Select Case mode Case OpenMode.OpenExistingFile Me.PasswordForOpening = passwordForOpening - Me.LoadAndInitializeWorkbookFile(file) + Me.LoadAndInitializeWorkbookFile(file, Me.LoadOptions) Case OpenMode.CreateFile - Me.CreateAndInitializeWorkbookFile(file) + Me.CreateAndInitializeWorkbookFile(file, Me.LoadOptions) Me.ReadOnly = [readOnly] OrElse (file = Nothing) Me.PasswordForOpening = passwordForOpening Case Else @@ -49,14 +142,17 @@ Namespace ExcelOps ''' ''' ''' + + Protected Sub New(data As Byte(), autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, passwordForOpening As String) + Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, True, passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) Me.AutoCalculationOnLoad = autoCalculationOnLoad Me.CalculationModuleDisabled = calculationModuleDisabled Me.ReadOnly = True 'OpenMode.OpenExistingFile Me.PasswordForOpening = passwordForOpening - Me.LoadAndInitializeWorkbookFile(data) + Me.LoadAndInitializeWorkbookFile(data, Me.LoadOptions) End Sub ''' @@ -66,14 +162,17 @@ Namespace ExcelOps ''' ''' ''' + + Protected Sub New(data As System.IO.Stream, autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, passwordForOpening As String) + Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, True, passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) Me.AutoCalculationOnLoad = autoCalculationOnLoad Me.CalculationModuleDisabled = calculationModuleDisabled Me.ReadOnly = True 'OpenMode.OpenExistingFile Me.PasswordForOpening = passwordForOpening - Me.LoadAndInitializeWorkbookFile(data) + Me.LoadAndInitializeWorkbookFile(data, Me.LoadOptions) End Sub ''' @@ -81,7 +180,10 @@ Namespace ExcelOps ''' ''' Automatically do a full recalculation after workbook has been loaded ''' Disables the Excel calculation engine + + Protected Sub New(autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, [readOnly] As Boolean, passwordForOpening As String) + Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, [readOnly], passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) Me.AutoCalculationOnLoad = autoCalculationOnLoad Me.CalculationModuleDisabled = calculationModuleDisabled @@ -93,7 +195,7 @@ Namespace ExcelOps ''' Reload a file from disk ''' Public Sub ReloadFromFile() - Me.LoadAndInitializeWorkbookFile(Me.FilePath) + Me.LoadAndInitializeWorkbookFile(Me.FilePath, Me.LoadOptions) End Sub ''' @@ -101,30 +203,114 @@ Namespace ExcelOps ''' ''' Public Property PasswordForOpening As String + Get + Return Me.LoadOptions.PasswordForOpening + End Get + Set(value As String) + Me.LoadOptions.PasswordForOpening = value + End Set + End Property ''' ''' Write protection for this filename prevents Save, but still allows SaveAs ''' ''' Public Property [ReadOnly] As Boolean + Get + Return Me.LoadOptions.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly + End Get + Set(value As Boolean) + Me.LoadOptions.FileWriteProtection = If(value, ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly, ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite) + End Set + End Property ''' ''' The calculation module of involved Excel engine might be disabled due to insufficiency/incompleteness of 3rd party Excel (calculation) engines (except for single cell calculations) ''' ''' Public Property CalculationModuleDisabled As Boolean + Get + Return Me.LoadOptions.DisableCalculationEngine.Value + End Get + Set(value As Boolean) + Me.LoadOptions.DisableCalculationEngine = value + End Set + End Property ''' ''' If enabled, the calculation engine will do a full recalculation after loading a workbook ''' ''' - Public ReadOnly Property AutoCalculationOnLoad As Boolean + Public Property AutoCalculationOnLoad As Boolean + Get + Return Me.LoadOptions.DisableInitialCalculation.Value + End Get + Set(value As Boolean) + Me.LoadOptions.DisableInitialCalculation = value + End Set + End Property + + ''' + ''' If enabled (default), the workbook setting will be reset to enabled AutoCalculation feature in all saved workbooks (but stays at its value in-memory) + ''' If disabled, the workbook setting for AutoCalculation will be saved as it is + ''' + ''' + ''' Please note: this property is an engine property and defaults to True + Public Property AutoCalculationResetToEnabledForAllSavedWorkbooks As Boolean = True + + ''' + ''' If enabled, the calculation engine will do a full recalculation after every modification. + ''' If disabled, the calculation engine is not allowed to automatically/continuously calculate on every change and the user has to manually force a recalculation (typically by pressing F9 key in MS Excel). + ''' + ''' + ''' Please note: this property is a workbook property (not an engine property!) + + + Public Property AutoCalculationEnabled As Boolean + Get + Return AutoCalculationEnabledWorkbookSetting + End Get + Set(value As Boolean) + AutoCalculationEnabledWorkbookSetting = value + End Set + End Property ''' - ''' If enabled, the calculation engine will do a full recalculation after every modification + ''' If enabled, the calculation engine will do a full recalculation after every modification. + ''' If disabled, the calculation engine is not allowed to automatically/continuously calculate on every change and the user has to manually force a recalculation (typically by pressing F9 key in MS Excel). ''' ''' - Public MustOverride Property AutoCalculationEnabled As Boolean + ''' Please note: this property is a workbook property (not an engine property!) + Public Overridable Property AutoCalculationEnabledWorkbookSetting As Boolean + Get + Return Not Me.LoadOptions.DisableAutoCalculationInWorkbook.GetValueOrDefault + End Get + Set(value As Boolean) + Me.LoadOptions.DisableAutoCalculationInWorkbook = Not value + End Set + End Property + + '''' + '''' If calculation module is enabled and also AutoCalculationEnabled is enabled, then AutoCalculationEnabled is enabled effectively + '''' + '''' + 'Protected Friend ReadOnly Property AutoCalculationEnabledEffectively As Boolean + ' Get + ' Return Me.CalculationModuleDisabled AndAlso Me.AutoCalculationEnabledWorkbookSetting + ' End Get + 'End Property + + ''' + ''' If calculation module is enabled and also AutoCalculationOnLoad is enabled, then AutoCalculationOnLoad is enabled effectively (regardless of AutoCalculationEnabled setting) + ''' + ''' + Protected Friend ReadOnly Property AutoCalculationOnLoadEffectively As Boolean + Get + Return Not Me.CalculationModuleDisabled AndAlso Me.AutoCalculationOnLoad + End Get + End Property + + Protected _FilePath As String @@ -163,6 +349,7 @@ Namespace ExcelOps ''' ''' Save modifications made to the workbook ''' + ''' Depending on AutoCalculationResetToEnabledForAllSavedWorkbooks, AutoCalculationEnabledWorkbookSetting will be reset to True in saved workbook Public Sub Save() Me.Save(SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) End Sub @@ -170,6 +357,7 @@ Namespace ExcelOps ''' ''' Save modifications made to the workbook ''' + ''' Depending on AutoCalculationResetToEnabledForAllSavedWorkbooks, AutoCalculationEnabledWorkbookSetting will be reset to True in saved workbook Public Sub Save(cachedCalculationsOption As SaveOptionsForDisabledCalculationEngines) If Me.ReadOnly = True Then Throw New FileReadOnlyException("File is read-only and can't be saved at same location") @@ -186,13 +374,17 @@ Namespace ExcelOps Me.SaveAs(Me.FilePath, cachedCalculationsOption) Else Me.SaveInternal_ApplyCachedCalculationOption(cachedCalculationsOption) - Dim AutoCalcBuffer As Boolean = Me.AutoCalculationEnabled - Try - Me.AutoCalculationEnabled = True + If Me.AutoCalculationResetToEnabledForAllSavedWorkbooks Then + Dim AutoCalcBuffer As Boolean = Me.AutoCalculationEnabledWorkbookSetting + Try + Me.AutoCalculationEnabledWorkbookSetting = True + Me.SaveInternal() + Finally + Me.AutoCalculationEnabledWorkbookSetting = AutoCalcBuffer + End Try + Else Me.SaveInternal() - Finally - Me.AutoCalculationEnabled = AutoCalcBuffer - End Try + End If End If End Sub @@ -226,6 +418,7 @@ Namespace ExcelOps ''' Save workbook as another file ''' ''' + ''' Depending on AutoCalculationResetToEnabledForAllSavedWorkbooks, AutoCalculationEnabledWorkbookSetting will be reset to True in saved workbook Public Sub SaveAs(filePath As String) @@ -236,6 +429,7 @@ Namespace ExcelOps ''' Save workbook as another file ''' ''' + ''' Depending on AutoCalculationResetToEnabledForAllSavedWorkbooks, AutoCalculationEnabledWorkbookSetting will be reset to True in saved workbook Public Sub SaveAs(filePath As String, cachedCalculationsOption As SaveOptionsForDisabledCalculationEngines) If Me.ReadOnly = True AndAlso Me._FilePath = filePath AndAlso Me.WorkbookFilePath <> Nothing Then Throw New FileReadOnlyException("File """ & filePath & """ is read-only and can't be saved at same location") @@ -249,14 +443,17 @@ Namespace ExcelOps If Me.RecalculationRequired AndAlso Me.CalculationModuleDisabled = False Then Me.RecalculateAll() Me.SaveInternal_ApplyCachedCalculationOption(cachedCalculationsOption) - Dim AutoCalcBuffer As Boolean = Me.AutoCalculationEnabled - Try - Me.AutoCalculationEnabled = True + If Me.AutoCalculationResetToEnabledForAllSavedWorkbooks Then + Dim AutoCalcBuffer As Boolean = Me.AutoCalculationEnabledWorkbookSetting + Try + Me.AutoCalculationEnabledWorkbookSetting = True + Me.SaveAsInternal(filePath, cachedCalculationsOption) + Finally + Me.AutoCalculationEnabledWorkbookSetting = AutoCalcBuffer + End Try + Else Me.SaveAsInternal(filePath, cachedCalculationsOption) - Finally - Me.AutoCalculationEnabled = AutoCalcBuffer - End Try - + End If Me._FilePath = filePath Me.ReadOnly = False End Sub @@ -447,36 +644,23 @@ Namespace ExcelOps ''' Formula without leading '=' char Public MustOverride Sub WriteCellFormula(sheetName As String, rowIndex As Integer, columnIndex As Integer, formula As String, immediatelyCalculateCellValue As Boolean) - Private _RecalculationRequired As TriState = TriState.UseDefault + Private _RecalculationRequired As Boolean? ''' ''' Modifications require a full recalculation ''' ''' Public Property RecalculationRequired As Boolean Get - If _RecalculationRequired = TriState.UseDefault Then - Me.RecalculationRequired = False 'Defaults to false - End If - If _RecalculationRequired = TriState.True Then - Return True - Else - Return False - End If + Return Me._RecalculationRequired.GetValueOrDefault(False) End Get Set(value As Boolean) - If value = True Then 'then AndAlso Me.AutoCalculationEnabled = False Then - _RecalculationRequired = TriState.True - Else - 'value=False OR - 'sub module requests calculation, but is already done by Excel engine automatically - _RecalculationRequired = TriState.False - End If + _RecalculationRequired = value End Set End Property Protected MustOverride Sub LoadWorkbook(file As System.IO.FileInfo) - Protected Sub LoadAndInitializeWorkbookFile(inputPath As String) + Protected Sub LoadAndInitializeWorkbookFile(inputPath As String, options As ExcelDataOperationsOptions) If inputPath = Nothing Then Throw New ArgumentNullException(NameOf(inputPath)) '1st, close an exsting workbook instance If Me.IsClosed = False Then Me.Close() @@ -487,38 +671,29 @@ Namespace ExcelOps Throw New System.IO.FileNotFoundException("Missing file: " & file.ToString, file.ToString) End If Me.LoadWorkbook(file) - Me.AutoCalculationEnabled = False - If Me.AutoCalculationOnLoad Then - Me.RecalculateAll() - End If + Me.PostLoadOrCreateWorkbook(options) End Sub Protected MustOverride Sub LoadWorkbook(data As Byte()) - Protected Sub LoadAndInitializeWorkbookFile(data As Byte()) + Protected Sub LoadAndInitializeWorkbookFile(data As Byte(), options As ExcelDataOperationsOptions) '1st, close an exsting workbook instance If Me.IsClosed = False Then Me.Close() 'Load the changed worksheet Me._FilePath = Nothing Me.LoadWorkbook(data) - Me.AutoCalculationEnabled = False - If Me.AutoCalculationOnLoad Then - Me.RecalculateAll() - End If + Me.PostLoadOrCreateWorkbook(options) End Sub Protected MustOverride Sub LoadWorkbook(data As System.IO.Stream) - Protected Sub LoadAndInitializeWorkbookFile(data As System.IO.Stream) + Protected Sub LoadAndInitializeWorkbookFile(data As System.IO.Stream, options As ExcelDataOperationsOptions) '1st, close an exsting workbook instance If Me.IsClosed = False Then Me.Close() 'Load the changed worksheet Me._FilePath = Nothing Me.LoadWorkbook(data) - Me.AutoCalculationEnabled = False - If Me.AutoCalculationOnLoad Then - Me.RecalculateAll() - End If + Me.PostLoadOrCreateWorkbook(options) End Sub Protected MustOverride Sub CreateWorkbook() @@ -527,7 +702,7 @@ Namespace ExcelOps ''' Create a new workbook ''' ''' If the file path is already known, the file will be checked to not exist already and the file path will be used for later saving - Protected Sub CreateAndInitializeWorkbookFile(intendedFilePath As String) + Protected Sub CreateAndInitializeWorkbookFile(intendedFilePath As String, options As ExcelDataOperationsOptions) 'Load the changed worksheet If intendedFilePath <> Nothing Then Me._FilePath = intendedFilePath @@ -539,8 +714,18 @@ Namespace ExcelOps Me._FilePath = Nothing End If Me.CreateWorkbook() - Me.AutoCalculationEnabled = False - If Me.AutoCalculationOnLoad Then + Me.PostLoadOrCreateWorkbook(options) + End Sub + + ''' + ''' Assign default options, perform required calculations + ''' + ''' + Protected Sub PostLoadOrCreateWorkbook(options As ExcelDataOperationsOptions) + If options.DisableAutoCalculationInWorkbook.HasValue Then + Me.AutoCalculationEnabledWorkbookSetting = options.DisableAutoCalculationInWorkbook.Value 'Update local internal value of property to the workbook's setting + End If + If Me.AutoCalculationOnLoadEffectively Then Me.RecalculateAll() End If End Sub diff --git a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb new file mode 100644 index 0000000..9a27131 --- /dev/null +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb @@ -0,0 +1,133 @@ +Option Explicit On +Option Strict On + +Imports System.IO +Imports System.Text + +Namespace ExcelOps + + ''' + ''' Base implementation for common API for the several Excel engines + ''' + Public Class ExcelDataOperationsOptions + + ''' + ''' Create a new options instance + ''' + Public Sub New() + End Sub + + Public Sub New(fileProtection As WriteProtectionMode) + Me.FileWriteProtection = fileProtection + End Sub + + Public Sub New(fileProtection As WriteProtectionMode, passwordForOpening As String) + Me.FileWriteProtection = fileProtection + Me.PasswordForOpening = passwordForOpening + End Sub + + ''' + ''' Create a new options instance + ''' + ''' Password for opening protected Excel files + Public Sub New(passwordForOpening As String) + Me.PasswordForOpening = passwordForOpening + End Sub + + ''' + ''' Create a new options instance + ''' + ''' Password for opening protected Excel files + ''' If set to true, no initial calculation of formulas is performed when opening/loading an Excel file + ''' If set to true, the calculation engine is disabled and no formula calculations are performed + Public Sub New(passwordForOpening As String, disableInitialCalculation As Boolean?, disableAutoCalculation As Boolean?, disableCalculationEngine As Boolean?) + Me.PasswordForOpening = passwordForOpening + Me.DisableInitialCalculation = disableInitialCalculation + Me.DisableAutoCalculationInWorkbook = disableAutoCalculation + Me.DisableCalculationEngine = disableCalculationEngine + End Sub + + ''' + ''' Create a new options instance + ''' + ''' Password for opening protected Excel files + ''' If set to true, no initial calculation of formulas is performed when opening/loading an Excel file + ''' If set to true, the calculation engine is disabled and no formula calculations are performed + Public Sub New(fileProtection As WriteProtectionMode, passwordForOpening As String, disableInitialCalculation As Boolean?, disableAutoCalculation As Boolean?, disableCalculationEngine As Boolean?) + Me.FileWriteProtection = fileProtection + Me.PasswordForOpening = passwordForOpening + Me.DisableInitialCalculation = disableInitialCalculation + Me.DisableAutoCalculationInWorkbook = disableAutoCalculation + Me.DisableCalculationEngine = disableCalculationEngine + End Sub + + Public Enum WriteProtectionMode As Byte + ''' + ''' File can't be saved (saving with same file name is forbidden), but SaveAs with another file name is allowed + ''' + [ReadOnly] = 0 + ''' + ''' No limitation + ''' + ReadWrite = 1 + End Enum + + ''' + ''' Write protection for this filename prevents Save, but still allows SaveAs + ''' + ''' + Public Property FileWriteProtection As WriteProtectionMode = WriteProtectionMode.ReadOnly + + ''' + ''' If set to true, the calculation engine is disabled and no formula calculations are performed, if set to false, the calculation engine is enabled, if null/not set, the engine default is used + ''' + ''' Feature belongs to Excel engine + Public Property DisableCalculationEngine As Boolean? + + ''' + ''' If set to true, no initial calculation of formulas is performed when opening/loading an Excel file, if set to false, the calculation engine is enabled, if null/not set, the engine default is used + ''' + ''' Feature belongs to Excel engine + Public Property DisableInitialCalculation As Boolean? + + ''' + ''' If set to true, automatic calculation mode is disabled in workbook (only manual calculation mode is used), if set to false, the calculation engine is enabled, if null/not set, the engine default is used + ''' + ''' Feature belongs to workbook and changes permanently the workbook's behaviour when saved + Public Property DisableAutoCalculationInWorkbook As Boolean? + + ''' + ''' Password for opening protected Excel files + ''' + ''' + Public Property PasswordForOpening As String + + ''' + ''' Create a clone of this options instance + ''' + ''' + Private Function Clone() As ExcelDataOperationsOptions + Return New ExcelDataOperationsOptions(PasswordForOpening, DisableInitialCalculation, DisableAutoCalculationInWorkbook, DisableCalculationEngine) With { + .FileWriteProtection = Me.FileWriteProtection + } + End Function + + ''' + ''' Apply default options from engine if not set and validate the resulting combination + ''' + ''' Default calculation options from engine + ''' Validated options instance + Public Function ApplyDefaultsFromEngineAndValidate(calculationDefaultOptions As ExcelEngineDefaultOptions) As ExcelDataOperationsOptions + Dim Result = Me.Clone + If Result.DisableCalculationEngine.HasValue = False Then + Result.DisableCalculationEngine = calculationDefaultOptions.DisableCalculationEngine + End If + If Result.DisableInitialCalculation.HasValue = False Then + Result.DisableInitialCalculation = calculationDefaultOptions.DisableInitialCalculation + End If + Return Result + End Function + + End Class + +End Namespace diff --git a/ExcelOps/ExcelOpsLowLevel/ExcelEngineDefaultOptions.vb b/ExcelOps/ExcelOpsLowLevel/ExcelEngineDefaultOptions.vb new file mode 100644 index 0000000..bf6bda5 --- /dev/null +++ b/ExcelOps/ExcelOpsLowLevel/ExcelEngineDefaultOptions.vb @@ -0,0 +1,36 @@ +Option Explicit On +Option Strict On + +Imports System.IO +Imports System.Text + +Namespace ExcelOps + + ''' + ''' Default options for an Excel engine + ''' + Public Class ExcelEngineDefaultOptions + + ''' + ''' Create a new options instance + ''' + ''' If set to true, no initial calculation of formulas is performed when opening/loading an Excel file, if set to false, the engine runs a full recalculation after loading a workbook + ''' If set to true, the calculation engine is disabled and no formula calculations can be performed, if set to false the calculation engine is available + Public Sub New(disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) + Me.DisableInitialCalculation = disableInitialCalculation + Me.DisableCalculationEngine = disableCalculationEngine + End Sub + + ''' + ''' If set to true, the calculation engine is disabled and no formula calculations are performed, if set to false, the calculation engine is enabled, if null/not set, the engine default is used + ''' + Public ReadOnly Property DisableCalculationEngine As Boolean + + ''' + ''' If set to true, no initial calculation of formulas is performed when opening/loading an Excel file, if set to false, the calculation engine is enabled, if null/not set, the engine default is used + ''' + Public ReadOnly Property DisableInitialCalculation As Boolean + + End Class + +End Namespace diff --git a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb index 10335b4..57b7293 100644 --- a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb +++ b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb @@ -1,4 +1,5 @@ -Imports NUnit.Framework +Imports CompuMaster.Excel.ExcelOps +Imports NUnit.Framework Namespace ExcelOpsTests.Engines @@ -7,8 +8,8 @@ Namespace ExcelOpsTests.Engines Public Overrides ReadOnly Property ExpectedEngineName As String = "FreeSpire.Xls" - Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) As ExcelOps.FreeSpireXlsDataOperations - Return New ExcelOps.FreeSpireXlsDataOperations(file, mode, [readOnly], passwordForOpening, disableInitialCalculation) + Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.FreeSpireXlsDataOperations + Return New ExcelOps.FreeSpireXlsDataOperations(file, mode, options) End Function Protected Overrides Function _CreateInstance() As ExcelOps.FreeSpireXlsDataOperations @@ -23,12 +24,12 @@ Namespace ExcelOpsTests.Engines MyBase.TestInCultureContext_AssignCurrentThreadCulture() End Sub - Protected Overrides Function _CreateInstance(data() As Byte, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.FreeSpireXlsDataOperations - Return New ExcelOps.FreeSpireXlsDataOperations(data, passwordForOpening, disableCalculationEngine) + Protected Overrides Function _CreateInstance(data() As Byte, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.FreeSpireXlsDataOperations + Return New ExcelOps.FreeSpireXlsDataOperations(data, options) End Function - Protected Overrides Function _CreateInstance(data As IO.Stream, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.FreeSpireXlsDataOperations - Return New ExcelOps.FreeSpireXlsDataOperations(data, passwordForOpening, disableCalculationEngine) + Protected Overrides Function _CreateInstance(data As IO.Stream, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.FreeSpireXlsDataOperations + Return New ExcelOps.FreeSpireXlsDataOperations(data, options) End Function End Class diff --git a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb index 5c6e069..cbda916 100644 --- a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb +++ b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb @@ -21,7 +21,7 @@ Namespace ExcelOpsTests.MsExcelSpecials End Property Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase - Return New ExcelOps.FreeSpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, String.Empty) + Return New ExcelOps.FreeSpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions()) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/ExcelOpsTest-FreeSpireXls/SpecialFeature_SaveToHtml.vb b/ExcelOpsTest-FreeSpireXls/SpecialFeature_SaveToHtml.vb index ea12984..f90fdb8 100644 --- a/ExcelOpsTest-FreeSpireXls/SpecialFeature_SaveToHtml.vb +++ b/ExcelOpsTest-FreeSpireXls/SpecialFeature_SaveToHtml.vb @@ -6,6 +6,8 @@ Public Class SpecialFeature_SaveToHtml Private Const OPEN_OUTPUT_IN_BROWSER_AFTER_TEST As Boolean = False Private Const UNIQUE_TEST_OUTPUT_SUBDIR_NAME_FOR_PROVIDER = "FreeSpire" + Private ReadOnly Property DisabledCalculationEngineOptions As ExcelDataOperationsOptions = New ExcelDataOperationsOptions("", True, True, True) + Public Sub ExportWorkbook() Dim TestXlsxFile = TestFiles.TestFileGrund01() @@ -14,7 +16,7 @@ Public Class SpecialFeature_SaveToHtml System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Try - Dim Wb As New FreeSpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Wb As New FreeSpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, DisabledCalculationEngineOptions) Wb.SaveToHtml(TestHtmlOutputFile, False) Catch ex As TypeInitializationException Assert.Ignore("Not supported on this platform " & System.Environment.OSVersion.Platform.ToString) @@ -35,7 +37,7 @@ Public Class SpecialFeature_SaveToHtml Dim Wb As FreeSpireXlsDataOperations = Nothing Try - Wb = New FreeSpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Wb = New FreeSpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, DisabledCalculationEngineOptions) Catch ex As TypeInitializationException Assert.Ignore("Not supported on this platform " & System.Environment.OSVersion.Platform.ToString) End Try diff --git a/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb b/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb index 2ff92d8..262ab15 100644 --- a/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb +++ b/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb @@ -11,8 +11,8 @@ Namespace ExcelOpsTests.Engines ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = True End Sub - Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) As ExcelOps.SpireXlsDataOperations - Return New ExcelOps.SpireXlsDataOperations(file, mode, [readOnly], passwordForOpening, disableInitialCalculation) + Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.SpireXlsDataOperations + Return New ExcelOps.SpireXlsDataOperations(file, mode, options) End Function Protected Overrides Function _CreateInstance() As ExcelOps.SpireXlsDataOperations @@ -37,12 +37,12 @@ Namespace ExcelOpsTests.Engines 'Simulation: license assigned ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = True Assert.NotNull(Me.CreateInstance) - Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, True, Nothing)) + Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions)) 'No license assigned -> instancing must fail ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = False Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance()) - Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, True, Nothing)) + Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions)) End Sub @@ -50,12 +50,12 @@ Namespace ExcelOpsTests.Engines Assert.False(CompuMaster.Excel.ExcelOps.Utils.IsLicensedContext) End Sub - Protected Overrides Function _CreateInstance(data() As Byte, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.SpireXlsDataOperations - Return New ExcelOps.SpireXlsDataOperations(data, passwordForOpening, disableCalculationEngine) + Protected Overrides Function _CreateInstance(data() As Byte, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.SpireXlsDataOperations + Return New ExcelOps.SpireXlsDataOperations(data, options) End Function - Protected Overrides Function _CreateInstance(data As IO.Stream, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.SpireXlsDataOperations - Return New ExcelOps.SpireXlsDataOperations(data, passwordForOpening, disableCalculationEngine) + Protected Overrides Function _CreateInstance(data As IO.Stream, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.SpireXlsDataOperations + Return New ExcelOps.SpireXlsDataOperations(data, options) End Function End Class diff --git a/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb b/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb index 84eb288..fe73ddb 100644 --- a/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb +++ b/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb @@ -21,7 +21,7 @@ Namespace ExcelOpsTests.MsExcelSpecials End Property Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase - Return New ExcelOps.SpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, String.Empty) + Return New ExcelOps.SpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/ExcelOpsTest-SpireXls/SpecialFeature_SaveToHtml.vb b/ExcelOpsTest-SpireXls/SpecialFeature_SaveToHtml.vb index 15ab39b..800d1ef 100644 --- a/ExcelOpsTest-SpireXls/SpecialFeature_SaveToHtml.vb +++ b/ExcelOpsTest-SpireXls/SpecialFeature_SaveToHtml.vb @@ -11,6 +11,8 @@ Public Class SpecialFeature_SaveToHtml ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = True End Sub + Private ReadOnly Property DisabledCalculationEngineOptions As ExcelDataOperationsOptions = New ExcelDataOperationsOptions("", True, True, True) + Public Sub ExportWorkbook() Dim TestXlsxFile = TestFiles.TestFileGrund01() @@ -19,7 +21,7 @@ Public Class SpecialFeature_SaveToHtml System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Try - Dim Wb As New SpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Wb As New SpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, DisabledCalculationEngineOptions) Wb.SaveToHtml(TestHtmlOutputFile, False) Catch ex As TypeInitializationException Assert.Ignore("Not supported on this platform " & System.Environment.OSVersion.Platform.ToString) @@ -40,7 +42,7 @@ Public Class SpecialFeature_SaveToHtml Dim Wb As SpireXlsDataOperations = Nothing Try - Wb = New SpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Wb = New SpireXlsDataOperations(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, DisabledCalculationEngineOptions) Catch ex As TypeInitializationException Assert.Ignore("Not supported on this platform " & System.Environment.OSVersion.Platform.ToString) End Try diff --git a/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb b/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb index 77a9829..fc4d34f 100644 --- a/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb +++ b/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb @@ -5,12 +5,21 @@ Option Strict On 'SEE: clone-build-files.cmd/.sh/.ps1 'WARNING: PLEASE CHANGE THIS FILE ONLY AT REQUIRED LOCATION, OR CHANGES WILL BE LOST! +Imports CompuMaster.Excel.ExcelOps Imports NUnit.Framework Namespace Data Public Class CmDataXlsEpplusPolyformEditionTest + Public Sub New() + AssignLicenseContext() + End Sub + + Friend Shared Sub AssignLicenseContext() + ExcelOps.EpplusPolyformExcelDataOperations.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial + End Sub + Public Sub ReadDataSetFromXlsFile() Dim Path As String = TestEnvironment.FullPathOfExistingTestFile("test_data", "SampleTable01.xlsx") diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb index 5c89302..338a62e 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb @@ -7,9 +7,9 @@ Namespace ExcelOpsTests.Engines Public Overrides ReadOnly Property ExpectedEngineName As String = "Epplus 4 (LGPL)" - Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) As ExcelOps.EpplusFreeExcelDataOperations + Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.EpplusFreeExcelDataOperations 'disableCalculationEngine not required since always disabled calc-module by engine - Return New ExcelOps.EpplusFreeExcelDataOperations(file, mode, [readOnly], passwordForOpening) + Return New ExcelOps.EpplusFreeExcelDataOperations(file, mode, options) End Function Protected Overrides Function _CreateInstance() As ExcelOps.EpplusFreeExcelDataOperations @@ -20,14 +20,14 @@ Namespace ExcelOpsTests.Engines Assert.Throws(Of NotSupportedException)(Sub() MyBase.CopySheetContent()) End Sub - Protected Overrides Function _CreateInstance(data() As Byte, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.EpplusFreeExcelDataOperations + Protected Overrides Function _CreateInstance(data() As Byte, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.EpplusFreeExcelDataOperations 'disableCalculationEngine not required since always disabled calc-module by engine - Return New ExcelOps.EpplusFreeExcelDataOperations(data, passwordForOpening) + Return New ExcelOps.EpplusFreeExcelDataOperations(data, options) End Function - Protected Overrides Function _CreateInstance(data As IO.Stream, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.EpplusFreeExcelDataOperations + Protected Overrides Function _CreateInstance(data As IO.Stream, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.EpplusFreeExcelDataOperations 'disableCalculationEngine not required since always disabled calc-module by engine - Return New ExcelOps.EpplusFreeExcelDataOperations(data, passwordForOpening) + Return New ExcelOps.EpplusFreeExcelDataOperations(data, options) End Function End Class diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb index fb69563..e1b39b5 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb @@ -1,4 +1,5 @@ -Imports NUnit.Framework +Imports CompuMaster.Excel.ExcelOps +Imports NUnit.Framework Namespace ExcelOpsTests.Engines @@ -15,8 +16,8 @@ Namespace ExcelOpsTests.Engines Public Overrides ReadOnly Property ExpectedEngineName As String = "Epplus (Polyform license edition)" - Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) As ExcelOps.EpplusPolyformExcelDataOperations - Return New ExcelOps.EpplusPolyformExcelDataOperations(file, mode, [readOnly], passwordForOpening, disableInitialCalculation) + Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.EpplusPolyformExcelDataOperations + Return New ExcelOps.EpplusPolyformExcelDataOperations(file, mode, options) End Function Protected Overrides Function _CreateInstance() As ExcelOps.EpplusPolyformExcelDataOperations @@ -27,12 +28,12 @@ Namespace ExcelOpsTests.Engines Assert.Throws(Of NotSupportedException)(Sub() MyBase.CopySheetContent()) End Sub - Protected Overrides Function _CreateInstance(data() As Byte, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.EpplusPolyformExcelDataOperations - Return New ExcelOps.EpplusPolyformExcelDataOperations(data, passwordForOpening, disableCalculationEngine) + Protected Overrides Function _CreateInstance(data() As Byte, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.EpplusPolyformExcelDataOperations + Return New ExcelOps.EpplusPolyformExcelDataOperations(data, options) End Function - Protected Overrides Function _CreateInstance(data As IO.Stream, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.EpplusPolyformExcelDataOperations - Return New ExcelOps.EpplusPolyformExcelDataOperations(data, passwordForOpening, disableCalculationEngine) + Protected Overrides Function _CreateInstance(data As IO.Stream, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.EpplusPolyformExcelDataOperations + Return New ExcelOps.EpplusPolyformExcelDataOperations(data, options) End Function End Class diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb b/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb index b38befc..4aae414 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb @@ -20,9 +20,9 @@ Namespace ExcelOpsTests.Engines Protected MustOverride Function _CreateInstance() As T #Disable Warning CA1716 ' Bezeichner dürfen nicht mit Schlüsselwörtern übereinstimmen - Protected MustOverride Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableCalculationEngine As Boolean) As T - Protected MustOverride Function _CreateInstance(data As Byte(), passwordForOpening As String, disableCalculationEngine As Boolean) As T - Protected MustOverride Function _CreateInstance(data As System.IO.Stream, passwordForOpening As String, disableCalculationEngine As Boolean) As T + Protected MustOverride Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As T + Protected MustOverride Function _CreateInstance(data As Byte(), options As ExcelOps.ExcelDataOperationsOptions) As T + Protected MustOverride Function _CreateInstance(data As System.IO.Stream, options As ExcelOps.ExcelDataOperationsOptions) As T #Enable Warning CA1716 ' Bezeichner dürfen nicht mit Schlüsselwörtern übereinstimmen ''' @@ -53,28 +53,6 @@ Namespace ExcelOpsTests.Engines End Try End Function - ''' - ''' 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) - ''' - ''' - ''' - ''' - ''' - ''' - Protected Function CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String) As T - Return Me.CreateInstance(file, mode, [readOnly], passwordForOpening, False) - End Function - - ''' - ''' 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) - ''' - ''' - ''' - ''' - Protected Function CreateInstance(data As Byte(), passwordForOpening As String) As T - Return Me.CreateInstance(data, passwordForOpening, False) - End Function - ''' ''' 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) ''' @@ -82,9 +60,9 @@ Namespace ExcelOpsTests.Engines ''' ''' ''' - Protected Function CreateInstance(data As Byte(), passwordForOpening As String, disableCalculationEngine As Boolean) As T + Protected Function CreateInstance(data As Byte(), options As ExcelOps.ExcelDataOperationsOptions) As T Try - Return _CreateInstance(data, passwordForOpening, disableCalculationEngine) + Return _CreateInstance(data, options) Catch ex As Exception If ex.GetType() Is GetType(PlatformNotSupportedException) Then Throw @@ -106,16 +84,6 @@ Namespace ExcelOpsTests.Engines End Try End Function - ''' - ''' 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) - ''' - ''' - ''' - ''' - Protected Function CreateInstance(data As System.IO.Stream, passwordForOpening As String) As T - Return Me.CreateInstance(data, passwordForOpening, False) - End Function - ''' ''' 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) ''' @@ -123,9 +91,9 @@ Namespace ExcelOpsTests.Engines ''' ''' ''' - Protected Function CreateInstance(data As System.IO.Stream, passwordForOpening As String, disableCalculationEngine As Boolean) As T + Protected Function CreateInstance(data As System.IO.Stream, options As ExcelOps.ExcelDataOperationsOptions) As T Try - Return _CreateInstance(data, passwordForOpening, disableCalculationEngine) + Return _CreateInstance(data, options) Catch ex As Exception If ex.GetType() Is GetType(PlatformNotSupportedException) Then Throw @@ -156,9 +124,9 @@ Namespace ExcelOpsTests.Engines ''' ''' True to disable calculation engine, e.g. sometimes required with some excel engines to load excel workbooks with circular reference errors successfully ''' - Protected Function CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableCalculationEngine As Boolean) As T + Protected Function CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As T Try - Return _CreateInstance(file, mode, [readOnly], passwordForOpening, disableCalculationEngine) + Return _CreateInstance(file, mode, options) Catch ex As Exception If ex.GetType() Is GetType(PlatformNotSupportedException) Then Throw @@ -183,7 +151,7 @@ Namespace ExcelOpsTests.Engines Public Sub CommonOneTimeSetup() Try - Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, True, Nothing)) + Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions)) Catch ex As PlatformNotSupportedException Assert.Ignore("Platform not supported: " & ex.Message) Catch ex As CompuMaster.ComInterop.ComApplicationNotAvailableException @@ -217,10 +185,10 @@ Namespace ExcelOpsTests.Engines Public Sub HasVbaProject() Dim VbaTestFile = TestEnvironment.FullPathOfExistingTestFile("test_data", "VbaProject.xlsm") - Assert.IsTrue(Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "").HasVbaProject) + Assert.IsTrue(Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions).HasVbaProject) Dim NonVbaTestFile = TestEnvironment.FullPathOfExistingTestFile("test_data", "ExcelOpsGrund01.xlsx") - Assert.IsFalse(Me.CreateInstance(NonVbaTestFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "").HasVbaProject) + Assert.IsFalse(Me.CreateInstance(NonVbaTestFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions).HasVbaProject) End Sub Public Sub SaveXlsxWithVbaProjectMustFail() @@ -232,7 +200,7 @@ Namespace ExcelOpsTests.Engines Dim NewXlsxTargetPath As String = TestEnvironment.FullPathOfDynTestFile(NameOf(SaveXlsxWithVbaProjectMustFail), "VbaProject.xlsx") System.IO.File.Copy(VbaTestFile, VbaTestFileClone) - Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "") + Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.True(Wb.HasVbaProject) Assert.Throws(Of NotSupportedException)(Sub() Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour)) Dim FilePathInEngineBefore As String = Wb.WorkbookFilePath @@ -247,7 +215,7 @@ Namespace ExcelOpsTests.Engines Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Wb.Close() - Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, "") + Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Assert.True(Wb.HasVbaProject) Wb.Save() Assert.True(Wb.HasVbaProject, "VBA project hasn't been removed automatically") @@ -262,12 +230,12 @@ Namespace ExcelOpsTests.Engines NewXlsxTargetPath = TestEnvironment.FullPathOfDynTestFile(NameOf(SaveXlsxWithVbaProjectMustFail), "NonVbaProject.xlsx") System.IO.File.Copy(NonVbaTestFile, NonVbaTestFileClone) - Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "") + Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.False(Wb.HasVbaProject) Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Wb.Close() - Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, "") + Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Assert.False(Wb.HasVbaProject) Wb.Save() Wb.Close() @@ -275,13 +243,13 @@ Namespace ExcelOpsTests.Engines 'Loading a workbook with VBA project + removing VBA project + saving workbook as XLSM + reloading workbook = must still HasVbaProject = False VbaTestFile = TestEnvironment.FullPathOfExistingTestFile("test_data", "VbaProject.xlsm") NewXlsxTargetPath = TestEnvironment.FullPathOfDynTestFile(NameOf(SaveXlsxWithVbaProjectMustFail), "VbaProject.xlsm") - Wb = Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "") + Wb = Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.True(Wb.HasVbaProject) Wb.RemoveVbaProject() Assert.False(Wb.HasVbaProject) Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Wb.Close() - Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "") + Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.False(Wb.HasVbaProject) End Sub @@ -294,10 +262,10 @@ Namespace ExcelOpsTests.Engines If GetType(T) Is GetType(MsExcelDataOperations) Then 'known to fail because no support for reading files from in-memory Assert.Throws(Of NotSupportedException)(Sub() - Me.CreateInstance(Data, "") + Me.CreateInstance(Data, New ExcelDataOperationsOptions) End Sub) Else - Wb = Me.CreateInstance(Data, "") + Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) Assert.That(Wb.ReadOnly, [Is].True) End If @@ -311,10 +279,10 @@ Namespace ExcelOpsTests.Engines If GetType(T) Is GetType(MsExcelDataOperations) Then 'known to fail because no support for reading files from in-memory Assert.Throws(Of NotSupportedException)(Sub() - Me.CreateInstance(Data, "") + Me.CreateInstance(Data, New ExcelDataOperationsOptions) End Sub) Else - Wb = Me.CreateInstance(Data, "") + Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) Assert.That(Wb.ReadOnly, [Is].True) End If @@ -324,7 +292,7 @@ Namespace ExcelOpsTests.Engines Dim Wb As T 'Testfile without password Dim TestFile As String = TestEnvironment.FullPathOfExistingTestFile("test_data", "ExcelOpsGrund01.xlsx") - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) 'Now, save it with password @@ -335,12 +303,12 @@ Namespace ExcelOpsTests.Engines Wb.Close() 'Try to reload it without password -> it must fail - Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "something else")) - Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "")) - Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing)) + Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = "something else"})) + Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = ""})) + Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = Nothing})) 'Reload it with password -> now it must succeed - Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "dummy") + Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = "dummy"}) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) End Sub @@ -355,13 +323,13 @@ Namespace ExcelOpsTests.Engines Wb.Close() TestFile = Nothing - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) Wb.Close() TestFile = "" - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Assert.AreEqual(Nothing, Wb.FilePath) Assert.AreEqual(Nothing, Wb.WorkbookFilePath) Wb.Close() @@ -373,7 +341,7 @@ Namespace ExcelOpsTests.Engines Dim TestFile2 As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, "created-workbook2.xlsx") 'Creating a new workbook without pre-defined file name must fail on Save(), but successful on SaveAs() - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Assert.AreEqual(TestFile = Nothing, Wb.ReadOnly, "Newly created files must be ReadOnly if file path hasn't been set up") Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(Nothing, Wb.WorkbookFilePath) @@ -386,12 +354,12 @@ Namespace ExcelOpsTests.Engines 'Creating a new workbook must fail with a pre-defined file name if there is already a file Assert.Throws(Of FileAlreadyExistsException)(Sub() - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) End Sub) System.IO.File.Delete(TestFile) 'Delete the file for next test block 'Creating a new workbook must always be ReadOnly and saving it without a name must be forbidden - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Assert.AreEqual(TestFile = Nothing, Wb.ReadOnly, "Newly created files must always be ReadOnly") Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(Nothing, Wb.WorkbookFilePath) @@ -410,7 +378,7 @@ Namespace ExcelOpsTests.Engines Assert.AreEqual(TestFile, Wb.WorkbookFilePath) 'Saving a ReadWrite file must be forbidden - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.AreEqual(True, Wb.ReadOnly) Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) @@ -423,7 +391,7 @@ Namespace ExcelOpsTests.Engines Wb.Close() 'Saving a ReadWrite file must be allowed - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, "") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) Assert.AreEqual(False, Wb.ReadOnly) Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) @@ -451,7 +419,7 @@ Namespace ExcelOpsTests.Engines End Select workbook.Close() - workbook = Me.CreateInstance(Nothing, ExcelDataOperationsBase.OpenMode.CreateFile, True, Nothing) + workbook = Me.CreateInstance(Nothing, ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions) Assert.AreEqual(1, workbook.SheetNames.Count, "Sheets Count") Assert.AreEqual("Sheet1", workbook.SheetNames(0)) workbook.Close() @@ -473,8 +441,8 @@ Namespace ExcelOpsTests.Engines Console.WriteLine("Test file output template: " & TestControllingToolFileNameOutTemplate) Console.WriteLine("Test file output: " & TestControllingToolFileNameOut) - eppeoIn = Me.CreateInstance(TestControllingToolFileNameIn, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) - eppeoOut = Me.CreateInstance(TestControllingToolFileNameOutTemplate, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeoIn = Me.CreateInstance(TestControllingToolFileNameIn, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeoOut = Me.CreateInstance(TestControllingToolFileNameOutTemplate, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Const SheetToCopy As String = "Grunddaten" eppeoIn.CopySheetContent(SheetToCopy, eppeoOut, ExcelOps.ExcelDataOperationsBase.CopySheetOption.TargetSheetMightExist) @@ -489,7 +457,7 @@ Namespace ExcelOpsTests.Engines End Sub Public Sub ExcelOpsTestCollection_ZahlenUndProzentwerte() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileExcelOpsTestCollection.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileExcelOpsTestCollection.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim SheetName As String SheetName = "ZahlenUndProzentwerte" Assert.AreEqual("0.00", eppeo.LookupCellFormat(SheetName, 0, 1)) @@ -505,7 +473,7 @@ Namespace ExcelOpsTests.Engines Public Sub IsMergedCell() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Const SheetName As String = "MergedCellsTest" Assert.True(eppeo.IsMergedCell(SheetName, 0, 0)) Assert.True(eppeo.IsMergedCell(SheetName, 1, 0)) @@ -520,7 +488,7 @@ Namespace ExcelOpsTests.Engines Public Sub MergeAndUnMergedCell() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Const SheetName As String = "MergedCellsTest" Assert.True(eppeo.IsMergedCell(SheetName, 0, 0)) Assert.True(eppeo.IsMergedCell(SheetName, 2, 2)) @@ -535,12 +503,12 @@ Namespace ExcelOpsTests.Engines Public Sub MergedCells() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim SheetName As String = "MergedCellsTest" Assert.AreEqual("A1:C3", String.Join(";"c, eppeo.MergedCells(SheetName).Select(Of String)(Function(x) x.LocalAddress))) TestControllingToolFileName = TestFiles.TestFileGrund01.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) SheetName = "Grunddaten" Assert.AreEqual("", String.Join(";"c, eppeo.MergedCells(SheetName).Select(Of String)(Function(x) x.LocalAddress))) End Sub @@ -548,7 +516,7 @@ Namespace ExcelOpsTests.Engines Public Sub AutoFitColumns() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Const SheetName As String = "MergedCellsTest" Try Assert.AreEqual(2, eppeo.LookupLastCell(SheetName).ColumnIndex) @@ -574,14 +542,14 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileGrund01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) EppeoSheetNamesList = eppeo.SheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) Assert.AreEqual("Grunddaten,Kostenplanung", Strings.Join(EppeoSheetNamesList.ToArray, ",")) TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) EppeoSheetNamesList = eppeo.SheetNames System.Console.WriteLine() System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) @@ -593,7 +561,7 @@ Namespace ExcelOpsTests.Engines Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.AreEqual(0, eppeo.SheetIndex("data")) Assert.AreEqual(1, eppeo.SheetIndex("chart")) Assert.AreEqual(-1, eppeo.SheetIndex("doesntexist")) @@ -605,7 +573,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) EppeoSheetNamesList = eppeo.WorkSheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) @@ -616,7 +584,7 @@ Namespace ExcelOpsTests.Engines Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.AreEqual(0, eppeo.WorkSheetIndex("data")) Assert.AreEqual(-1, eppeo.WorkSheetIndex("chart")) End Sub @@ -626,7 +594,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileGrund03.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Ausgewählt")) @@ -640,13 +608,13 @@ Namespace ExcelOpsTests.Engines System.Console.WriteLine("OUT: " & eppeo.FilePath) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Grunddaten")) - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) eppeo.SelectSheet(1) eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Ausgewählt.1.xlsx"), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) System.Console.WriteLine("OUT: " & eppeo.FilePath) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Ausgewählt")) - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) eppeo.SelectSheet(2) eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Kostenplanung.2.xlsx"), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) System.Console.WriteLine("OUT: " & eppeo.FilePath) @@ -657,7 +625,7 @@ Namespace ExcelOpsTests.Engines System.Console.WriteLine("OUT: " & eppeo.FilePath) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Grunddaten")) - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) eppeo.SelectSheet("Kostenplanung") eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Kostenplanung.xlsx"), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) System.Console.WriteLine("OUT: " & eppeo.FilePath) @@ -670,7 +638,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileHtmlExport01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Onboarding offen")) eppeo.SelectSheet("Upload erledigt") @@ -683,7 +651,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) EppeoSheetNamesList = eppeo.ChartSheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) @@ -694,7 +662,7 @@ Namespace ExcelOpsTests.Engines Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.AreEqual(0, eppeo.ChartSheetIndex("chart")) Assert.AreEqual(-1, eppeo.ChartSheetIndex("data")) End Sub @@ -707,7 +675,7 @@ Namespace ExcelOpsTests.Engines Dim BeforeSheet As String = "Grunddaten" Dim SheetNameTopPosition As String = "SheetOnTop" Dim SheetNameBottomPosition As String = "SheetOnBottom" - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim ExpectedSheetNamesList, NewSheetNamesList As List(Of String) ExpectedSheetNamesList = eppeo.SheetNames ExpectedSheetNamesList.Add(SheetNameBottomPosition) @@ -725,7 +693,7 @@ Namespace ExcelOpsTests.Engines Dim AllFormulas As List(Of ExcelOps.TextTableCell) TestControllingToolFileName = TestFiles.TestFileGrund01.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) AllFormulas = eppeo.AllFormulasOfWorkbook Console.WriteLine("Test file: " & TestControllingToolFileName) Assert.NotZero(AllFormulas.Count) @@ -750,7 +718,7 @@ Namespace ExcelOpsTests.Engines End Sub Public Sub CellWithError() - Dim wb As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileGrund02.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim wb As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileGrund02.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim SheetName As String = wb.SheetNames(0) wb.WriteCellFormula(SheetName, 0, 0, "B2", False) @@ -790,7 +758,7 @@ Namespace ExcelOpsTests.Engines Dim TestControllingToolFileName As String = TestFiles.TestFileGrund01.FullName Dim TestSheet As String = "Grunddaten" - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.AreEqual("E40", eppeo.LookupLastCell(TestSheet).Address) Assert.AreEqual(39, eppeo.LookupLastRowIndex(TestSheet)) Assert.AreEqual(4, eppeo.LookupLastColumnIndex(TestSheet)) @@ -801,7 +769,7 @@ Namespace ExcelOpsTests.Engines Assert.AreEqual(9, eppeo.LookupLastColumnIndex(TestSheet)) TestControllingToolFileName = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) TestSheet = "MergedCellsTest" Assert.AreEqual("C3", eppeo.LookupLastCell(TestSheet).Address) Assert.AreEqual(2, eppeo.LookupLastRowIndex(TestSheet)) @@ -813,7 +781,7 @@ Namespace ExcelOpsTests.Engines Dim TestControllingToolFileName As String = TestFiles.TestFileGrund01.FullName Dim TestSheet As String = "Grunddaten" - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Assert.AreEqual("E40", eppeo.LookupLastContentCell(TestSheet).Address) Assert.AreEqual(39, eppeo.LookupLastContentRowIndex(TestSheet)) Assert.AreEqual(4, eppeo.LookupLastContentColumnIndex(TestSheet)) @@ -825,7 +793,7 @@ Namespace ExcelOpsTests.Engines Assert.AreEqual(8, eppeo.LookupLastContentColumnIndex(TestSheet)) TestControllingToolFileName = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) TestSheet = "MergedCellsTest" Assert.AreEqual("C3", eppeo.LookupLastContentCell(TestSheet).Address) Assert.AreEqual(2, eppeo.LookupLastContentRowIndex(TestSheet)) @@ -875,7 +843,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -932,7 +900,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -988,7 +956,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) ExpectedMatrix = "# |A |B |C |D " & ControlChars.CrLf & @@ -1045,7 +1013,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -1103,7 +1071,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -1169,7 +1137,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) '## Expected matrix like following '"# |A |B |C |D |E @@ -1220,7 +1188,7 @@ Namespace ExcelOpsTests.Engines #Region "ExcelCharting" Private Function PrepareAndFillExcelFileWithChart(variantOfImage As Byte) As ExcelOps.ExcelDataOperationsBase Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileChartSheet01.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Select Case variantOfImage Case 0 'master Workbook.WriteCellValue(Of String)(New ExcelCell("data", "B1", ExcelCell.ValueTypes.All), "Sample Chart") @@ -1321,7 +1289,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable) '## Expected matrix like following @@ -1353,7 +1321,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable) '## Expected matrix like following @@ -1390,7 +1358,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithEmbeddedPicture01() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileEmbeddedPicture01.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture01.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1416,7 +1384,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithEmbeddedPicture02() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileEmbeddedPicture02.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture02.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1442,7 +1410,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithEmbeddedPicture03() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileEmbeddedPicture03.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture02.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1471,26 +1439,56 @@ Namespace ExcelOpsTests.Engines Dim CatchedEx As Exception = Nothing Try - Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing) + Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Catch ex As Exception CatchedEx = ex Workbook = Me.CreateInstance() End Try Select Case Workbook.EngineName Case "Epplus 4 (LGPL)" - Assert.AreEqual(False, Workbook.AutoCalculationOnLoad) - Assert.Null(CatchedEx) - Assert.NotNull(Workbook.FilePath) + Assert.Multiple( + Sub() + Assert.AreEqual(True, Workbook.DefaultCalculationOptions.DisableCalculationEngine, "DefaultCalculationOptions.DisableCalculationEngine") + Assert.AreEqual(False, Workbook.DefaultCalculationOptions.DisableInitialCalculation, "DefaultCalculationOptions.DisableInitialCalculation") + Assert.AreEqual(True, Workbook.CalculationModuleDisabled, "CalculationModuleDisabled") + Assert.AreEqual(True, Workbook.AutoCalculationEnabledWorkbookSetting, "AutoCalculationEnabledWorkbookSetting") + Assert.AreEqual(True, Workbook.AutoCalculationOnLoad, "AutoCalculationOnLoad") + Assert.AreEqual(False, Workbook.AutoCalculationOnLoadEffectively, "AutoCalculationOnLoadEffectively") + Assert.Null(CatchedEx) + Assert.NotNull(Workbook.FilePath) + End Sub) Case "Epplus (Polyform license edition)" - Assert.Null(Workbook.FilePath) - Assert.AreEqual(False, Workbook.AutoCalculationOnLoad) - Assert.AreEqual("Circular Reference in cell CircularRefTest!B2", CatchedEx.Message) - Assert.AreEqual("OfficeOpenXml.FormulaParsing.Exceptions.CircularReferenceException", CatchedEx.GetType.FullName) + Assert.Multiple( + Sub() + 'Assert.Null(Workbook.FilePath) + Assert.AreEqual(False, Workbook.DefaultCalculationOptions.DisableCalculationEngine, "DefaultCalculationOptions.DisableCalculationEngine") + Assert.AreEqual(True, Workbook.DefaultCalculationOptions.DisableInitialCalculation, "DefaultCalculationOptions.DisableInitialCalculation") + Assert.AreEqual(False, Workbook.CalculationModuleDisabled, "CalculationModuleDisabled") + Assert.AreEqual(True, Workbook.AutoCalculationEnabledWorkbookSetting, "AutoCalculationEnabledWorkbookSetting") + Assert.AreEqual(False, Workbook.AutoCalculationOnLoad, "AutoCalculationOnLoad") + Assert.AreEqual(False, Workbook.AutoCalculationOnLoadEffectively, "AutoCalculationOnLoadEffectively") + Assert.Null(CatchedEx, "CatchedEx on AutoCalculationOnLoadEffectively") + Try + Workbook.RecalculateAll() + Catch ex As Exception + CatchedEx = ex + End Try + Assert.AreEqual("Circular Reference in cell CircularRefTest!B2", CatchedEx.Message, "CatchedEx on RecalculateAll") + Assert.AreEqual("OfficeOpenXml.FormulaParsing.Exceptions.CircularReferenceException", CatchedEx.GetType.FullName) + End Sub) Case Else Console.WriteLine("Workbook.EngineName=" & Workbook.EngineName) - Assert.AreEqual(True, Workbook.AutoCalculationOnLoad) - Assert.Null(CatchedEx) - Assert.NotNull(Workbook.FilePath) + Assert.Multiple( + Sub() + Assert.AreEqual(False, Workbook.DefaultCalculationOptions.DisableCalculationEngine, "DefaultCalculationOptions.DisableCalculationEngine") + Assert.AreEqual(False, Workbook.DefaultCalculationOptions.DisableInitialCalculation, "DefaultCalculationOptions.DisableInitialCalculation") + Assert.AreEqual(False, Workbook.CalculationModuleDisabled, "CalculationModuleDisabled") + Assert.AreEqual(True, Workbook.AutoCalculationEnabledWorkbookSetting, "AutoCalculationEnabledWorkbookSetting") + Assert.AreEqual(True, Workbook.AutoCalculationOnLoad, "AutoCalculationOnLoad") + Assert.AreEqual(True, Workbook.AutoCalculationOnLoadEffectively, "AutoCalculationOnLoadEffectively") + Assert.Null(CatchedEx) + Assert.NotNull(Workbook.FilePath) + End Sub) End Select Catch ex As PlatformNotSupportedException 'System.Drawing.Common is not supported on platform @@ -1512,7 +1510,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithCircularReference01_LoadAndResaveWithDisabledCalculationEngine() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileCircularReference01.FullName) - Dim Workbook As T = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Workbook As T = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions("", True, True, True)) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_circularref01_rewritten.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) Catch ex As PlatformNotSupportedException @@ -1535,7 +1533,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithCircularReference01_LoadAndRecalculateOnEnabledCalculationEngine() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileCircularReference01.FullName) - Dim Workbook As T = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Workbook As T = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions("", True, True, False)) Dim CatchedEx As Exception = Nothing Try If Workbook.CalculationModuleDisabled = False Then @@ -1577,7 +1575,7 @@ Namespace ExcelOpsTests.Engines System.Console.WriteLine("TEST IN FILE: " & TestXlsxFile.FullName) Try - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.JumpToAnchor}) @@ -1602,7 +1600,7 @@ Namespace ExcelOpsTests.Engines Try With Nothing - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".nav-anchor.html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.JumpToAnchor}) @@ -1614,7 +1612,7 @@ Namespace ExcelOpsTests.Engines End If End With With Nothing - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".nav-anchor-fixed-on-top.html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.JumpToAnchor, .SheetNavigationAlwaysVisible = True}) @@ -1626,7 +1624,7 @@ Namespace ExcelOpsTests.Engines End If End With With Nothing - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".nav-switch.html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.SwitchVisibleSheet}) @@ -1655,7 +1653,7 @@ Namespace ExcelOpsTests.Engines Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Nothing Try - Wb = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + Wb = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) Catch ex As TypeInitializationException Assert.Ignore("Not supported on this platform " & System.Environment.OSVersion.Platform.ToString) End Try diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb index 3118019..246b6de 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb @@ -1,4 +1,5 @@ -Imports NUnit.Framework +Imports CompuMaster.Excel.ExcelOps +Imports NUnit.Framework Namespace ExcelOpsTests.Engines @@ -8,14 +9,14 @@ Namespace ExcelOpsTests.Engines Public Overrides ReadOnly Property ExpectedEngineName As String = "Microsoft Excel (2013 or higher)" - Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) As ExcelOps.MsExcelDataOperations + Protected Overrides Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.MsExcelDataOperations If MsExcelInstance Is Nothing OrElse MsExcelInstance.IsDisposed Then 'recreate excel instance MsExcelInstance = New CompuMaster.Excel.MsExcelCom.MsExcelApplicationWrapper ElseIf AlwaysCloseAllWorkbooksInNewEngineInstances Then MsExcelInstance.Workbooks.CloseAllWorkbooks() End If - Return New ExcelOps.MsExcelDataOperations(file, mode, MsExcelInstance, False, [readOnly], passwordForOpening) With {.AutoCalculationEnabled = Not disableInitialCalculation} + Return New ExcelOps.MsExcelDataOperations(file, mode, MsExcelInstance, False, New ExcelDataOperationsOptions) End Function Protected Overrides Function _CreateInstance() As ExcelOps.MsExcelDataOperations @@ -25,7 +26,7 @@ Namespace ExcelOpsTests.Engines ElseIf AlwaysCloseAllWorkbooksInNewEngineInstances Then MsExcelInstance.Workbooks.CloseAllWorkbooks() End If - Return New ExcelOps.MsExcelDataOperations(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, MsExcelInstance, False, True, Nothing) + Return New ExcelOps.MsExcelDataOperations(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, MsExcelInstance, False, New ExcelDataOperationsOptions) End Function @@ -119,11 +120,11 @@ Namespace ExcelOpsTests.Engines MsExcelInstance.SetCultureContext(System.Threading.Thread.CurrentThread.CurrentCulture) End Sub - Protected Overrides Function _CreateInstance(data() As Byte, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.MsExcelDataOperations + Protected Overrides Function _CreateInstance(data() As Byte, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.MsExcelDataOperations Throw New NotSupportedException End Function - Protected Overrides Function _CreateInstance(data As IO.Stream, passwordForOpening As String, disableCalculationEngine As Boolean) As ExcelOps.MsExcelDataOperations + Protected Overrides Function _CreateInstance(data As IO.Stream, options As ExcelOps.ExcelDataOperationsOptions) As ExcelOps.MsExcelDataOperations Throw New NotSupportedException End Function End Class diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb index 08bed88..d13c2fb 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb @@ -46,7 +46,7 @@ Namespace ExcelOpsTests.MsExcelSpecials End Sub Public Sub OpenAnCloseMsExcelWithProperProcessCleanup_SeparateMsExcelAppWithExplicitQuit() - Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, True, Nothing) + Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, New ExcelDataOperationsOptions) DummyCTWb.CloseExcelAppInstance() Dim MsExcelProcessesAfterExplicitQuit As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("EXCEL") Assert.AreEqual(MsExcelProcessesAfterExplicitQuit.Length, MsExcelProcessesAfterExplicitQuit.Length, "Process count after ExcelApp.Quit") @@ -55,7 +55,7 @@ Namespace ExcelOpsTests.MsExcelSpecials ' Public Sub OpenAnCloseMsExcelWithPropertProcessCleanup_SeparateMsExcelApp( explicitlyCloseMsExcelAppInstance As Boolean) Dim Dummy = Sub() - Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, True, Nothing) + Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, New ExcelDataOperationsOptions) #Disable Warning IDE0059 ' Unnötige Zuweisung eines Werts. If explicitlyCloseMsExcelAppInstance Then DummyCTWb.CloseExcelAppInstance() DummyCTWb = Nothing @@ -72,8 +72,8 @@ Namespace ExcelOpsTests.MsExcelSpecials Public Sub OpenAnCloseMsExcelWithPropertProcessCleanup_ReusedMsExcelApp( explicitlyCloseMsExcelAppInstance As Boolean) Dim Dummy = Sub() Dim MsExcelApp As New MsExcelApplicationWrapper() - Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, True, Nothing) - Dim DummyCTWb2 As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, True, Nothing) + Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions) + Dim DummyCTWb2 As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions) #Disable Warning IDE0059 ' Unnötige Zuweisung eines Werts. DummyCTWb = Nothing DummyCTWb2 = Nothing diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb index 9f89652..6bb81eb 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb @@ -21,7 +21,7 @@ Namespace ExcelOpsTests.MsExcelSpecials End Property Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase - Return New ExcelOps.EpplusFreeExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, String.Empty) + Return New ExcelOps.EpplusFreeExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions()) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb index 721718b..11c29ce 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb @@ -22,7 +22,7 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase ExcelOpsTests.Engines.EpplusPolyformEditionOpsTest.AssignLicenseContext() - Return New ExcelOps.EpplusPolyformExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, String.Empty) + Return New ExcelOps.EpplusPolyformExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/README.md b/README.md index 2ff87f0..71ab59d 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ TextTable formulasOrValues; TextTable values; //Create a workbook and put some values and formulas -ExcelDataOperationsBase workbook = new EpplusFreeExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +ExcelDataOperationsBase workbook = new EpplusFreeExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); workbook.WriteCellValue(new ExcelCell(FirstSheetName, "B1", ExcelCell.ValueTypes.All), 456.123); @@ -120,7 +120,7 @@ TextTable values; EpplusPolyformExcelDataOperations.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial; //Create a workbook and put some values and formulas -workbook = new EpplusPolyformExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +workbook = new EpplusPolyformExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); workbook.WriteCellValue(new ExcelCell(FirstSheetName, "B1", ExcelCell.ValueTypes.All), 456.123); @@ -161,7 +161,7 @@ TextTable formulasOrValues; TextTable values; //Create a workbook and put some values and formulas -workbook = new FreeSpireXlsDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +workbook = new FreeSpireXlsDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); workbook.WriteCellValue(new ExcelCell(FirstSheetName, "B1", ExcelCell.ValueTypes.All), 456.123); @@ -202,7 +202,7 @@ TextTable formulasOrValues; TextTable values; //Create a workbook and put some values and formulas -workbook = new MsExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +workbook = new MsExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); workbook.WriteCellValue(new ExcelCell(FirstSheetName, "B1", ExcelCell.ValueTypes.All), 456.123); diff --git a/TestAndDemoExcelOps/Program.cs b/TestAndDemoExcelOps/Program.cs index 3109341..53fe160 100644 --- a/TestAndDemoExcelOps/Program.cs +++ b/TestAndDemoExcelOps/Program.cs @@ -6,7 +6,7 @@ TextTable values; //Create a workbook and put some values and formulas -workbook = new EpplusFreeExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +workbook = new EpplusFreeExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); @@ -27,7 +27,7 @@ EpplusPolyformExcelDataOperations.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial; //Create a workbook and put some values and formulas -workbook = new EpplusPolyformExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +workbook = new EpplusPolyformExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); @@ -46,7 +46,7 @@ /* //Create a workbook and put some values and formulas -workbook = new FreeSpireXlsDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +workbook = new FreeSpireXlsDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); @@ -65,7 +65,7 @@ //Create a workbook and put some values and formulas -workbook = new MsExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, true, null); +workbook = new MsExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); From d18005479ab9fe72cbe84ef152d30ea547c88d54 Mon Sep 17 00:00:00 2001 From: Jochen Wezel Date: Thu, 18 Dec 2025 16:31:23 +0100 Subject: [PATCH 2/7] fixed several issues --- .../EpplusFreeExcelDataOperations.vb | 24 ++- .../EpplusPolyformExcelDataOperations.vb | 16 +- .../FreeSpireXlsDataOperations.vb | 20 ++- .../ComWrappers/MsExcelTools.vb | 2 +- .../ExcelOpsLowLevel/MsExcelDataOperations.vb | 27 ++-- ExcelOps-SpireXls/SpireXlsDataOperations.vb | 26 ++- .../ExcelDataOperationsBase.vb | 80 ++++++--- .../ExcelDataOperationsOptions.vb | 14 +- .../FreeSpireXlsOpsTest.vb | 2 +- .../MsExcelCalcTestFreeSpireXls.vb | 6 +- .../ExcelOpsTests.Engines/SpireXlsOpsTest.vb | 9 +- .../MsExcelCalcTestSpireXls.vb | 6 +- .../EpplusFreeFixCalcsEditionOpsTest.vb | 5 +- .../EpplusPolyformEditionOpsTest.vb | 2 +- .../ExcelOpsTests.Engines/ExcelOpsTestBase.vb | 152 +++++++++--------- .../ExcelOpsTests.Engines/MsExcelOpsTest.vb | 4 +- .../MsExcelAppReleaseTest.vb | 14 +- .../MsExcelCalcTestBase.vb | 12 +- .../MsExcelCalcTestEpplusFree.vb | 6 +- .../MsExcelCalcTestEpplusPolyform.vb | 6 +- TestAndDemoExcelOps/Program.cs | 6 +- 21 files changed, 269 insertions(+), 170 deletions(-) diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb index fadd6a7..f08a599 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb @@ -39,6 +39,23 @@ Namespace ExcelOps MyBase.New(file, mode, options) End Sub + ''' + ''' Create a new workbook or just create an uninitialized instance of this Excel engine + ''' + ''' + Public Sub New(mode As OpenMode) + MyBase.New(mode) + End Sub + + ''' + ''' Create a new workbook or just create an uninitialized instance of this Excel engine + ''' + ''' + ''' + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(mode, options) + End Sub + ''' ''' Open a workbook ''' @@ -111,13 +128,6 @@ Namespace ExcelOps MyBase.New(data, Not disableInitialCalculation, True, passwordForOpening) End Sub - ''' - ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) - ''' - Friend Sub New() - MyBase.New(New ExcelDataOperationsOptions) - End Sub - ''' ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' diff --git a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb index 037901f..45a331d 100644 --- a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb +++ b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb @@ -171,10 +171,20 @@ Namespace ExcelOps End Sub ''' - ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) + ''' Create a new workbook or just create an uninitialized instance of this Excel engine + ''' + ''' + Public Sub New(mode As OpenMode) + MyBase.New(mode) + End Sub + + ''' + ''' Create a new workbook or just create an uninitialized instance of this Excel engine ''' - Friend Sub New() - MyBase.New(New ExcelDataOperationsOptions) + ''' + ''' + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(mode, options) End Sub ''' diff --git a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb index 8cc269c..818ca3f 100644 --- a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb +++ b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb @@ -118,14 +118,28 @@ Namespace ExcelOps End Sub ''' - ''' 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) + ''' Create a new workbook or just create an uninitialized instance of this Excel engine ''' + ''' + ''' + ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. + ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. + ''' + Public Sub New(mode As OpenMode) + MyBase.New(mode) + End Sub + + ''' + ''' Create a new workbook or just create an uninitialized instance of this Excel engine + ''' + ''' + ''' ''' ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' - Friend Sub New() - MyBase.New(New ExcelDataOperationsOptions) + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(mode, options) End Sub ''' diff --git a/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb b/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb index 4972bd8..0bdd3c9 100644 --- a/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb +++ b/ExcelOps-MicrosoftExcel/ComWrappers/MsExcelTools.vb @@ -33,7 +33,7 @@ Namespace Global.CompuMaster.Excel.MsExcelCom If MsExcelApp Is Nothing Then MsExcelApp = New MsExcelApplicationWrapper() End If - Dim wb As New ExcelOps.MsExcelDataOperations(filePath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Dim wb As New ExcelOps.MsExcelDataOperations(filePath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Try wb.RecalculateAll() wb.Save() diff --git a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb index a58d2af..ea46b48 100644 --- a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb +++ b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb @@ -47,9 +47,12 @@ Namespace Global.CompuMaster.Excel.ExcelOps End Property ''' - ''' Class for holding a reference to Excel.Application (ATTENTION: watch for advised Try-Finally pattern!) + ''' Create a new workbook or just create an uninitialized instance of this Excel engine ''' - ''' Use with pattern + ''' + ''' + ''' For holding a reference to Excel.Application (ATTENTION: watch for advised Try-Finally pattern!) + ''' Use with pattern ''' ''' Dim MsExcelOps As New MsExcelDataOperations(fileName) ''' Try @@ -59,16 +62,18 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - - - Public Sub New(passwordForOpeningOnNextTime As String) - Me.New(Nothing, OpenMode.CreateFile, False, True, passwordForOpeningOnNextTime) + Public Sub New(mode As OpenMode) + MyBase.New(mode) End Sub ''' - ''' Class for holding a reference to Excel.Application (ATTENTION: watch for advised Try-Finally pattern!) + ''' Create a new workbook or just create an uninitialized instance of this Excel engine ''' - ''' Use with pattern + ''' + ''' + ''' + ''' For holding a reference to Excel.Application (ATTENTION: watch for advised Try-Finally pattern!) + ''' Use with pattern ''' ''' Dim MsExcelOps As New MsExcelDataOperations(fileName) ''' Try @@ -78,8 +83,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - Friend Sub New() - MyBase.New(New ExcelDataOperationsOptions) + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(mode, options) End Sub ''' @@ -260,7 +265,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps Me.LoadAndInitializeWorkbookFile(file, options) Case OpenMode.CreateFile Me.CreateAndInitializeWorkbookFile(file, options) - Me.ReadOnly = [ReadOnly] OrElse (file = Nothing) + Me.ReadOnly = Me.[ReadOnly] OrElse (file = Nothing) Case Else Throw New ArgumentOutOfRangeException(NameOf(mode)) End Select diff --git a/ExcelOps-SpireXls/SpireXlsDataOperations.vb b/ExcelOps-SpireXls/SpireXlsDataOperations.vb index b11596e..0c453fb 100644 --- a/ExcelOps-SpireXls/SpireXlsDataOperations.vb +++ b/ExcelOps-SpireXls/SpireXlsDataOperations.vb @@ -34,6 +34,7 @@ Namespace ExcelOps ''' Public Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) MyBase.New(file, mode, options) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub ''' @@ -43,6 +44,7 @@ Namespace ExcelOps ''' File and engine options Public Sub New(data As Byte(), options As ExcelDataOperationsOptions) MyBase.New(data, options) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub ''' @@ -52,6 +54,7 @@ Namespace ExcelOps ''' File and engine options Public Sub New(data As System.IO.Stream, options As ExcelDataOperationsOptions) MyBase.New(data, options) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub ''' @@ -88,32 +91,47 @@ Namespace ExcelOps Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub ''' - ''' 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) + ''' Create a new workbook or just create an uninitialized instance of this Excel engine ''' - ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ - Friend Sub New() - MyBase.New(New ExcelDataOperationsOptions) + ''' + Public Sub New(mode As OpenMode) + MyBase.New(mode) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") + End Sub + + ''' + ''' Create a new workbook or just create an uninitialized instance of this Excel engine + ''' + ''' + ''' + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(mode, options) + If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub ''' diff --git a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb index d69d037..02e9887 100644 --- a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb @@ -3,6 +3,7 @@ Option Strict On Imports System.IO Imports System.Text +Imports CompuMaster.Excel.ExcelOps.ExcelDataOperationsOptions Namespace ExcelOps @@ -12,8 +13,18 @@ Namespace ExcelOps Public MustInherit Class ExcelDataOperationsBase Public Enum OpenMode As Byte + ''' + ''' Open an existing workbook from file + ''' OpenExistingFile = 0 + ''' + ''' Create a new workbook + ''' CreateFile = 1 + ''' + ''' Just create the engine instance, but don't create or load a workbook explicitly (except the Excel engine automatically creates a new workbook implicitly) + ''' + Uninitialized = 255 End Enum ''' @@ -24,20 +35,45 @@ Namespace ExcelOps ''' File and engine options Protected Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) Me.New(options) - If mode = OpenMode.OpenExistingFile AndAlso file = Nothing Then - Throw New ArgumentNullException(NameOf(file), "File path must be provided when opening an existing file") - End If Select Case mode Case OpenMode.OpenExistingFile + If file = Nothing Then Throw New ArgumentNullException(NameOf(file), "File path must be provided when opening an existing file") + If options.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile Then Throw New NotSupportedException("Option's WriteProtectionMode property must not be equal to " & WriteProtectionMode.DefaultBehaviourOnCreateFile.ToString) Me.LoadAndInitializeWorkbookFile(file, options) Case OpenMode.CreateFile Me.CreateAndInitializeWorkbookFile(file, options) - Me.ReadOnly = [ReadOnly] OrElse (file = Nothing) + If options.FileWriteProtection = WriteProtectionMode.DefaultBehaviourOnCreateFile Then + Me.ReadOnly = (file = Nothing) + End If + Case OpenMode.Uninitialized + 'do nothing Case Else - Throw New ArgumentOutOfRangeException(NameOf(mode)) + Throw New NotImplementedException("OpenMode not implemented: " & mode.ToString) End Select End Sub + ''' + ''' Create a new workbook or just create an uninitialized instance of this Excel engine + ''' + ''' + Public Sub New(mode As OpenMode) + Me.New("", OpenModeMustNotBeOpenExistingFile(mode), New ExcelDataOperationsOptions(WriteProtectionMode.DefaultBehaviourOnCreateFile)) + End Sub + + ''' + ''' Create a new workbook or just create an uninitialized instance of this Excel engine + ''' + ''' + ''' + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + Me.New("", OpenModeMustNotBeOpenExistingFile(mode), options) + End Sub + + Private Shared Function OpenModeMustNotBeOpenExistingFile(mode As OpenMode) As OpenMode + If mode = OpenMode.OpenExistingFile Then Throw New ArgumentOutOfRangeException(NameOf(mode), "Mode " & mode.ToString & " not supported for this constructor overload") + Return mode + End Function + ''' ''' Open a workbook ''' @@ -86,8 +122,10 @@ Namespace ExcelOps ''' ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' + + Private Sub New() - Me.New(New ExcelDataOperationsOptions) + Me.New(New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) End Sub ''' @@ -114,8 +152,8 @@ Namespace ExcelOps ''' ''' ''' - - + + Protected Sub New(file As String, mode As OpenMode, autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, [readOnly], passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) @@ -142,8 +180,8 @@ Namespace ExcelOps ''' ''' ''' - - + + Protected Sub New(data As Byte(), autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, True, passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) @@ -162,8 +200,8 @@ Namespace ExcelOps ''' ''' ''' - - + + Protected Sub New(data As System.IO.Stream, autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, True, passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) @@ -180,8 +218,8 @@ Namespace ExcelOps ''' ''' Automatically do a full recalculation after workbook has been loaded ''' Disables the Excel calculation engine - - + + Protected Sub New(autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, [readOnly], passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) @@ -264,8 +302,8 @@ Namespace ExcelOps ''' ''' ''' Please note: this property is a workbook property (not an engine property!) - - + + Public Property AutoCalculationEnabled As Boolean Get Return AutoCalculationEnabledWorkbookSetting @@ -392,7 +430,7 @@ Namespace ExcelOps ''' Apply CachedCalculation setting ''' ''' - + Protected Overridable Sub SaveInternal_ApplyCachedCalculationOption(cachedCalculationsOption As SaveOptionsForDisabledCalculationEngines) If cachedCalculationsOption = SaveOptionsForDisabledCalculationEngines.DefaultBehaviour Then cachedCalculationsOption = SaveOptionsForDisabledCalculationEngines.NoReset @@ -419,8 +457,8 @@ Namespace ExcelOps ''' ''' ''' Depending on AutoCalculationResetToEnabledForAllSavedWorkbooks, AutoCalculationEnabledWorkbookSetting will be reset to True in saved workbook - - + + Public Sub SaveAs(filePath As String) Me.SaveAs(filePath, SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) End Sub @@ -1860,8 +1898,8 @@ Namespace ExcelOps Dim adj As Func(Of Integer, Integer) = Function(ch As Integer) Dim v As Double - If tint < 0 Then - v = ch * (1.0 + tint) ' dunkler + If tint <0 Then + v= ch * (1.0 + tint) ' dunkler Else v = ch * (1.0 - tint) + 255.0 * tint ' heller End If diff --git a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb index 9a27131..00e9b0d 100644 --- a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb @@ -11,12 +11,6 @@ Namespace ExcelOps ''' Public Class ExcelDataOperationsOptions - ''' - ''' Create a new options instance - ''' - Public Sub New() - End Sub - Public Sub New(fileProtection As WriteProtectionMode) Me.FileWriteProtection = fileProtection End Sub @@ -62,14 +56,18 @@ Namespace ExcelOps End Sub Public Enum WriteProtectionMode As Byte + ''' + ''' If a file path is present, ReadWrite mode is enabled, without a file path, ReadOnly mode is active + ''' + DefaultBehaviourOnCreateFile = 0 ''' ''' File can't be saved (saving with same file name is forbidden), but SaveAs with another file name is allowed ''' - [ReadOnly] = 0 + [ReadOnly] = 1 ''' ''' No limitation ''' - ReadWrite = 1 + ReadWrite = 4 End Enum ''' diff --git a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb index 57b7293..2da7fec 100644 --- a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb +++ b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb @@ -13,7 +13,7 @@ Namespace ExcelOpsTests.Engines End Function Protected Overrides Function _CreateInstance() As ExcelOps.FreeSpireXlsDataOperations - Return New ExcelOps.FreeSpireXlsDataOperations() + Return New ExcelOps.FreeSpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() diff --git a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb index cbda916..32c8113 100644 --- a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb +++ b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestFreeSpireXls.vb @@ -15,13 +15,13 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected Overrides ReadOnly Property EngineName As String Get Static Result As String - If Result Is Nothing Then Result = (New ExcelOps.FreeSpireXlsDataOperations()).EngineName + If Result Is Nothing Then Result = (New ExcelOps.FreeSpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName Return Result End Get End Property - Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase - Return New ExcelOps.FreeSpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions()) + Protected Overrides Function CreateEngineInstanceWithCreateFileMode(testFile As String) As ExcelOps.ExcelDataOperationsBase + Return New ExcelOps.FreeSpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb b/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb index 262ab15..0494186 100644 --- a/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb +++ b/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb @@ -1,4 +1,5 @@ -Imports NUnit.Framework +Imports CompuMaster.Excel.ExcelOps +Imports NUnit.Framework Namespace ExcelOpsTests.Engines @@ -16,7 +17,7 @@ Namespace ExcelOpsTests.Engines End Function Protected Overrides Function _CreateInstance() As ExcelOps.SpireXlsDataOperations - Return New ExcelOps.SpireXlsDataOperations() + Return New ExcelOps.SpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() @@ -37,12 +38,12 @@ Namespace ExcelOpsTests.Engines 'Simulation: license assigned ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = True Assert.NotNull(Me.CreateInstance) - Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions)) + Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile))) 'No license assigned -> instancing must fail ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = False Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance()) - Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions)) + Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile))) End Sub diff --git a/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb b/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb index fe73ddb..00d43c1 100644 --- a/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb +++ b/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb @@ -15,13 +15,13 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected Overrides ReadOnly Property EngineName As String Get Static Result As String - If Result Is Nothing Then Result = (New ExcelOps.SpireXlsDataOperations()).EngineName + If Result Is Nothing Then Result = (New ExcelOps.SpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName Return Result End Get End Property - Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase - Return New ExcelOps.SpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions) + Protected Overrides Function CreateEngineInstanceWithCreateFileMode(testFile As String) As ExcelOps.ExcelDataOperationsBase + Return New ExcelOps.SpireXlsDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb index 338a62e..ce5c4da 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb @@ -1,4 +1,5 @@ -Imports NUnit.Framework +Imports CompuMaster.Excel.ExcelOps +Imports NUnit.Framework Namespace ExcelOpsTests.Engines @@ -13,7 +14,7 @@ Namespace ExcelOpsTests.Engines End Function Protected Overrides Function _CreateInstance() As ExcelOps.EpplusFreeExcelDataOperations - Return New ExcelOps.EpplusFreeExcelDataOperations() + Return New ExcelOps.EpplusFreeExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb index e1b39b5..a0ea926 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb @@ -21,7 +21,7 @@ Namespace ExcelOpsTests.Engines End Function Protected Overrides Function _CreateInstance() As ExcelOps.EpplusPolyformExcelDataOperations - Return New ExcelOps.EpplusPolyformExcelDataOperations() + Return New ExcelOps.EpplusPolyformExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb b/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb index 4aae414..a0798f3 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb @@ -151,7 +151,7 @@ Namespace ExcelOpsTests.Engines Public Sub CommonOneTimeSetup() Try - Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions)) + Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly))) Catch ex As PlatformNotSupportedException Assert.Ignore("Platform not supported: " & ex.Message) Catch ex As CompuMaster.ComInterop.ComApplicationNotAvailableException @@ -185,10 +185,10 @@ Namespace ExcelOpsTests.Engines Public Sub HasVbaProject() Dim VbaTestFile = TestEnvironment.FullPathOfExistingTestFile("test_data", "VbaProject.xlsm") - Assert.IsTrue(Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions).HasVbaProject) + Assert.IsTrue(Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)).HasVbaProject) Dim NonVbaTestFile = TestEnvironment.FullPathOfExistingTestFile("test_data", "ExcelOpsGrund01.xlsx") - Assert.IsFalse(Me.CreateInstance(NonVbaTestFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions).HasVbaProject) + Assert.IsFalse(Me.CreateInstance(NonVbaTestFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)).HasVbaProject) End Sub Public Sub SaveXlsxWithVbaProjectMustFail() @@ -200,7 +200,7 @@ Namespace ExcelOpsTests.Engines Dim NewXlsxTargetPath As String = TestEnvironment.FullPathOfDynTestFile(NameOf(SaveXlsxWithVbaProjectMustFail), "VbaProject.xlsx") System.IO.File.Copy(VbaTestFile, VbaTestFileClone) - Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.True(Wb.HasVbaProject) Assert.Throws(Of NotSupportedException)(Sub() Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour)) Dim FilePathInEngineBefore As String = Wb.WorkbookFilePath @@ -215,7 +215,7 @@ Namespace ExcelOpsTests.Engines Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Wb.Close() - Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Wb = Me.CreateInstance(VbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Assert.True(Wb.HasVbaProject) Wb.Save() Assert.True(Wb.HasVbaProject, "VBA project hasn't been removed automatically") @@ -230,12 +230,12 @@ Namespace ExcelOpsTests.Engines NewXlsxTargetPath = TestEnvironment.FullPathOfDynTestFile(NameOf(SaveXlsxWithVbaProjectMustFail), "NonVbaProject.xlsx") System.IO.File.Copy(NonVbaTestFile, NonVbaTestFileClone) - Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.False(Wb.HasVbaProject) Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Wb.Close() - Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Wb = Me.CreateInstance(NonVbaTestFileClone, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Assert.False(Wb.HasVbaProject) Wb.Save() Wb.Close() @@ -243,13 +243,13 @@ Namespace ExcelOpsTests.Engines 'Loading a workbook with VBA project + removing VBA project + saving workbook as XLSM + reloading workbook = must still HasVbaProject = False VbaTestFile = TestEnvironment.FullPathOfExistingTestFile("test_data", "VbaProject.xlsm") NewXlsxTargetPath = TestEnvironment.FullPathOfDynTestFile(NameOf(SaveXlsxWithVbaProjectMustFail), "VbaProject.xlsm") - Wb = Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(VbaTestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.True(Wb.HasVbaProject) Wb.RemoveVbaProject() Assert.False(Wb.HasVbaProject) Wb.SaveAs(NewXlsxTargetPath, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Wb.Close() - Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.False(Wb.HasVbaProject) End Sub @@ -262,10 +262,10 @@ Namespace ExcelOpsTests.Engines If GetType(T) Is GetType(MsExcelDataOperations) Then 'known to fail because no support for reading files from in-memory Assert.Throws(Of NotSupportedException)(Sub() - Me.CreateInstance(Data, New ExcelDataOperationsOptions) + Me.CreateInstance(Data, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) End Sub) Else - Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) Assert.That(Wb.ReadOnly, [Is].True) End If @@ -279,10 +279,10 @@ Namespace ExcelOpsTests.Engines If GetType(T) Is GetType(MsExcelDataOperations) Then 'known to fail because no support for reading files from in-memory Assert.Throws(Of NotSupportedException)(Sub() - Me.CreateInstance(Data, New ExcelDataOperationsOptions) + Me.CreateInstance(Data, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) End Sub) Else - Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) Assert.That(Wb.ReadOnly, [Is].True) End If @@ -292,7 +292,7 @@ Namespace ExcelOpsTests.Engines Dim Wb As T 'Testfile without password Dim TestFile As String = TestEnvironment.FullPathOfExistingTestFile("test_data", "ExcelOpsGrund01.xlsx") - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) 'Now, save it with password @@ -303,12 +303,12 @@ Namespace ExcelOpsTests.Engines Wb.Close() 'Try to reload it without password -> it must fail - Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = "something else"})) - Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = ""})) - Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = Nothing})) + Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly, "something else"))) + Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly, ""))) + Assert.Catch(Of Exception)(Sub() Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly, Nothing))) 'Reload it with password -> now it must succeed - Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.PasswordForOpening = "dummy"}) + Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly, "dummy")) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) End Sub @@ -323,13 +323,13 @@ Namespace ExcelOpsTests.Engines Wb.Close() TestFile = Nothing - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) Wb.Close() TestFile = "" - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Assert.AreEqual(Nothing, Wb.FilePath) Assert.AreEqual(Nothing, Wb.WorkbookFilePath) Wb.Close() @@ -341,8 +341,12 @@ Namespace ExcelOpsTests.Engines Dim TestFile2 As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, "created-workbook2.xlsx") 'Creating a new workbook without pre-defined file name must fail on Save(), but successful on SaveAs() - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) - Assert.AreEqual(TestFile = Nothing, Wb.ReadOnly, "Newly created files must be ReadOnly if file path hasn't been set up") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) + Assert.AreEqual(True, Wb.ReadOnly, "Newly created files must be ReadOnly if file path hasn't been set up, but ReadWrite if file path has been set up") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) + Assert.AreEqual(False, Wb.ReadOnly, "Newly created files must be ReadOnly if file path hasn't been set up, but ReadWrite if file path has been set up") + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)) + Assert.AreEqual(TestFile = Nothing, Wb.ReadOnly, "Newly created files must be ReadOnly if file path hasn't been set up, but ReadWrite if file path has been set up") Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(Nothing, Wb.WorkbookFilePath) Wb.Save() @@ -354,12 +358,12 @@ Namespace ExcelOpsTests.Engines 'Creating a new workbook must fail with a pre-defined file name if there is already a file Assert.Throws(Of FileAlreadyExistsException)(Sub() - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) End Sub) System.IO.File.Delete(TestFile) 'Delete the file for next test block 'Creating a new workbook must always be ReadOnly and saving it without a name must be forbidden - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Assert.AreEqual(TestFile = Nothing, Wb.ReadOnly, "Newly created files must always be ReadOnly") Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(Nothing, Wb.WorkbookFilePath) @@ -378,7 +382,7 @@ Namespace ExcelOpsTests.Engines Assert.AreEqual(TestFile, Wb.WorkbookFilePath) 'Saving a ReadWrite file must be forbidden - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(True, Wb.ReadOnly) Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) @@ -391,7 +395,7 @@ Namespace ExcelOpsTests.Engines Wb.Close() 'Saving a ReadWrite file must be allowed - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions With {.FileWriteProtection = ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite}) + Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Assert.AreEqual(False, Wb.ReadOnly) Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) @@ -419,7 +423,7 @@ Namespace ExcelOpsTests.Engines End Select workbook.Close() - workbook = Me.CreateInstance(Nothing, ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions) + workbook = Me.CreateInstance(Nothing, ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(1, workbook.SheetNames.Count, "Sheets Count") Assert.AreEqual("Sheet1", workbook.SheetNames(0)) workbook.Close() @@ -441,8 +445,8 @@ Namespace ExcelOpsTests.Engines Console.WriteLine("Test file output template: " & TestControllingToolFileNameOutTemplate) Console.WriteLine("Test file output: " & TestControllingToolFileNameOut) - eppeoIn = Me.CreateInstance(TestControllingToolFileNameIn, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) - eppeoOut = Me.CreateInstance(TestControllingToolFileNameOutTemplate, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeoIn = Me.CreateInstance(TestControllingToolFileNameIn, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) + eppeoOut = Me.CreateInstance(TestControllingToolFileNameOutTemplate, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Const SheetToCopy As String = "Grunddaten" eppeoIn.CopySheetContent(SheetToCopy, eppeoOut, ExcelOps.ExcelDataOperationsBase.CopySheetOption.TargetSheetMightExist) @@ -457,7 +461,7 @@ Namespace ExcelOpsTests.Engines End Sub Public Sub ExcelOpsTestCollection_ZahlenUndProzentwerte() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileExcelOpsTestCollection.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileExcelOpsTestCollection.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim SheetName As String SheetName = "ZahlenUndProzentwerte" Assert.AreEqual("0.00", eppeo.LookupCellFormat(SheetName, 0, 1)) @@ -473,7 +477,7 @@ Namespace ExcelOpsTests.Engines Public Sub IsMergedCell() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Const SheetName As String = "MergedCellsTest" Assert.True(eppeo.IsMergedCell(SheetName, 0, 0)) Assert.True(eppeo.IsMergedCell(SheetName, 1, 0)) @@ -488,7 +492,7 @@ Namespace ExcelOpsTests.Engines Public Sub MergeAndUnMergedCell() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Const SheetName As String = "MergedCellsTest" Assert.True(eppeo.IsMergedCell(SheetName, 0, 0)) Assert.True(eppeo.IsMergedCell(SheetName, 2, 2)) @@ -503,12 +507,12 @@ Namespace ExcelOpsTests.Engines Public Sub MergedCells() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim SheetName As String = "MergedCellsTest" Assert.AreEqual("A1:C3", String.Join(";"c, eppeo.MergedCells(SheetName).Select(Of String)(Function(x) x.LocalAddress))) TestControllingToolFileName = TestFiles.TestFileGrund01.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) SheetName = "Grunddaten" Assert.AreEqual("", String.Join(";"c, eppeo.MergedCells(SheetName).Select(Of String)(Function(x) x.LocalAddress))) End Sub @@ -516,7 +520,7 @@ Namespace ExcelOpsTests.Engines Public Sub AutoFitColumns() Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestControllingToolFileName As String = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Const SheetName As String = "MergedCellsTest" Try Assert.AreEqual(2, eppeo.LookupLastCell(SheetName).ColumnIndex) @@ -542,14 +546,14 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileGrund01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) EppeoSheetNamesList = eppeo.SheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) Assert.AreEqual("Grunddaten,Kostenplanung", Strings.Join(EppeoSheetNamesList.ToArray, ",")) TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) EppeoSheetNamesList = eppeo.SheetNames System.Console.WriteLine() System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) @@ -561,7 +565,7 @@ Namespace ExcelOpsTests.Engines Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(0, eppeo.SheetIndex("data")) Assert.AreEqual(1, eppeo.SheetIndex("chart")) Assert.AreEqual(-1, eppeo.SheetIndex("doesntexist")) @@ -573,7 +577,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) EppeoSheetNamesList = eppeo.WorkSheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) @@ -584,7 +588,7 @@ Namespace ExcelOpsTests.Engines Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(0, eppeo.WorkSheetIndex("data")) Assert.AreEqual(-1, eppeo.WorkSheetIndex("chart")) End Sub @@ -594,7 +598,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileGrund03.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Ausgewählt")) @@ -608,13 +612,13 @@ Namespace ExcelOpsTests.Engines System.Console.WriteLine("OUT: " & eppeo.FilePath) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Grunddaten")) - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) eppeo.SelectSheet(1) eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Ausgewählt.1.xlsx"), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) System.Console.WriteLine("OUT: " & eppeo.FilePath) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Ausgewählt")) - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) eppeo.SelectSheet(2) eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Kostenplanung.2.xlsx"), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) System.Console.WriteLine("OUT: " & eppeo.FilePath) @@ -625,7 +629,7 @@ Namespace ExcelOpsTests.Engines System.Console.WriteLine("OUT: " & eppeo.FilePath) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Grunddaten")) - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) eppeo.SelectSheet("Kostenplanung") eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Kostenplanung.xlsx"), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) System.Console.WriteLine("OUT: " & eppeo.FilePath) @@ -638,7 +642,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileHtmlExport01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Onboarding offen")) eppeo.SelectSheet("Upload erledigt") @@ -651,7 +655,7 @@ Namespace ExcelOpsTests.Engines Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) EppeoSheetNamesList = eppeo.ChartSheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) @@ -662,7 +666,7 @@ Namespace ExcelOpsTests.Engines Dim eppeo As ExcelOps.ExcelDataOperationsBase Dim TestFileName As String TestFileName = TestFiles.TestFileChartSheet01.FullName - eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(0, eppeo.ChartSheetIndex("chart")) Assert.AreEqual(-1, eppeo.ChartSheetIndex("data")) End Sub @@ -675,7 +679,7 @@ Namespace ExcelOpsTests.Engines Dim BeforeSheet As String = "Grunddaten" Dim SheetNameTopPosition As String = "SheetOnTop" Dim SheetNameBottomPosition As String = "SheetOnBottom" - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim ExpectedSheetNamesList, NewSheetNamesList As List(Of String) ExpectedSheetNamesList = eppeo.SheetNames ExpectedSheetNamesList.Add(SheetNameBottomPosition) @@ -693,7 +697,7 @@ Namespace ExcelOpsTests.Engines Dim AllFormulas As List(Of ExcelOps.TextTableCell) TestControllingToolFileName = TestFiles.TestFileGrund01.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) AllFormulas = eppeo.AllFormulasOfWorkbook Console.WriteLine("Test file: " & TestControllingToolFileName) Assert.NotZero(AllFormulas.Count) @@ -718,7 +722,7 @@ Namespace ExcelOpsTests.Engines End Sub Public Sub CellWithError() - Dim wb As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileGrund02.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim wb As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestFiles.TestFileGrund02.FullName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim SheetName As String = wb.SheetNames(0) wb.WriteCellFormula(SheetName, 0, 0, "B2", False) @@ -758,7 +762,7 @@ Namespace ExcelOpsTests.Engines Dim TestControllingToolFileName As String = TestFiles.TestFileGrund01.FullName Dim TestSheet As String = "Grunddaten" - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual("E40", eppeo.LookupLastCell(TestSheet).Address) Assert.AreEqual(39, eppeo.LookupLastRowIndex(TestSheet)) Assert.AreEqual(4, eppeo.LookupLastColumnIndex(TestSheet)) @@ -769,7 +773,7 @@ Namespace ExcelOpsTests.Engines Assert.AreEqual(9, eppeo.LookupLastColumnIndex(TestSheet)) TestControllingToolFileName = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) TestSheet = "MergedCellsTest" Assert.AreEqual("C3", eppeo.LookupLastCell(TestSheet).Address) Assert.AreEqual(2, eppeo.LookupLastRowIndex(TestSheet)) @@ -781,7 +785,7 @@ Namespace ExcelOpsTests.Engines Dim TestControllingToolFileName As String = TestFiles.TestFileGrund01.FullName Dim TestSheet As String = "Grunddaten" - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual("E40", eppeo.LookupLastContentCell(TestSheet).Address) Assert.AreEqual(39, eppeo.LookupLastContentRowIndex(TestSheet)) Assert.AreEqual(4, eppeo.LookupLastContentColumnIndex(TestSheet)) @@ -793,7 +797,7 @@ Namespace ExcelOpsTests.Engines Assert.AreEqual(8, eppeo.LookupLastContentColumnIndex(TestSheet)) TestControllingToolFileName = TestFiles.TestFileMergedCells.FullName - eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + eppeo = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) TestSheet = "MergedCellsTest" Assert.AreEqual("C3", eppeo.LookupLastContentCell(TestSheet).Address) Assert.AreEqual(2, eppeo.LookupLastContentRowIndex(TestSheet)) @@ -843,7 +847,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -900,7 +904,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -956,7 +960,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D " & ControlChars.CrLf & @@ -1013,7 +1017,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -1071,7 +1075,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -1137,7 +1141,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) '## Expected matrix like following '"# |A |B |C |D |E @@ -1188,7 +1192,7 @@ Namespace ExcelOpsTests.Engines #Region "ExcelCharting" Private Function PrepareAndFillExcelFileWithChart(variantOfImage As Byte) As ExcelOps.ExcelDataOperationsBase Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileChartSheet01.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Select Case variantOfImage Case 0 'master Workbook.WriteCellValue(Of String)(New ExcelCell("data", "B1", ExcelCell.ValueTypes.All), "Sample Chart") @@ -1289,7 +1293,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable) '## Expected matrix like following @@ -1304,7 +1308,7 @@ Namespace ExcelOpsTests.Engines 'NOTE: Known expected behaviour for #NUM! error value is differently between the several engines Select Case eppeo.EngineName - Case "Spire.Xls", "FreeSpire.Xls", "Epplus (Polyform license edition)" + Case "Spire.Xls", "FreeSpire.Xls" ', "Epplus (Polyform license edition)" Assert.AreEqual(Nothing, eppeo.LookupCellErrorValue(New ExcelOps.ExcelCell(TestSheet, "D1", ExcelOps.ExcelCell.ValueTypes.All))) Assert.Ignore(eppeo.EngineName & " is not fully compatible and doesn't show up with #NUM! error value in cell E1 (=10^1000)") Case Else @@ -1321,7 +1325,7 @@ Namespace ExcelOpsTests.Engines TestInCultureContext( cultureName, Sub() - Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestControllingToolFileName, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable) '## Expected matrix like following @@ -1336,7 +1340,7 @@ Namespace ExcelOpsTests.Engines 'NOTE: Known expected behaviour for #NUM! error value is differently between the several engines Select Case eppeo.EngineName - Case "Spire.Xls", "FreeSpire.Xls", "Epplus (Polyform license edition)" + Case "Spire.Xls", "FreeSpire.Xls" ', "Epplus (Polyform license edition)" Assert.AreEqual(0, eppeo.FindErrorCellsInWorkbook("#NUM!").Count) 'Error detection not working (correctly) in engine Assert.AreEqual(4, eppeo.FindErrorCellsInWorkbook().Count) Assert.Ignore(eppeo.EngineName & " is not fully compatible and doesn't show up with #NUM! error value in cell E1 (=10^1000)") @@ -1358,7 +1362,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithEmbeddedPicture01() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileEmbeddedPicture01.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture01.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1384,7 +1388,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithEmbeddedPicture02() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileEmbeddedPicture02.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture02.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1410,7 +1414,7 @@ Namespace ExcelOpsTests.Engines Public Sub TestFileWithEmbeddedPicture03() Try Dim ExcelFile As String = TestEnvironment.FullPathOfExistingTestFile(TestFiles.TestFileEmbeddedPicture03.FullName) - Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture02.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1439,7 +1443,7 @@ Namespace ExcelOpsTests.Engines Dim CatchedEx As Exception = Nothing Try - Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Catch ex As Exception CatchedEx = ex Workbook = Me.CreateInstance() @@ -1575,7 +1579,7 @@ Namespace ExcelOpsTests.Engines System.Console.WriteLine("TEST IN FILE: " & TestXlsxFile.FullName) Try - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.JumpToAnchor}) @@ -1600,7 +1604,7 @@ Namespace ExcelOpsTests.Engines Try With Nothing - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".nav-anchor.html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.JumpToAnchor}) @@ -1612,7 +1616,7 @@ Namespace ExcelOpsTests.Engines End If End With With Nothing - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".nav-anchor-fixed-on-top.html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.JumpToAnchor, .SheetNavigationAlwaysVisible = True}) @@ -1624,7 +1628,7 @@ Namespace ExcelOpsTests.Engines End If End With With Nothing - Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Wb, TestXlsxFile.Name & ".nav-switch.html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportWorkbookToHtml(TestHtmlOutputFile, New HtmlWorkbookExportOptions() With {.SheetNavigationActionStyle = HtmlWorkbookExportOptions.SheetNavigationActionStyles.SwitchVisibleSheet}) @@ -1653,7 +1657,7 @@ Namespace ExcelOpsTests.Engines Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Nothing Try - Wb = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions) + Wb = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Catch ex As TypeInitializationException Assert.Ignore("Not supported on this platform " & System.Environment.OSVersion.Platform.ToString) End Try diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb index 246b6de..3871178 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb @@ -16,7 +16,7 @@ Namespace ExcelOpsTests.Engines ElseIf AlwaysCloseAllWorkbooksInNewEngineInstances Then MsExcelInstance.Workbooks.CloseAllWorkbooks() End If - Return New ExcelOps.MsExcelDataOperations(file, mode, MsExcelInstance, False, New ExcelDataOperationsOptions) + Return New ExcelOps.MsExcelDataOperations(file, mode, MsExcelInstance, False, options) End Function Protected Overrides Function _CreateInstance() As ExcelOps.MsExcelDataOperations @@ -26,7 +26,7 @@ Namespace ExcelOpsTests.Engines ElseIf AlwaysCloseAllWorkbooksInNewEngineInstances Then MsExcelInstance.Workbooks.CloseAllWorkbooks() End If - Return New ExcelOps.MsExcelDataOperations(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, MsExcelInstance, False, New ExcelDataOperationsOptions) + Return New ExcelOps.MsExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb index d13c2fb..0302eda 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelAppReleaseTest.vb @@ -45,17 +45,17 @@ Namespace ExcelOpsTests.MsExcelSpecials Assert.Pass() End Sub - Public Sub OpenAnCloseMsExcelWithProperProcessCleanup_SeparateMsExcelAppWithExplicitQuit() - Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, New ExcelDataOperationsOptions) + Public Sub OpenAndCloseMsExcelWithProperProcessCleanup_SeparateMsExcelAppWithExplicitQuit() + Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) DummyCTWb.CloseExcelAppInstance() Dim MsExcelProcessesAfterExplicitQuit As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("EXCEL") Assert.AreEqual(MsExcelProcessesAfterExplicitQuit.Length, MsExcelProcessesAfterExplicitQuit.Length, "Process count after ExcelApp.Quit") End Sub ' - Public Sub OpenAnCloseMsExcelWithPropertProcessCleanup_SeparateMsExcelApp( explicitlyCloseMsExcelAppInstance As Boolean) + Public Sub OpenAndCloseMsExcelWithProperProcessCleanup_SeparateMsExcelApp( explicitlyCloseMsExcelAppInstance As Boolean) Dim Dummy = Sub() - Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, New ExcelDataOperationsOptions) + Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, False, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) #Disable Warning IDE0059 ' Unnötige Zuweisung eines Werts. If explicitlyCloseMsExcelAppInstance Then DummyCTWb.CloseExcelAppInstance() DummyCTWb = Nothing @@ -69,11 +69,11 @@ Namespace ExcelOpsTests.MsExcelSpecials End Sub ' - Public Sub OpenAnCloseMsExcelWithPropertProcessCleanup_ReusedMsExcelApp( explicitlyCloseMsExcelAppInstance As Boolean) + Public Sub OpenAndCloseMsExcelWithProperProcessCleanup_ReusedMsExcelApp( explicitlyCloseMsExcelAppInstance As Boolean) Dim Dummy = Sub() Dim MsExcelApp As New MsExcelApplicationWrapper() - Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions) - Dim DummyCTWb2 As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions) + Dim DummyCTWb As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) + Dim DummyCTWb2 As New MsExcelDataOperations(TestFiles.TestFileGrund02.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, MsExcelApp, False, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) #Disable Warning IDE0059 ' Unnötige Zuweisung eines Werts. DummyCTWb = Nothing DummyCTWb2 = Nothing diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestBase.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestBase.vb index 061b9d4..ad0b936 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestBase.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestBase.vb @@ -20,7 +20,7 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected MustOverride ReadOnly Property EngineName As String - Protected MustOverride Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase + Protected MustOverride Function CreateEngineInstanceWithCreateFileMode(testFile As String) As ExcelOps.ExcelDataOperationsBase Protected MustOverride Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) @@ -79,7 +79,7 @@ Namespace ExcelOpsTests.MsExcelSpecials System.Console.WriteLine() 'Create new Excel workbook with Epplus and add some cells with values and formulas - Dim Eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateEngineInstance(TestFile) + Dim Eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateEngineInstanceWithCreateFileMode(TestFile) Dim FirstSheetName As String = Eppeo.SheetNames(0) Eppeo.WriteCellValue(Of String)(FirstSheetName, 0, 0, "Static value initially set") @@ -98,14 +98,14 @@ Namespace ExcelOpsTests.MsExcelSpecials Eppeo.WriteCellFormula(FirstSheetName, 5, 1, "B3", False) Select Case EngineName - Case (New ExcelOps.EpplusFreeExcelDataOperations()).EngineName + Case (New ExcelOps.EpplusFreeExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName Assert.AreEqual(True, Eppeo.CalculationModuleDisabled) Assert.Throws(Of FeatureDisabledException)(Sub() Eppeo.Save(ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset)) + Eppeo.CalculationModuleDisabled = False + Assert.AreEqual(False, Eppeo.CalculationModuleDisabled) Case Else Assert.AreEqual(False, Eppeo.CalculationModuleDisabled) End Select - Eppeo.CalculationModuleDisabled = False - Assert.AreEqual(False, Eppeo.CalculationModuleDisabled) Eppeo.Save(ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) 'Create workbook copy, open and recalculate and save in MS Excel @@ -185,7 +185,7 @@ Namespace ExcelOpsTests.MsExcelSpecials System.Console.WriteLine() 'Create new Excel workbook with Epplus and add some cells with values and formulas - Dim Eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateEngineInstance(TestFile) + Dim Eppeo As ExcelOps.ExcelDataOperationsBase = Me.CreateEngineInstanceWithCreateFileMode(TestFile) Dim FirstSheetName As String = Eppeo.SheetNames(0) Eppeo.AddSheet("Sheet2") diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb index 6bb81eb..39b89db 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusFree.vb @@ -15,13 +15,13 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected Overrides ReadOnly Property EngineName As String Get Static Result As String - If Result Is Nothing Then Result = (New ExcelOps.EpplusFreeExcelDataOperations()).EngineName + If Result Is Nothing Then Result = (New ExcelOps.EpplusFreeExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName Return Result End Get End Property - Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase - Return New ExcelOps.EpplusFreeExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions()) + Protected Overrides Function CreateEngineInstanceWithCreateFileMode(testFile As String) As ExcelOps.ExcelDataOperationsBase + Return New ExcelOps.EpplusFreeExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb index a7d21f1..6eddf19 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb @@ -20,14 +20,14 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected Overrides ReadOnly Property EngineName As String Get Static Result As String - If Result Is Nothing Then Result = (New ExcelOps.EpplusPolyformExcelDataOperations()).EngineName + If Result Is Nothing Then Result = (New ExcelOps.EpplusPolyformExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName Return Result End Get End Property - Protected Overrides Function CreateEngineInstance(testFile As String) As ExcelOps.ExcelDataOperationsBase + Protected Overrides Function CreateEngineInstanceWithCreateFileMode(testFile As String) As ExcelOps.ExcelDataOperationsBase ExcelOpsTests.Engines.EpplusPolyformEditionOpsTest.AssignLicenseContext() - Return New ExcelOps.EpplusPolyformExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions) + Return New ExcelOps.EpplusPolyformExcelDataOperations(testFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)) End Function Protected Overrides Sub EngineResetCellValueFromFormulaCell(wb As ExcelOps.ExcelDataOperationsBase, sheetName As String, rowIndex As Integer, columnIndex As Integer) diff --git a/TestAndDemoExcelOps/Program.cs b/TestAndDemoExcelOps/Program.cs index 53fe160..bf24cd4 100644 --- a/TestAndDemoExcelOps/Program.cs +++ b/TestAndDemoExcelOps/Program.cs @@ -6,7 +6,7 @@ TextTable values; //Create a workbook and put some values and formulas -workbook = new EpplusFreeExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); +workbook = new EpplusFreeExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); @@ -27,7 +27,7 @@ EpplusPolyformExcelDataOperations.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial; //Create a workbook and put some values and formulas -workbook = new EpplusPolyformExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); +workbook = new EpplusPolyformExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); @@ -65,7 +65,7 @@ //Create a workbook and put some values and formulas -workbook = new MsExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions()); +workbook = new MsExcelDataOperations(null, ExcelDataOperationsBase.OpenMode.CreateFile, new ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123); From ff58da13b1d5c4f16f112d3009589623e42283bf Mon Sep 17 00:00:00 2001 From: Jochen Wezel Date: Thu, 18 Dec 2025 16:48:37 +0100 Subject: [PATCH 3/7] fixed issues --- .../ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb | 5 ++++- .../MsExcelCalcTestEpplusPolyform.vb | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb b/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb index 00d43c1..fd211b2 100644 --- a/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb +++ b/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb @@ -15,7 +15,10 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected Overrides ReadOnly Property EngineName As String Get Static Result As String - If Result Is Nothing Then Result = (New ExcelOps.SpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName + If Result Is Nothing Then + ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = True + Result = (New ExcelOps.SpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName + End If Return Result End Get End Property diff --git a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb index 6eddf19..34f6e48 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb @@ -20,7 +20,9 @@ Namespace ExcelOpsTests.MsExcelSpecials Protected Overrides ReadOnly Property EngineName As String Get Static Result As String - If Result Is Nothing Then Result = (New ExcelOps.EpplusPolyformExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName + If Result Is Nothing Then + Result = (New ExcelOps.EpplusPolyformExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName + End If Return Result End Get End Property From b6ed0b14ec3899ed3140df9bc6f7175741a88018 Mon Sep 17 00:00:00 2001 From: Jochen Wezel Date: Thu, 18 Dec 2025 16:50:08 +0100 Subject: [PATCH 4/7] reverted obsolete error to obsolete warning --- .../EpplusFreeExcelDataOperations.vb | 14 ++++++------- .../EpplusPolyformExcelDataOperations.vb | 20 +++++++++---------- .../FreeSpireXlsDataOperations.vb | 14 ++++++------- .../ExcelOpsLowLevel/MsExcelDataOperations.vb | 10 +++++----- ExcelOps-SpireXls/SpireXlsDataOperations.vb | 14 ++++++------- .../ExcelDataOperationsBase.vb | 18 ++++++++--------- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb index f08a599..c22409b 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb @@ -77,7 +77,7 @@ Namespace ExcelOps ''' ''' Create or open a workbook ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(file, mode, Not disableInitialCalculation, False, [readOnly], passwordForOpening) @@ -86,7 +86,7 @@ Namespace ExcelOps ''' ''' Create or open a workbook ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, False, True, [readOnly], passwordForOpening) @@ -95,7 +95,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, False, True, passwordForOpening) @@ -104,7 +104,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, True, passwordForOpening) @@ -113,7 +113,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, False, True, passwordForOpening) @@ -122,7 +122,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, True, passwordForOpening) @@ -132,7 +132,7 @@ Namespace ExcelOps ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' ''' Pre-define encryption password on future save actions - + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(False, True, True, passwordForOpeningOnNextTime) diff --git a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb index 45a331d..335dd80 100644 --- a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb +++ b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb @@ -83,7 +83,7 @@ Namespace ExcelOps ''' ''' Create or open a workbook ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(file, mode, Not disableInitialCalculation, disableCalculationEngine, [readOnly], passwordForOpening) @@ -93,7 +93,7 @@ Namespace ExcelOps ''' ''' Create or open a workbook ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(file, mode, Not disableInitialCalculation, False, [readOnly], passwordForOpening) @@ -103,7 +103,7 @@ Namespace ExcelOps ''' ''' Create or open a workbook ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, True, False, [readOnly], passwordForOpening) @@ -113,7 +113,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) @@ -123,7 +123,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) @@ -133,7 +133,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) @@ -143,7 +143,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) @@ -153,7 +153,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) @@ -163,7 +163,7 @@ Namespace ExcelOps ''' ''' Open a workbook ''' - + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean) MyBase.New(data, Not disableInitialCalculation, False, passwordForOpening) @@ -191,7 +191,7 @@ Namespace ExcelOps ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' ''' Pre-define encryption password on future save actions - + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(False, True, True, passwordForOpeningOnNextTime) diff --git a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb index 818ca3f..3eb2a68 100644 --- a/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb +++ b/ExcelOps-FreeSpireXls/FreeSpireXlsDataOperations.vb @@ -70,7 +70,7 @@ Namespace ExcelOps ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(file, mode, Not disableInitialCalculation, disableCalculationEngine, [readOnly], passwordForOpening) @@ -87,31 +87,31 @@ Namespace ExcelOps ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, True, False, [readOnly], passwordForOpening) End Sub - + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) End Sub - + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) End Sub - + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) End Sub - + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) @@ -150,7 +150,7 @@ Namespace ExcelOps ''' Just as a reminder for usage of FreeSpire.Xls: the manufacturer has limited the feature set for this component. Free version is limited to 5 sheets per workbook and 150 rows per sheet. ''' See https://www.e-iceblue.com/ for more details on limitations and licensing. ''' - + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(True, False, True, passwordForOpeningOnNextTime) diff --git a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb index ea46b48..4a509a4 100644 --- a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb +++ b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb @@ -100,7 +100,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, New MsExcelApplicationWrapper, False, [readOnly], passwordForOpening) @@ -119,7 +119,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - + Public Sub New(file As String, mode As OpenMode, unprotectWorksheets As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, New MsExcelApplicationWrapper, unprotectWorksheets, [readOnly], passwordForOpening) @@ -139,7 +139,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - ' + ' Public Sub New(file As String, mode As OpenMode, msExcelApp As MsExcelApplicationWrapper, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, msExcelApp, True, [readOnly], passwordForOpening) @@ -160,7 +160,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - + Public Sub New(file As String, mode As OpenMode, msExcelApp As MsExcelApplicationWrapper, unprotectWorksheets As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(file, mode, msExcelApp, unprotectWorksheets, [readOnly], passwordForOpening, False) @@ -181,7 +181,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - + Public Sub New(file As String, mode As OpenMode, msExcelApp As MsExcelApplicationWrapper, unprotectWorksheets As Boolean, [readOnly] As Boolean, passwordForOpening As String, disableAutoCalculation As Boolean) #Disable Warning IDE0060 ' Nicht verwendete Parameter entfernen diff --git a/ExcelOps-SpireXls/SpireXlsDataOperations.vb b/ExcelOps-SpireXls/SpireXlsDataOperations.vb index 0c453fb..2d2c27a 100644 --- a/ExcelOps-SpireXls/SpireXlsDataOperations.vb +++ b/ExcelOps-SpireXls/SpireXlsDataOperations.vb @@ -65,7 +65,7 @@ Namespace ExcelOps ''' ''' ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(file, mode, Not disableInitialCalculation, disableCalculationEngine, [readOnly], passwordForOpening) @@ -80,35 +80,35 @@ Namespace ExcelOps ''' ''' ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ - + Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String) MyBase.New(file, mode, True, False, [readOnly], passwordForOpening) If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub - + Public Sub New(data As Byte(), passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub - + Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub - + Public Sub New(data As System.IO.Stream, passwordForOpening As String) MyBase.New(data, True, False, passwordForOpening) If AllowInstancingForNonLicencedContextForTestingPurposesOnly = False AndAlso IsLicensedContext = False Then Throw New LicenseException(GetType(Spire.License.LicenseProvider), Nothing, "Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/") End Sub - + Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean, disableCalculationEngine As Boolean) MyBase.New(data, Not disableInitialCalculation, disableCalculationEngine, passwordForOpening) @@ -139,7 +139,7 @@ Namespace ExcelOps ''' ''' ''' Correct licensing required, see Spire.License.LicenseProvider and https://www.e-iceblue.com/ - + Public Sub New(passwordForOpeningOnNextTime As String) MyBase.New(True, False, True, passwordForOpeningOnNextTime) diff --git a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb index 02e9887..d21a811 100644 --- a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb @@ -122,7 +122,7 @@ Namespace ExcelOps ''' ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) ''' - + Private Sub New() Me.New(New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) @@ -152,8 +152,8 @@ Namespace ExcelOps ''' ''' ''' - - + + Protected Sub New(file As String, mode As OpenMode, autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, [readOnly], passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) @@ -180,8 +180,8 @@ Namespace ExcelOps ''' ''' ''' - - + + Protected Sub New(data As Byte(), autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, True, passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) @@ -200,8 +200,8 @@ Namespace ExcelOps ''' ''' ''' - - + + Protected Sub New(data As System.IO.Stream, autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, True, passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) @@ -218,8 +218,8 @@ Namespace ExcelOps ''' ''' Automatically do a full recalculation after workbook has been loaded ''' Disables the Excel calculation engine - - + + Protected Sub New(autoCalculationOnLoad As Boolean, calculationModuleDisabled As Boolean, [readOnly] As Boolean, passwordForOpening As String) Me.New(ConvertToUnvalidatedOptions(autoCalculationOnLoad, calculationModuleDisabled, [readOnly], passwordForOpening)) If autoCalculationOnLoad AndAlso calculationModuleDisabled Then Throw New ArgumentException("Calculation engine is disabled, but AutoCalculation requested", NameOf(autoCalculationOnLoad)) From e1320a5f3216011566d9a3fdb0dce3cd697a9257 Mon Sep 17 00:00:00 2001 From: Jochen Wezel Date: Thu, 18 Dec 2025 17:45:57 +0100 Subject: [PATCH 5/7] fixed several issues again --- .../ExcelOpsLowLevel/MsExcelDataOperations.vb | 15 +++------ .../ExcelDataOperationsBase.vb | 10 ++++++ .../FreeSpireXlsOpsTest.vb | 2 +- .../ExcelOpsTests.Engines/SpireXlsOpsTest.vb | 6 ++-- .../EpplusFreeFixCalcsEditionOpsTest.vb | 2 +- .../EpplusPolyformEditionOpsTest.vb | 2 +- .../ExcelOpsTests.Engines/ExcelOpsTestBase.vb | 31 ++++++++++--------- .../ExcelOpsTests.Engines/MsExcelOpsTest.vb | 2 +- 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb index 4a509a4..b47e44b 100644 --- a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb +++ b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb @@ -2,6 +2,7 @@ Option Strict On Imports System.Text +Imports CompuMaster.Excel.ExcelOps.ExcelDataOperationsOptions Imports CompuMaster.Excel.MsExcelCom Imports Microsoft.Office.Interop.Excel Imports MsExcel = Microsoft.Office.Interop.Excel @@ -260,15 +261,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps MyBase.New(options) Me._MsExcelAppInstance = msExcelApp Me._Workbooks = New MsExcelWorkbooksWrapper(msExcelApp, msExcelApp.ComObjectStronglyTyped.Workbooks) - Select Case mode - Case OpenMode.OpenExistingFile - Me.LoadAndInitializeWorkbookFile(file, options) - Case OpenMode.CreateFile - Me.CreateAndInitializeWorkbookFile(file, options) - Me.ReadOnly = Me.[ReadOnly] OrElse (file = Nothing) - Case Else - Throw New ArgumentOutOfRangeException(NameOf(mode)) - End Select + Me.ExecuteOpenModeActions(file, mode, options) If unprotectWorksheets = True Then Me.UnprotectSheets() End If @@ -403,7 +396,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' Please note: this property is a workbook property (not an engine property!) Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean Get - If Me.MsExcelAppInstance IsNot Nothing AndAlso Me.MsExcelAppInstance.ComObjectStronglyTyped IsNot Nothing Then + If Me.MsExcelAppInstance IsNot Nothing AndAlso Me.MsExcelAppInstance.ComObjectStronglyTyped IsNot Nothing AndAlso Me._Workbook IsNot Nothing Then Return (Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationAutomatic) Else Return MyBase.AutoCalculationEnabledWorkbookSetting @@ -411,7 +404,7 @@ Namespace Global.CompuMaster.Excel.ExcelOps End Get Set(value As Boolean) MyBase.AutoCalculationEnabledWorkbookSetting = value - If Me.MsExcelAppInstance IsNot Nothing AndAlso Me.MsExcelAppInstance.ComObjectStronglyTyped IsNot Nothing Then + If Me.MsExcelAppInstance IsNot Nothing AndAlso Me.MsExcelAppInstance.ComObjectStronglyTyped IsNot Nothing AndAlso Me._Workbook IsNot Nothing Then If value Then Me.MsExcelAppInstance.ComObjectStronglyTyped.Calculation = MsExcel.XlCalculation.xlCalculationAutomatic Else diff --git a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb index d21a811..d9e4b46 100644 --- a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb @@ -35,6 +35,16 @@ Namespace ExcelOps ''' File and engine options Protected Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) Me.New(options) + Me.ExecuteOpenModeActions(file, mode, options) + End Sub + + ''' + ''' Initialize engine, open file or create new workbook + ''' + ''' + ''' + ''' + Protected Sub ExecuteOpenModeActions(file As String, mode As OpenMode, options As ExcelDataOperationsOptions) Select Case mode Case OpenMode.OpenExistingFile If file = Nothing Then Throw New ArgumentNullException(NameOf(file), "File path must be provided when opening an existing file") diff --git a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb index 2da7fec..df12c26 100644 --- a/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb +++ b/ExcelOpsTest-FreeSpireXls/ExcelOpsTests.Engines/FreeSpireXlsOpsTest.vb @@ -12,7 +12,7 @@ Namespace ExcelOpsTests.Engines Return New ExcelOps.FreeSpireXlsDataOperations(file, mode, options) End Function - Protected Overrides Function _CreateInstance() As ExcelOps.FreeSpireXlsDataOperations + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.FreeSpireXlsDataOperations Return New ExcelOps.FreeSpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function diff --git a/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb b/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb index 0494186..d3e5190 100644 --- a/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb +++ b/ExcelOpsTest-SpireXls/ExcelOpsTests.Engines/SpireXlsOpsTest.vb @@ -16,7 +16,7 @@ Namespace ExcelOpsTests.Engines Return New ExcelOps.SpireXlsDataOperations(file, mode, options) End Function - Protected Overrides Function _CreateInstance() As ExcelOps.SpireXlsDataOperations + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.SpireXlsDataOperations Return New ExcelOps.SpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function @@ -37,12 +37,12 @@ Namespace ExcelOpsTests.Engines Public Sub IsLicensedContext() 'Simulation: license assigned ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = True - Assert.NotNull(Me.CreateInstance) + Assert.NotNull(Me.CreateInstanceUninitialized) Assert.NotNull(Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile))) 'No license assigned -> instancing must fail ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = False - Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance()) + Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstanceUninitialized()) Assert.Throws(Of System.ComponentModel.LicenseException)(Sub() Me.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelOps.ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile))) End Sub diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb index ce5c4da..226f0b9 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb @@ -13,7 +13,7 @@ Namespace ExcelOpsTests.Engines Return New ExcelOps.EpplusFreeExcelDataOperations(file, mode, options) End Function - Protected Overrides Function _CreateInstance() As ExcelOps.EpplusFreeExcelDataOperations + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.EpplusFreeExcelDataOperations Return New ExcelOps.EpplusFreeExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb index a0ea926..985e0ef 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusPolyformEditionOpsTest.vb @@ -20,7 +20,7 @@ Namespace ExcelOpsTests.Engines Return New ExcelOps.EpplusPolyformExcelDataOperations(file, mode, options) End Function - Protected Overrides Function _CreateInstance() As ExcelOps.EpplusPolyformExcelDataOperations + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.EpplusPolyformExcelDataOperations Return New ExcelOps.EpplusPolyformExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb b/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb index a0798f3..c024b00 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb @@ -17,7 +17,7 @@ Namespace ExcelOpsTests.Engines Private Const OPEN_HTML_OUTPUT_IN_BROWSER_AFTER_TEST As Boolean = True #End If - Protected MustOverride Function _CreateInstance() As T + Protected MustOverride Function _CreateInstanceUninitialized() As T #Disable Warning CA1716 ' Bezeichner dürfen nicht mit Schlüsselwörtern übereinstimmen Protected MustOverride Function _CreateInstance(file As String, mode As ExcelOps.ExcelDataOperationsBase.OpenMode, options As ExcelOps.ExcelDataOperationsOptions) As T @@ -29,9 +29,9 @@ Namespace ExcelOpsTests.Engines ''' 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) ''' ''' - Protected Function CreateInstance() As T + Protected Function CreateInstanceUninitialized() As T Try - Return _CreateInstance() + Return _CreateInstanceUninitialized() Catch ex As Exception If ex.GetType() Is GetType(PlatformNotSupportedException) Then Throw @@ -180,7 +180,7 @@ Namespace ExcelOpsTests.Engines Public MustOverride ReadOnly Property ExpectedEngineName As String Public Sub EngineName() - Assert.AreEqual(ExpectedEngineName, Me.CreateInstance().EngineName) + Assert.AreEqual(ExpectedEngineName, Me.CreateInstanceUninitialized().EngineName) End Sub Public Sub HasVbaProject() @@ -317,7 +317,7 @@ Namespace ExcelOpsTests.Engines Dim TestFile As String TestFile = Nothing - Wb = Me.CreateInstance() + Wb = Me.CreateInstanceUninitialized() Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) Wb.Close() @@ -337,8 +337,8 @@ Namespace ExcelOpsTests.Engines Public Sub CreateAndSaveAsAndFilePath() Dim Wb As T - Dim TestFile As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, "created-workbook.xlsx") - Dim TestFile2 As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, "created-workbook2.xlsx") + Dim TestFile As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstanceUninitialized, "created-workbook.xlsx") + Dim TestFile2 As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstanceUninitialized, "created-workbook2.xlsx") 'Creating a new workbook without pre-defined file name must fail on Save(), but successful on SaveAs() Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) @@ -412,11 +412,12 @@ Namespace ExcelOpsTests.Engines Public Sub CreateInstanceWithOrWithoutCreationOfWorkbook() Dim workbook As ExcelDataOperationsBase - workbook = Me.CreateInstance() + workbook = Me.CreateInstanceUninitialized() Select Case workbook.GetType Case GetType(MsExcelDataOperations) 'Accept fact that a new workbook is opened automatically - Assert.NotZero(workbook.SheetNames.Count) + 'Assert.NotZero(workbook.SheetNames.Count) + Assert.Throws(Of System.NullReferenceException)(Function() workbook.SheetNames.Count) Case Else 'No workbook opened - must be done in 2ndary step Assert.Throws(Of InvalidOperationException)(Function() workbook.SheetNames.Count) @@ -439,7 +440,7 @@ Namespace ExcelOpsTests.Engines TestControllingToolFileNameIn = TestFiles.TestFileGrund01.FullName TestControllingToolFileNameOutTemplate = TestFiles.TestFileGrund02.FullName - TestControllingToolFileNameOut = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, "CopySheetContent_" & GetType(T).Name & ".xlsx") + TestControllingToolFileNameOut = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstanceUninitialized, "CopySheetContent_" & GetType(T).Name & ".xlsx") Try Console.WriteLine("Test file in: " & TestControllingToolFileNameIn) Console.WriteLine("Test file output template: " & TestControllingToolFileNameOutTemplate) @@ -1239,7 +1240,7 @@ Namespace ExcelOpsTests.Engines Public Sub ExportChartSheetImage() Try - Dim TempFilePng As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, "excel_test_chart.png") + Dim TempFilePng As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstanceUninitialized, "excel_test_chart.png") Dim MasterImg As System.Drawing.Image #Disable Warning CA1416 MasterImg = System.Drawing.Image.FromFile(TestEnvironment.FullPathOfExistingTestFile("test_comparison_masters", "excel_test_chart.png")) @@ -1446,7 +1447,7 @@ Namespace ExcelOpsTests.Engines Workbook = Me.CreateInstance(ExcelFile, ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Catch ex As Exception CatchedEx = ex - Workbook = Me.CreateInstance() + Workbook = Me.CreateInstanceUninitialized() End Try Select Case Workbook.EngineName Case "Epplus 4 (LGPL)" @@ -1652,7 +1653,7 @@ Namespace ExcelOpsTests.Engines Dim TestXlsxFile = TestFiles.TestFileGrund01() System.Console.WriteLine("TEST IN FILE: " & TestXlsxFile.FullName) - Dim TempFilePng As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, "excel_test_chart.png") + Dim TempFilePng As String = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstanceUninitialized, "excel_test_chart.png") Dim Workbook = PrepareAndFillExcelFileWithChart(0) Dim Wb As CompuMaster.Excel.ExcelOps.ExcelDataOperationsBase = Nothing @@ -1667,7 +1668,7 @@ Namespace ExcelOpsTests.Engines Try For Each WorkSheetName In Wb.WorkSheetNames With Nothing - Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, TestXlsxFile.Name & "." & WorkSheetName & ".no-title.html") + Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstanceUninitialized, TestXlsxFile.Name & "." & WorkSheetName & ".no-title.html") System.Console.WriteLine("TEST OUT FILE: " & TestHtmlOutputFile) Wb.ExportSheetToHtml(WorkSheetName, TestHtmlOutputFile, New HtmlSheetExportOptions) If OPEN_HTML_OUTPUT_IN_BROWSER_AFTER_TEST Then @@ -1678,7 +1679,7 @@ Namespace ExcelOpsTests.Engines End If End With With Nothing - Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstance, TestXlsxFile.Name & "." & WorkSheetName & ".h2.html") + Dim TestHtmlOutputFile = TestEnvironment.FullPathOfDynTestFile(Me.CreateInstanceUninitialized, TestXlsxFile.Name & "." & WorkSheetName & ".h2.html") Wb.ExportSheetToHtml(WorkSheetName, TestHtmlOutputFile, New HtmlSheetExportOptions() With {.ExportSheetNameAsTitle = HtmlSheetExportOptions.SheetTitleStyles.H2}) If OPEN_HTML_OUTPUT_IN_BROWSER_AFTER_TEST Then Dim OpenFileProcess = System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo() With { diff --git a/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb index 3871178..dbd6891 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/MsExcelOpsTest.vb @@ -19,7 +19,7 @@ Namespace ExcelOpsTests.Engines Return New ExcelOps.MsExcelDataOperations(file, mode, MsExcelInstance, False, options) End Function - Protected Overrides Function _CreateInstance() As ExcelOps.MsExcelDataOperations + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.MsExcelDataOperations If MsExcelInstance Is Nothing OrElse MsExcelInstance.IsDisposed Then 'recreate excel instance MsExcelInstance = New CompuMaster.Excel.MsExcelCom.MsExcelApplicationWrapper From 0cb2065cacaa7053c016be5eb984c0b76361efc5 Mon Sep 17 00:00:00 2001 From: Jochen Wezel Date: Thu, 18 Dec 2025 17:55:41 +0100 Subject: [PATCH 6/7] fixed compile issues --- .../EpplusFreeExcelDataOperations.SharedCode.vb | 6 +++--- .../EpplusFreeExcelDataOperations.vb | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb index 9956f60..de6acc6 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb @@ -513,7 +513,7 @@ Namespace ExcelOps Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False 'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad - Me.Workbook.FullCalcOnLoad = FULL_CALC_ON_LOAD 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too + Me.Workbook.FullCalcOnLoad = Me.AutoCalculationOnLoad 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too Me.Workbook.Worksheets.Add("Sheet1") End Sub @@ -526,7 +526,7 @@ Namespace ExcelOps Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False 'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad - Me.Workbook.FullCalcOnLoad = FULL_CALC_ON_LOAD 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too + Me.Workbook.FullCalcOnLoad = Me.AutoCalculationOnLoad 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too End Sub Protected Overrides Sub LoadWorkbook(data As Byte()) @@ -545,7 +545,7 @@ Namespace ExcelOps Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False 'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad - Me.Workbook.FullCalcOnLoad = FULL_CALC_ON_LOAD 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too + Me.Workbook.FullCalcOnLoad = Me.AutoCalculationOnLoad 'unknown if executed after loading already completed or if it's a workbook setting with effect on opening as user in MS Excel, too End Sub ''' diff --git a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb index c22409b..560c30f 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb @@ -144,8 +144,6 @@ Namespace ExcelOps End Get End Property - Private Const FULL_CALC_ON_LOAD As Boolean = True - Private _WorkbookPackage As CompuMaster.Epplus4.ExcelPackage Public ReadOnly Property WorkbookPackage As CompuMaster.Epplus4.ExcelPackage Get From 7044a24240f1d97d5e64faed291fa51dafca0931 Mon Sep 17 00:00:00 2001 From: Jochen Wezel Date: Thu, 18 Dec 2025 18:02:25 +0100 Subject: [PATCH 7/7] fixed shared code copy/clone issues --- ...usPolyformExcelDataOperations.SharedCode.vb | 4 +++- ...DataXlsEpplusPolyformEditionTest.Partial.vb | 18 ++++++++++++++++++ .../Data/CmDataXlsEpplusPolyformEditionTest.vb | 9 --------- 3 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.Partial.vb diff --git a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb index 07519cf..8b41a83 100644 --- a/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb +++ b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb @@ -927,9 +927,11 @@ Namespace ExcelOps End Sub ''' - ''' Is the Excel engine allowed to automatically/continuously calculate on every change or does the user has to manually force a recalculation (typically by pressing F9 key in MS Excel) + ''' If enabled, the calculation engine will do a full recalculation after every modification. + ''' If disabled, the calculation engine is not allowed to automatically/continuously calculate on every change and the user has to manually force a recalculation (typically by pressing F9 key in MS Excel). ''' ''' + ''' Please note: this property is a workbook property (not an engine property!) Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean Get If Me._WorkbookPackage IsNot Nothing Then diff --git a/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.Partial.vb b/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.Partial.vb new file mode 100644 index 0000000..ec41f6e --- /dev/null +++ b/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.Partial.vb @@ -0,0 +1,18 @@ +Option Explicit On +Option Strict On + +Namespace Data + + Partial Public Class CmDataXlsEpplusPolyformEditionTest + + Public Sub New() + AssignLicenseContext() + End Sub + + Friend Shared Sub AssignLicenseContext() + ExcelOps.EpplusPolyformExcelDataOperations.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial + End Sub + + End Class + +End Namespace diff --git a/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb b/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb index fc4d34f..77a9829 100644 --- a/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb +++ b/ExcelOpsTest/Data/CmDataXlsEpplusPolyformEditionTest.vb @@ -5,21 +5,12 @@ Option Strict On 'SEE: clone-build-files.cmd/.sh/.ps1 'WARNING: PLEASE CHANGE THIS FILE ONLY AT REQUIRED LOCATION, OR CHANGES WILL BE LOST! -Imports CompuMaster.Excel.ExcelOps Imports NUnit.Framework Namespace Data Public Class CmDataXlsEpplusPolyformEditionTest - Public Sub New() - AssignLicenseContext() - End Sub - - Friend Shared Sub AssignLicenseContext() - ExcelOps.EpplusPolyformExcelDataOperations.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial - End Sub - Public Sub ReadDataSetFromXlsFile() Dim Path As String = TestEnvironment.FullPathOfExistingTestFile("test_data", "SampleTable01.xlsx")