diff --git a/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario.sln b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario.sln new file mode 100644 index 00000000..30595ee9 --- /dev/null +++ b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply Scenario", "Apply Scenario\Apply Scenario.csproj", "{F380A41E-6685-477D-9009-25CCA7A67887}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F380A41E-6685-477D-9009-25CCA7A67887}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F380A41E-6685-477D-9009-25CCA7A67887}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F380A41E-6685-477D-9009-25CCA7A67887}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F380A41E-6685-477D-9009-25CCA7A67887}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {752640F0-7359-486C-800B-806D15A22152} + EndGlobalSection +EndGlobal diff --git a/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Apply Scenario.csproj b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Apply Scenario.csproj new file mode 100644 index 00000000..adaf156d --- /dev/null +++ b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Apply Scenario.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + Apply_Scenario + enable + enable + + + + + + + diff --git a/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Data/WhatIfAnalysisTemplate.xlsx b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Data/WhatIfAnalysisTemplate.xlsx new file mode 100644 index 00000000..64604f0a Binary files /dev/null and b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Data/WhatIfAnalysisTemplate.xlsx differ diff --git a/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Program.cs b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Program.cs new file mode 100644 index 00000000..8d7ddb3c --- /dev/null +++ b/What-If Analysis/Apply Scenario/NET Standard/Apply Scenario/Apply Scenario/Program.cs @@ -0,0 +1,50 @@ +using System.IO; +using Syncfusion.XlsIO; +using System; +using static System.Net.Mime.MediaTypeNames; + +namespace Apply_Scenario +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream inputStream = new FileStream("../../../Data/WhatIfAnalysisTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic); + inputStream.Dispose(); + + IWorksheet worksheet = workbook.Worksheets[0]; + + //Access the collection of scenarios in the worksheet + IScenarios scenarios = worksheet.Scenarios; + + for (int pos = 0; pos < scenarios.Count; pos++) + { + //Apply scenarios + scenarios[pos].Show(); + + IWorkbook newBook = excelEngine.Excel.Workbooks.Create(0); + + IWorksheet newSheet = newBook.Worksheets.AddCopy(worksheet); + + newSheet.Name = scenarios[pos].Name; + + //Saving the new workbook as a stream + using (FileStream stream = new FileStream(scenarios[pos].Name + ".xlsx", FileMode.Create, FileAccess.ReadWrite)) + { + newBook.SaveAs(stream); + } + + //To restore the cell values from the previous scenario results + scenarios["Current % of Change"].Show(); + scenarios["Current Quantity"].Show(); + } + } + } + } +} \ No newline at end of file diff --git a/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios.sln b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios.sln new file mode 100644 index 00000000..7c17285f --- /dev/null +++ b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create Scenarios", "Create Scenarios\Create Scenarios.csproj", "{7D535C40-18F4-438A-B8BD-47F41D3A826B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7D535C40-18F4-438A-B8BD-47F41D3A826B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D535C40-18F4-438A-B8BD-47F41D3A826B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D535C40-18F4-438A-B8BD-47F41D3A826B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D535C40-18F4-438A-B8BD-47F41D3A826B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {099D2397-528B-4ADE-89B0-7F198AFD3DB5} + EndGlobalSection +EndGlobal diff --git a/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Create Scenarios.csproj b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Create Scenarios.csproj new file mode 100644 index 00000000..716df41e --- /dev/null +++ b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Create Scenarios.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + Create_Scenarios + enable + enable + + + + + + + diff --git a/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Data/WhatIfAnalysisTemplate.xlsx b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Data/WhatIfAnalysisTemplate.xlsx new file mode 100644 index 00000000..df5aa45c Binary files /dev/null and b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Data/WhatIfAnalysisTemplate.xlsx differ diff --git a/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Program.cs b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Program.cs new file mode 100644 index 00000000..5856ca9d --- /dev/null +++ b/What-If Analysis/Create Scenarios/NET Standard/Create Scenarios/Create Scenarios/Program.cs @@ -0,0 +1,59 @@ +using System.IO; +using Syncfusion.XlsIO; +using System; + +namespace Create_Scenarios +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream inputStream = new FileStream("../../../Data/WhatIfAnalysisTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic); + inputStream.Dispose(); + + IWorksheet worksheet = workbook.Worksheets[0]; + + // Access the collection of scenarios in the worksheet + IScenarios scenarios = worksheet.Scenarios; + + //Initialize list objects with different values for scenarios + List currentChangePercentage_Values = new List { 0.23, 0.8, 1.1, 0.5, 0.35, 0.2 }; + List increasedChangePercentage_Values = new List { 0.45, 0.56, 0.9, 0.5, 0.58, 0.43 }; + List decreasedChangePercentage_Values = new List { 0.3, 0.2, 0.5, 0.3, 0.5, 0.23 }; + List currentQuantity_Values = new List { 1500, 3000, 5000, 4000, 500, 4000 }; + List increasedQuantity_Values = new List { 1000, 5000, 4500, 3900, 10000, 8900 }; + List decreasedQuantity_Values = new List { 1000, 2000, 3000, 3000, 300, 4000 }; + + //Add scenarios in the worksheet with different values for the same cells + scenarios.Add("Current % of Change", worksheet.Range["F5:F10"], currentChangePercentage_Values); + scenarios.Add("Increased % of Change", worksheet.Range["F5:F10"], increasedChangePercentage_Values); + scenarios.Add("Decreased % of Change", worksheet.Range["F5:F10"], decreasedChangePercentage_Values); + scenarios.Add("Current Quantity", worksheet.Range["D5:D10"], currentQuantity_Values); + scenarios.Add("Increased Quantity", worksheet.Range["D5:D10"], increasedQuantity_Values); + scenarios.Add("Decreased Quantity", worksheet.Range["D5:D10"], decreasedQuantity_Values); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream("CreateScenarios.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + + System.Diagnostics.Process process = new System.Diagnostics.Process(); + process.StartInfo = new System.Diagnostics.ProcessStartInfo("CreateScenarios.xlsx") + { + UseShellExecute = true + }; + process.Start(); + } + } + } +} \ No newline at end of file diff --git a/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario.sln b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario.sln new file mode 100644 index 00000000..f366fb64 --- /dev/null +++ b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hide Scenario", "Hide Scenario\Hide Scenario.csproj", "{AD9B8124-B5F6-45A8-89F9-4751CED04851}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AD9B8124-B5F6-45A8-89F9-4751CED04851}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AD9B8124-B5F6-45A8-89F9-4751CED04851}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD9B8124-B5F6-45A8-89F9-4751CED04851}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AD9B8124-B5F6-45A8-89F9-4751CED04851}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {30FEDFFF-0378-4048-9B3F-BB61BE8CB1EF} + EndGlobalSection +EndGlobal diff --git a/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Data/WhatIfAnalysisTemplate.xlsx b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Data/WhatIfAnalysisTemplate.xlsx new file mode 100644 index 00000000..64604f0a Binary files /dev/null and b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Data/WhatIfAnalysisTemplate.xlsx differ diff --git a/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Hide Scenario.csproj b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Hide Scenario.csproj new file mode 100644 index 00000000..5de51b35 --- /dev/null +++ b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Hide Scenario.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + Hide_Scenario + enable + enable + + + + + + + diff --git a/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Program.cs b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Program.cs new file mode 100644 index 00000000..c1c5d9db --- /dev/null +++ b/What-If Analysis/Hide Scenario/NET Standard/Hide Scenario/Hide Scenario/Program.cs @@ -0,0 +1,51 @@ +using System.IO; +using Syncfusion.XlsIO; +using System; +using static System.Net.Mime.MediaTypeNames; + +namespace Hide_Scenario +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream inputStream = new FileStream("../../../Data/WhatIfAnalysisTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic); + inputStream.Dispose(); + + IWorksheet worksheet = workbook.Worksheets[0]; + + //Access the collection of scenarios in the worksheet + IScenarios scenarios = worksheet.Scenarios; + + //Disable the protection for a specific scenario + scenarios["Increased % of Change"].Hidden = true; + + //Enable worksheet protection + worksheet.Protect("Scenario"); + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream("HideScenario.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + + System.Diagnostics.Process process = new System.Diagnostics.Process(); + process.StartInfo = new System.Diagnostics.ProcessStartInfo("HideScenario.xlsx") + { + UseShellExecute = true + }; + process.Start(); + + } + } + } +} \ No newline at end of file diff --git a/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario.sln b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario.sln new file mode 100644 index 00000000..0872c2bb --- /dev/null +++ b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Protect Scenario", "Protect Scenario\Protect Scenario.csproj", "{9F5FE4FF-257F-4A59-8841-D89D1A709DA5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9F5FE4FF-257F-4A59-8841-D89D1A709DA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F5FE4FF-257F-4A59-8841-D89D1A709DA5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F5FE4FF-257F-4A59-8841-D89D1A709DA5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F5FE4FF-257F-4A59-8841-D89D1A709DA5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2D2852E4-1761-48E4-A61C-0D2328660647} + EndGlobalSection +EndGlobal diff --git a/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Data/WhatIfAnalysisTemplate.xlsx b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Data/WhatIfAnalysisTemplate.xlsx new file mode 100644 index 00000000..64604f0a Binary files /dev/null and b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Data/WhatIfAnalysisTemplate.xlsx differ diff --git a/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Program.cs b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Program.cs new file mode 100644 index 00000000..8489a7f4 --- /dev/null +++ b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Program.cs @@ -0,0 +1,51 @@ +using System.IO; +using Syncfusion.XlsIO; +using System; +using static System.Net.Mime.MediaTypeNames; + +namespace Protect_Scenario +{ + class Program + { + static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + + FileStream inputStream = new FileStream("../../../Data/WhatIfAnalysisTemplate.xlsx", FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream, ExcelOpenType.Automatic); + inputStream.Dispose(); + + IWorksheet worksheet = workbook.Worksheets[0]; + + //Enable worksheet protection + worksheet.Protect("scenario"); + + // Access the collection of scenarios in the worksheet + IScenarios scenarios = worksheet.Scenarios; + + //To make a scenario editable after protecting the sheet + scenarios[0].Locked = false; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream("ProtectScenario.xlsx", FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + + System.Diagnostics.Process process = new System.Diagnostics.Process(); + process.StartInfo = new System.Diagnostics.ProcessStartInfo("ProtectScenario.xlsx") + { + UseShellExecute = true + }; + process.Start(); + + } + } + } +} \ No newline at end of file diff --git a/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Protect Scenario.csproj b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Protect Scenario.csproj new file mode 100644 index 00000000..96d4eee6 --- /dev/null +++ b/What-If Analysis/Protect Scenario/NET Standard/Protect Scenario/Protect Scenario/Protect Scenario.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + Protect_Scenario + enable + enable + + + + + + +