Skip to content

Commit 157d87d

Browse files
authored
11 redesign all constructors (#13)
implemented #11 * redesigned constructors and engine/workbook default options (old constructors remained for compatibility reasons, but marked as obsolete) * fixed several issues found in unit tests which were not tested automatically in CI/CD pipeline
1 parent 589fe1d commit 157d87d

36 files changed

Lines changed: 1262 additions & 374 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Imports System
2+
Imports System.Reflection
3+
Imports System.Runtime.InteropServices
4+
5+
<Assembly: AssemblyTrademark("camm")>
6+
<Assembly: ComVisible(False)>
7+
8+
<Assembly: Runtime.CompilerServices.InternalsVisibleTo("CompuMaster.Excel.Test")>

ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.SharedCode.vb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ Namespace ExcelOps
513513
Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False
514514

515515
'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad
516-
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
516+
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
517517
Me.Workbook.Worksheets.Add("Sheet1")
518518
End Sub
519519

@@ -526,7 +526,7 @@ Namespace ExcelOps
526526
Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False
527527

528528
'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad
529-
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
529+
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
530530
End Sub
531531

532532
Protected Overrides Sub LoadWorkbook(data As Byte())
@@ -545,7 +545,7 @@ Namespace ExcelOps
545545
Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False
546546

547547
'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad
548-
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
548+
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
549549
End Sub
550550

551551
''' <summary>
@@ -927,18 +927,27 @@ Namespace ExcelOps
927927
End Sub
928928

929929
''' <summary>
930-
''' 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)
930+
''' If enabled, the calculation engine will do a full recalculation after every modification.
931+
''' 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).
931932
''' </summary>
932933
''' <returns></returns>
933-
Public Overrides Property AutoCalculationEnabled As Boolean
934+
''' <remarks>Please note: this property is a workbook property (not an engine property!)</remarks>
935+
Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean
934936
Get
935-
Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic)
937+
If Me._WorkbookPackage IsNot Nothing Then
938+
Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic)
939+
Else
940+
Return MyBase.AutoCalculationEnabledWorkbookSetting
941+
End If
936942
End Get
937943
Set(value As Boolean)
938-
If value Then
939-
Me.Workbook.CalcMode = ExcelCalcMode.Automatic
940-
Else
941-
Me.Workbook.CalcMode = ExcelCalcMode.Manual
944+
MyBase.AutoCalculationEnabledWorkbookSetting = value
945+
If Me._WorkbookPackage IsNot Nothing Then
946+
If value Then
947+
Me.Workbook.CalcMode = ExcelCalcMode.Automatic
948+
Else
949+
Me.Workbook.CalcMode = ExcelCalcMode.Manual
950+
End If
942951
End If
943952
End Set
944953
End Property

ExcelOps-EpplusFreeFixCalcsEdition/EpplusFreeExcelDataOperations.vb

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,59 +19,121 @@ Namespace ExcelOps
1919
Public Class EpplusFreeExcelDataOperations
2020
Inherits ExcelDataOperationsBase
2121

22+
Protected Overrides ReadOnly Property DefaultCalculationOptions As ExcelEngineDefaultOptions
23+
Get
24+
Return New ExcelEngineDefaultOptions(False, True)
25+
End Get
26+
End Property
27+
28+
''' <summary>
29+
''' 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)
30+
''' </summary>
31+
''' <param name="file">Path to a file which shall be loaded or null if a new workbook shall be created</param>
32+
''' <param name="mode">Open an existing file or (re)create a new file</param>
33+
''' <param name="options">File and engine options</param>
34+
''' <remarks>
35+
''' 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.
36+
''' See https://www.e-iceblue.com/ for more details on limitations and licensing.
37+
''' </remarks>
38+
Public Sub New(file As String, mode As OpenMode, options As ExcelDataOperationsOptions)
39+
MyBase.New(file, mode, options)
40+
End Sub
41+
42+
''' <summary>
43+
''' Create a new workbook or just create an uninitialized instance of this Excel engine
44+
''' </summary>
45+
''' <param name="mode"></param>
46+
Public Sub New(mode As OpenMode)
47+
MyBase.New(mode)
48+
End Sub
49+
50+
''' <summary>
51+
''' Create a new workbook or just create an uninitialized instance of this Excel engine
52+
''' </summary>
53+
''' <param name="mode"></param>
54+
''' <param name="options"></param>
55+
Public Sub New(mode As OpenMode, options As ExcelDataOperationsOptions)
56+
MyBase.New(mode, options)
57+
End Sub
58+
59+
''' <summary>
60+
''' Open a workbook
61+
''' </summary>
62+
''' <param name="data"></param>
63+
''' <param name="options">File and engine options</param>
64+
Public Sub New(data As Byte(), options As ExcelDataOperationsOptions)
65+
MyBase.New(data, options)
66+
End Sub
67+
68+
''' <summary>
69+
''' Open a workbook
70+
''' </summary>
71+
''' <param name="data"></param>
72+
''' <param name="options">File and engine options</param>
73+
Public Sub New(data As System.IO.Stream, options As ExcelDataOperationsOptions)
74+
MyBase.New(data, options)
75+
End Sub
76+
2277
''' <summary>
2378
''' Create or open a workbook
2479
''' </summary>
80+
<Obsolete("Use overloaded method with ExcelDataOperationsOptions", False)>
81+
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
2582
Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String, disableInitialCalculation As Boolean)
2683
MyBase.New(file, mode, Not disableInitialCalculation, False, [readOnly], passwordForOpening)
2784
End Sub
2885

2986
''' <summary>
3087
''' Create or open a workbook
3188
''' </summary>
89+
<Obsolete("Use overloaded method with ExcelDataOperationsOptions", False)>
90+
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
3291
Public Sub New(file As String, mode As OpenMode, [readOnly] As Boolean, passwordForOpening As String)
3392
MyBase.New(file, mode, False, True, [readOnly], passwordForOpening)
3493
End Sub
3594

3695
''' <summary>
3796
''' Open a workbook
3897
''' </summary>
98+
<Obsolete("Use overloaded method with ExcelDataOperationsOptions", False)>
99+
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
39100
Public Sub New(data As Byte(), passwordForOpening As String)
40101
MyBase.New(data, False, True, passwordForOpening)
41102
End Sub
42103

43104
''' <summary>
44105
''' Open a workbook
45106
''' </summary>
107+
<Obsolete("Use overloaded method with ExcelDataOperationsOptions", False)>
108+
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
46109
Public Sub New(data As Byte(), passwordForOpening As String, disableInitialCalculation As Boolean)
47110
MyBase.New(data, Not disableInitialCalculation, True, passwordForOpening)
48111
End Sub
49112

50113
''' <summary>
51114
''' Open a workbook
52115
''' </summary>
116+
<Obsolete("Use overloaded method with ExcelDataOperationsOptions", False)>
117+
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
53118
Public Sub New(data As System.IO.Stream, passwordForOpening As String)
54119
MyBase.New(data, False, True, passwordForOpening)
55120
End Sub
56121

57122
''' <summary>
58123
''' Open a workbook
59124
''' </summary>
125+
<Obsolete("Use overloaded method with ExcelDataOperationsOptions", False)>
126+
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
60127
Public Sub New(data As System.IO.Stream, passwordForOpening As String, disableInitialCalculation As Boolean)
61128
MyBase.New(data, Not disableInitialCalculation, True, passwordForOpening)
62129
End Sub
63130

64-
''' <summary>
65-
''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook)
66-
''' </summary>
67-
Public Sub New()
68-
Me.New(Nothing)
69-
End Sub
70-
71131
''' <summary>
72132
''' Create a new instance for accessing Excel workbooks (still requires creating or loading of a workbook)
73133
''' </summary>
74134
''' <param name="passwordForOpeningOnNextTime">Pre-define encryption password on future save actions</param>
135+
<Obsolete("Use overloaded method with ExcelDataOperationsOptions", False)>
136+
<System.ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
75137
Public Sub New(passwordForOpeningOnNextTime As String)
76138
MyBase.New(False, True, True, passwordForOpeningOnNextTime)
77139
End Sub
@@ -82,8 +144,6 @@ Namespace ExcelOps
82144
End Get
83145
End Property
84146

85-
Private Const FULL_CALC_ON_LOAD As Boolean = True
86-
87147
Private _WorkbookPackage As CompuMaster.Epplus4.ExcelPackage
88148
Public ReadOnly Property WorkbookPackage As CompuMaster.Epplus4.ExcelPackage
89149
Get
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Imports System
2+
Imports System.Reflection
3+
Imports System.Runtime.InteropServices
4+
5+
<Assembly: AssemblyTrademark("camm")>
6+
<Assembly: ComVisible(False)>
7+
8+
<Assembly: Runtime.CompilerServices.InternalsVisibleTo("CompuMaster.Excel.Test")>

ExcelOps-EpplusPolyform/EpplusPolyformExcelDataOperations.SharedCode.vb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ Namespace ExcelOps
513513
Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False
514514

515515
'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad
516-
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
516+
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
517517
Me.Workbook.Worksheets.Add("Sheet1")
518518
End Sub
519519

@@ -526,7 +526,7 @@ Namespace ExcelOps
526526
Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False
527527

528528
'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad
529-
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
529+
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
530530
End Sub
531531

532532
Protected Overrides Sub LoadWorkbook(data As Byte())
@@ -545,7 +545,7 @@ Namespace ExcelOps
545545
Me._WorkbookPackage.Compatibility.IsWorksheets1Based = False
546546

547547
'set workbook FullCalcOnLoad always to False since it's already triggered using property of Me.AutoCalculationOnLoad
548-
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
548+
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
549549
End Sub
550550

551551
''' <summary>
@@ -927,18 +927,27 @@ Namespace ExcelOps
927927
End Sub
928928

929929
''' <summary>
930-
''' 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)
930+
''' If enabled, the calculation engine will do a full recalculation after every modification.
931+
''' 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).
931932
''' </summary>
932933
''' <returns></returns>
933-
Public Overrides Property AutoCalculationEnabled As Boolean
934+
''' <remarks>Please note: this property is a workbook property (not an engine property!)</remarks>
935+
Public Overrides Property AutoCalculationEnabledWorkbookSetting As Boolean
934936
Get
935-
Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic)
937+
If Me._WorkbookPackage IsNot Nothing Then
938+
Return (Me.Workbook.CalcMode = ExcelCalcMode.Automatic)
939+
Else
940+
Return MyBase.AutoCalculationEnabledWorkbookSetting
941+
End If
936942
End Get
937943
Set(value As Boolean)
938-
If value Then
939-
Me.Workbook.CalcMode = ExcelCalcMode.Automatic
940-
Else
941-
Me.Workbook.CalcMode = ExcelCalcMode.Manual
944+
MyBase.AutoCalculationEnabledWorkbookSetting = value
945+
If Me._WorkbookPackage IsNot Nothing Then
946+
If value Then
947+
Me.Workbook.CalcMode = ExcelCalcMode.Automatic
948+
Else
949+
Me.Workbook.CalcMode = ExcelCalcMode.Manual
950+
End If
942951
End If
943952
End Set
944953
End Property

0 commit comments

Comments
 (0)