Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Kb Samples #110

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Multiple dependent dropdown", "Multiple dependent dropdown\Multiple dependent dropdown.csproj", "{F83D925D-7DC9-4462-B424-010AE9A1B411}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F83D925D-7DC9-4462-B424-010AE9A1B411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F83D925D-7DC9-4462-B424-010AE9A1B411}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F83D925D-7DC9-4462-B424-010AE9A1B411}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F83D925D-7DC9-4462-B424-010AE9A1B411}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9BBF736E-F406-436F-BB79-D1406337F6F1}
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>net8.0</TargetFramework>
<RootNamespace>Multiple_dependent_dropdown</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="26.1.40" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using Syncfusion.Office;
using Syncfusion.XlsIO;
using System.Data.Common;

namespace Mulitple_depenedent_dropdown
{
class Program
{
public static void Main(string[] args)
{
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet worksheet = workbook.Worksheets[0];

//Set name range
IName name1 = workbook.Names.Add("Country");
name1.RefersToRange = worksheet.Range["A2:A5"];

IName name2 = workbook.Names.Add("India");
name2.RefersToRange = worksheet.Range["B2:B6"];

IName name3 = workbook.Names.Add("Brazil");
name3.RefersToRange = worksheet.Range["B7:B10"];

IName name4 = workbook.Names.Add("Australia");
name4.RefersToRange = worksheet.Range["B11:B13"];

IName name5 = workbook.Names.Add("USA");
name5.RefersToRange = worksheet.Range["B14:B16"];

worksheet.Range["E1"].Text = "Country";
worksheet.Range["E1"].CellStyle.Font.Bold = true;

//Data validation in E2
IDataValidation validation = worksheet.Range["E2"].DataValidation;
validation.AllowType = ExcelDataType.User;
validation.FirstFormula = "=Country";

//Shows the error message
validation.ErrorBoxText = "Enter the valid country";
validation.ErrorBoxTitle = "ERROR";
validation.PromptBoxText = "Enter the country";
validation.ShowPromptBox = true;

worksheet.Range["F1"].Text = "States";
worksheet.Range["F1"].CellStyle.Font.Bold = true;

//Data validation in F2
IDataValidation validation2 = worksheet.Range["F2"].DataValidation;
validation2.AllowType = ExcelDataType.User;
validation2.FirstFormula = "=Indirect(E2)";

//Shows the error message
validation2.ErrorBoxText = "Enter the valid states";
validation2.ErrorBoxTitle = "ERROR";
validation2.PromptBoxText = "Enter the state";
validation2.ShowPromptBox = true;

//Creating Vba project
IVbaProject project = workbook.VbaProject;

//Accessing vba modules collection
IVbaModules vbaModules = project.Modules;

//Accessing sheet module
IVbaModule vbaModule = vbaModules[worksheet.CodeName];

//Adding vba code to the module
vbaModule.Code = @"Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDropdown As Range
Dim oldValue As String
Dim newValue As String
Dim DelimiterType As String
DelimiterType = "", "" ' Assuming you want to use a comma followed by a space as the delimiter

If Target.Count > 1 Then Exit Sub
On Error Resume Next
If Target.Column <> 5 And Target.Column <> 6 Then GoTo exitError
Set rngDropdown = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitError
If rngDropdown Is Nothing Then GoTo exitError
If Intersect(Target, rngDropdown) Is Nothing Then
' Do nothing for non-dropdown cells
Else
Application.EnableEvents = False
newValue = Target.Value
Application.Undo
oldValue = Target.Value
Target.Value = newValue

' Check if the change was in E2 and clear F2
If Target.Address = ""$E$2"" Then
Range(""F2"").ClearContents
ElseIf Target.Address = ""$F$2"" Then
' Append new value to F2 with the delimiter if F2 is not empty
If oldValue <> """" Then
If newValue <> """" Then
If oldValue = newValue Or _
InStr(1, oldValue, DelimiterType & newValue) > 0 Or _
InStr(1, oldValue, newValue & DelimiterType) > 0 Then
' Do nothing if the new value is the same or already exists
Else
' Append the new value with the delimiter
Target.Value = oldValue & DelimiterType & newValue
End If
End If
Else
' Set F2 directly to the new value if it's empty
Target.Value = newValue
End If
End If

' Re-enable events after handling the change
Application.EnableEvents = True
End If
exitError:
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub";

//Saving the workbook as stream
FileStream stream = new FileStream("Output.xlsm", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo("Output.xlsm")
{
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.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Read Excel using SFUploader", "Read Excel using SFUploader\Read Excel using SFUploader.csproj", "{DCE0DD47-3BDA-4B5D-AFBA-2AA9E8C9F63B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DCE0DD47-3BDA-4B5D-AFBA-2AA9E8C9F63B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCE0DD47-3BDA-4B5D-AFBA-2AA9E8C9F63B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCE0DD47-3BDA-4B5D-AFBA-2AA9E8C9F63B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCE0DD47-3BDA-4B5D-AFBA-2AA9E8C9F63B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2B3C60C4-7E9C-4A93-B0CE-EC92D6A0CA55}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.JSInterop;

namespace Read_Excel_using_SFUploader
{
public static class FileUtils
{
public static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
=> js.InvokeAsync<object>(
"saveAsFile",
filename,
Convert.ToBase64String(data));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>

<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>

<article class="content px-4">
@Body
</article>
</main>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}

main {
flex: 1;
}

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}

.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}

.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}

.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}

@media (min-width: 641px) {
.page {
flex-direction: row;
}

.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row {
position: sticky;
top: 0;
z-index: 1;
}

.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}

.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">Read Excel using SFUploader</a>
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
<span class="navbar-toggler-icon"></span>
</button>
</div>
</div>

<div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="weather">
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="Excel">
<span class="oi oi-list-rich" aria-hidden="true"></span> Excel
</NavLink>
</div>

</nav>
</div>

@code {
private bool collapseNavMenu = true;

private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
collapseNavMenu = !collapseNavMenu;
}
}
Loading
Loading