Skip to content

Commit

Permalink
What-If Analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurmitha4004 committed Sep 19, 2023
1 parent 1932098 commit bca7a37
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Apply_Scenario</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.NET" Version="23.1.36" />
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Create_Scenarios</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.NET" Version="23.1.36" />
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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<object> currentChangePercentage_Values = new List<object> { 0.23, 0.8, 1.1, 0.5, 0.35, 0.2 };
List<object> increasedChangePercentage_Values = new List<object> { 0.45, 0.56, 0.9, 0.5, 0.58, 0.43 };
List<object> decreasedChangePercentage_Values = new List<object> { 0.3, 0.2, 0.5, 0.3, 0.5, 0.23 };
List<object> currentQuantity_Values = new List<object> { 1500, 3000, 5000, 4000, 500, 4000 };
List<object> increasedQuantity_Values = new List<object> { 1000, 5000, 4500, 3900, 10000, 8900 };
List<object> decreasedQuantity_Values = new List<object> { 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();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Hide_Scenario</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.NET" Version="23.1.36" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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();

}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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();

}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Protect_Scenario</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.NET" Version="23.1.36" />
</ItemGroup>

</Project>

0 comments on commit bca7a37

Please sign in to comment.