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..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 ''' @@ -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..560c30f 100644 --- a/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb +++ b/ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb @@ -19,9 +19,66 @@ 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 + + ''' + ''' 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 + ''' + ''' + ''' 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 +86,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 +95,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 +104,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 +113,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,21 +122,18 @@ 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 - ''' - ''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook) - ''' - Public Sub New() - Me.New(Nothing) - 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 @@ -82,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 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..8b41a83 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 ''' @@ -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-EpplusPolyform/EpplusPolyformExcelDataOperations.vb b/ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.vb index 2b2560f..335dd80 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,22 +153,46 @@ 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) 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() - Me.New(Nothing) + ''' + 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 ''' ''' 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 +204,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..3eb2a68 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,35 +87,59 @@ 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 ''' - ''' 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. ''' - Public Sub New() - Me.New(Nothing) + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(mode, options) End Sub ''' @@ -86,6 +150,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..0bdd3c9 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(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Try wb.RecalculateAll() wb.Save() diff --git a/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb b/ExcelOps-MicrosoftExcel/ExcelOpsLowLevel/MsExcelDataOperations.vb index a7c30cc..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 @@ -40,10 +41,19 @@ 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!) + ''' 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 @@ -53,14 +63,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 @@ -70,8 +84,8 @@ Namespace Global.CompuMaster.Excel.ExcelOps ''' End Try ''' ''' - Public Sub New() - Me.New(Nothing) + Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions) + MyBase.New(mode, options) End Sub ''' @@ -87,6 +101,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 +120,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 +140,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 +161,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 +182,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 +195,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 +207,71 @@ 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) + Me.ExecuteOpenModeActions(file, mode, options) + 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 +388,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 AndAlso Me._Workbook 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 AndAlso Me._Workbook 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 +1204,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..2d2c27a 100644 --- a/ExcelOps-SpireXls/SpireXlsDataOperations.vb +++ b/ExcelOps-SpireXls/SpireXlsDataOperations.vb @@ -16,6 +16,47 @@ 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) + 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 + + ''' + ''' Open a workbook + ''' + ''' + ''' 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 + + ''' + ''' Open a workbook + ''' + ''' + ''' 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 + ''' ''' 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 +65,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 +80,58 @@ 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) - 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) + 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) - 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) + 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/ - Public Sub New() - Me.New(Nothing) + ''' + 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 ''' @@ -71,6 +139,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..d9e4b46 100644 --- a/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsBase.vb @@ -1,7 +1,9 @@ Option Explicit On Option Strict On + Imports System.IO Imports System.Text +Imports CompuMaster.Excel.ExcelOps.ExcelDataOperationsOptions Namespace ExcelOps @@ -11,10 +13,146 @@ 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 + ''' + ''' 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) + 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") + 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) + If options.FileWriteProtection = WriteProtectionMode.DefaultBehaviourOnCreateFile Then + Me.ReadOnly = (file = Nothing) + End If + Case OpenMode.Uninitialized + 'do nothing + Case Else + 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 + ''' + ''' + ''' 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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) + 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 +162,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 +173,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 +190,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 +210,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 +228,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 +243,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 +251,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 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 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 enabled, the calculation engine will do a full recalculation after every modification + ''' If calculation module is enabled and also AutoCalculationOnLoad is enabled, then AutoCalculationOnLoad is enabled effectively (regardless of AutoCalculationEnabled setting) ''' ''' - Public MustOverride Property AutoCalculationEnabled As Boolean + 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 +397,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 +405,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 +422,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 @@ -200,7 +440,7 @@ Namespace ExcelOps ''' Apply CachedCalculation setting ''' ''' - + Protected Overridable Sub SaveInternal_ApplyCachedCalculationOption(cachedCalculationsOption As SaveOptionsForDisabledCalculationEngines) If cachedCalculationsOption = SaveOptionsForDisabledCalculationEngines.DefaultBehaviour Then cachedCalculationsOption = SaveOptionsForDisabledCalculationEngines.NoReset @@ -226,8 +466,9 @@ 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) Me.SaveAs(filePath, SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) End Sub @@ -236,6 +477,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 +491,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 +692,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 +719,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 +750,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 +762,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 @@ -1675,8 +1908,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 new file mode 100644 index 0000000..00e9b0d --- /dev/null +++ b/ExcelOps/ExcelOpsLowLevel/ExcelDataOperationsOptions.vb @@ -0,0 +1,131 @@ +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 + + 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 + ''' + ''' 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] = 1 + ''' + ''' No limitation + ''' + ReadWrite = 4 + 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..df12c26 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,12 +8,12 @@ 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 - Return New ExcelOps.FreeSpireXlsDataOperations() + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.FreeSpireXlsDataOperations + Return New ExcelOps.FreeSpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() @@ -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..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, False, String.Empty) + 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-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..d3e5190 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 @@ -11,12 +12,12 @@ 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 - Return New ExcelOps.SpireXlsDataOperations() + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.SpireXlsDataOperations + Return New ExcelOps.SpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() @@ -36,13 +37,13 @@ Namespace ExcelOpsTests.Engines Public Sub IsLicensedContext() '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.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.CreateInstance(Nothing, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, True, Nothing)) + 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 @@ -50,12 +51,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..fd211b2 100644 --- a/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb +++ b/ExcelOpsTest-SpireXls/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestSpireXls.vb @@ -15,13 +15,16 @@ 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 + ExcelOps.SpireXlsDataOperations.AllowInstancingForNonLicencedContextForTestingPurposesOnly = True + Result = (New ExcelOps.SpireXlsDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized)).EngineName + End If 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, False, String.Empty) + 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-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.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/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb b/ExcelOpsTest/ExcelOpsTests.Engines/EpplusFreeFixCalcsEditionOpsTest.vb index 5c89302..226f0b9 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 @@ -7,27 +8,27 @@ 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 - Return New ExcelOps.EpplusFreeExcelDataOperations() + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.EpplusFreeExcelDataOperations + Return New ExcelOps.EpplusFreeExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() 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..985e0ef 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,24 +16,24 @@ 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 - Return New ExcelOps.EpplusPolyformExcelDataOperations() + Protected Overrides Function _CreateInstanceUninitialized() As ExcelOps.EpplusPolyformExcelDataOperations + Return New ExcelOps.EpplusPolyformExcelDataOperations(ExcelDataOperationsBase.OpenMode.Uninitialized) End Function Public Overrides Sub CopySheetContent() 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..c024b00 100644 --- a/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb +++ b/ExcelOpsTest/ExcelOpsTests.Engines/ExcelOpsTestBase.vb @@ -17,21 +17,21 @@ 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, [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 ''' ''' 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 @@ -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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly))) Catch ex As PlatformNotSupportedException Assert.Ignore("Platform not supported: " & ex.Message) Catch ex As CompuMaster.ComInterop.ComApplicationNotAvailableException @@ -212,15 +180,15 @@ 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() 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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)).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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)).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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) 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(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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) 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(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(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, True, "") + Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) 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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) End Sub) Else - Wb = Me.CreateInstance(Data, "") + Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) 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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) End Sub) Else - Wb = Me.CreateInstance(Data, "") + Wb = Me.CreateInstance(Data, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) 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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) 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(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, True, "dummy") + Wb = Me.CreateInstance(NewXlsxTargetPath, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, New ExcelDataOperationsOptions(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly, "dummy")) Assert.AreEqual("Grunddaten", Wb.SheetNames(0)) End Sub @@ -349,19 +317,19 @@ 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() TestFile = Nothing - Wb = Me.CreateInstance(TestFile, ExcelOps.ExcelDataOperationsBase.OpenMode.CreateFile, False, "") + 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, False, "") + 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() @@ -369,12 +337,16 @@ 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, False, "") - 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() @@ -386,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, False, "") + 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, False, "") + 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) @@ -410,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, True, "") + 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) @@ -423,7 +395,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadWrite)) Assert.AreEqual(False, Wb.ReadOnly) Assert.AreEqual(TestFile, Wb.FilePath) Assert.AreEqual(TestFile, Wb.WorkbookFilePath) @@ -440,18 +412,19 @@ 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) End Select workbook.Close() - workbook = Me.CreateInstance(Nothing, ExcelDataOperationsBase.OpenMode.CreateFile, True, Nothing) + 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() @@ -467,14 +440,14 @@ 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) 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(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) @@ -489,7 +462,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim SheetName As String SheetName = "ZahlenUndProzentwerte" Assert.AreEqual("0.00", eppeo.LookupCellFormat(SheetName, 0, 1)) @@ -505,7 +478,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Const SheetName As String = "MergedCellsTest" Assert.True(eppeo.IsMergedCell(SheetName, 0, 0)) Assert.True(eppeo.IsMergedCell(SheetName, 1, 0)) @@ -520,7 +493,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Const SheetName As String = "MergedCellsTest" Assert.True(eppeo.IsMergedCell(SheetName, 0, 0)) Assert.True(eppeo.IsMergedCell(SheetName, 2, 2)) @@ -535,12 +508,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(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, True, Nothing) + 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 @@ -548,7 +521,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Const SheetName As String = "MergedCellsTest" Try Assert.AreEqual(2, eppeo.LookupLastCell(SheetName).ColumnIndex) @@ -574,14 +547,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(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, True, Nothing) + 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)) @@ -593,7 +566,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(0, eppeo.SheetIndex("data")) Assert.AreEqual(1, eppeo.SheetIndex("chart")) Assert.AreEqual(-1, eppeo.SheetIndex("doesntexist")) @@ -605,7 +578,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) EppeoSheetNamesList = eppeo.WorkSheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) @@ -616,7 +589,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(0, eppeo.WorkSheetIndex("data")) Assert.AreEqual(-1, eppeo.WorkSheetIndex("chart")) End Sub @@ -626,7 +599,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Ausgewählt")) @@ -640,13 +613,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(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, True, Nothing) + 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) @@ -657,7 +630,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) eppeo.SelectSheet("Kostenplanung") eppeo.SaveAs(TestEnvironment.FullPathOfDynTestFile(eppeo, "SelectedSheet.Kostenplanung.xlsx"), ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.NoReset) System.Console.WriteLine("OUT: " & eppeo.FilePath) @@ -670,7 +643,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.That(eppeo.SelectedSheetName, [Is].EqualTo("Onboarding offen")) eppeo.SelectSheet("Upload erledigt") @@ -683,7 +656,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) EppeoSheetNamesList = eppeo.ChartSheetNames System.Console.WriteLine("## " & System.IO.Path.GetFileName(TestFileName)) System.Console.WriteLine(Strings.Join(EppeoSheetNamesList.ToArray, ",")) @@ -694,7 +667,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual(0, eppeo.ChartSheetIndex("chart")) Assert.AreEqual(-1, eppeo.ChartSheetIndex("data")) End Sub @@ -707,7 +680,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim ExpectedSheetNamesList, NewSheetNamesList As List(Of String) ExpectedSheetNamesList = eppeo.SheetNames ExpectedSheetNamesList.Add(SheetNameBottomPosition) @@ -725,7 +698,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) AllFormulas = eppeo.AllFormulasOfWorkbook Console.WriteLine("Test file: " & TestControllingToolFileName) Assert.NotZero(AllFormulas.Count) @@ -750,7 +723,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim SheetName As String = wb.SheetNames(0) wb.WriteCellFormula(SheetName, 0, 0, "B2", False) @@ -790,7 +763,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual("E40", eppeo.LookupLastCell(TestSheet).Address) Assert.AreEqual(39, eppeo.LookupLastRowIndex(TestSheet)) Assert.AreEqual(4, eppeo.LookupLastColumnIndex(TestSheet)) @@ -801,7 +774,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) TestSheet = "MergedCellsTest" Assert.AreEqual("C3", eppeo.LookupLastCell(TestSheet).Address) Assert.AreEqual(2, eppeo.LookupLastRowIndex(TestSheet)) @@ -813,7 +786,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Assert.AreEqual("E40", eppeo.LookupLastContentCell(TestSheet).Address) Assert.AreEqual(39, eppeo.LookupLastContentRowIndex(TestSheet)) Assert.AreEqual(4, eppeo.LookupLastContentColumnIndex(TestSheet)) @@ -825,7 +798,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) TestSheet = "MergedCellsTest" Assert.AreEqual("C3", eppeo.LookupLastContentCell(TestSheet).Address) Assert.AreEqual(2, eppeo.LookupLastContentRowIndex(TestSheet)) @@ -875,7 +848,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -932,7 +905,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -988,7 +961,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D " & ControlChars.CrLf & @@ -1045,7 +1018,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -1103,7 +1076,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) ExpectedMatrix = "# |A |B |C |D |E " & ControlChars.CrLf & @@ -1169,7 +1142,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) '## Expected matrix like following '"# |A |B |C |D |E @@ -1220,7 +1193,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Select Case variantOfImage Case 0 'master Workbook.WriteCellValue(Of String)(New ExcelCell("data", "B1", ExcelCell.ValueTypes.All), "Sample Chart") @@ -1267,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")) @@ -1321,7 +1294,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable) '## Expected matrix like following @@ -1336,7 +1309,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 @@ -1353,7 +1326,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Console.WriteLine(eppeo.SheetContentMatrix(TestSheet, ExcelDataOperationsBase.MatrixContent.Errors).ToUIExcelTable) '## Expected matrix like following @@ -1368,7 +1341,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)") @@ -1390,7 +1363,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture01.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1416,7 +1389,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture02.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1442,7 +1415,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(ExcelDataOperationsOptions.WriteProtectionMode.ReadOnly)) Dim OutputFile As String = TestEnvironment.FullPathOfDynTestFile(Workbook.GetType, "test_embeddedpicture02.xlsx") Workbook.SaveAs(OutputFile, ExcelDataOperationsBase.SaveOptionsForDisabledCalculationEngines.DefaultBehaviour) Catch ex As PlatformNotSupportedException @@ -1471,26 +1444,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(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)" - 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 +1515,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 +1538,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 +1580,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(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}) @@ -1602,7 +1605,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(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}) @@ -1614,7 +1617,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(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}) @@ -1626,7 +1629,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(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}) @@ -1650,12 +1653,12 @@ 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 Try - Wb = Me.CreateInstance(TestXlsxFile.FullName, ExcelOps.ExcelDataOperationsBase.OpenMode.OpenExistingFile, True, Nothing, True) + 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 @@ -1665,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 @@ -1676,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 3118019..dbd6891 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,24 +9,24 @@ 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, 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 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(ExcelDataOperationsBase.OpenMode.Uninitialized) 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..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, True, Nothing) + 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, True, Nothing) + 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, 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(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 9f89652..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, False, String.Empty) + 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 1594a7b..34f6e48 100644 --- a/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb +++ b/ExcelOpsTest/ExcelOpsTests.MsExcelSpecials/MsExcelCalcTestEpplusPolyform.vb @@ -20,14 +20,16 @@ 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 + End If 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, False, String.Empty) + 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/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..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, true, null); +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, true, null); +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); @@ -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(ExcelDataOperationsOptions.WriteProtectionMode.DefaultBehaviourOnCreateFile)); System.Console.WriteLine("Engine=" + workbook.EngineName); FirstSheetName = workbook.SheetNames()[0]; workbook.WriteCellValue(FirstSheetName, 0, 0, 123);