diff --git a/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType.sln b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType.sln new file mode 100644 index 00000000..a33c0ae2 --- /dev/null +++ b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36221.1 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomFilterStringType", "CustomFilterStringType\CustomFilterStringType.csproj", "{F22EFEC1-0351-48AC-B50E-04211BEBD213}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F22EFEC1-0351-48AC-B50E-04211BEBD213}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F22EFEC1-0351-48AC-B50E-04211BEBD213}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F22EFEC1-0351-48AC-B50E-04211BEBD213}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F22EFEC1-0351-48AC-B50E-04211BEBD213}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {577F87AB-4F9E-40F5-8D93-796229613048} + EndGlobalSection +EndGlobal diff --git a/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/CustomFilterStringType.csproj b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/CustomFilterStringType.csproj new file mode 100644 index 00000000..6d620a0d --- /dev/null +++ b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/CustomFilterStringType.csproj @@ -0,0 +1,20 @@ + + + + Exe + net9.0 + enable + enable + + + + + + + + + Always + + + + diff --git a/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Data/Input.xlsx b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Data/Input.xlsx new file mode 100644 index 00000000..318ac1b1 Binary files /dev/null and b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Data/Input.xlsx differ diff --git a/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Output/.gitkeep b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Program.cs b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Program.cs new file mode 100644 index 00000000..8d35975c --- /dev/null +++ b/FAQ/Filtering/.NET/Custom Filter String Type/CustomFilterStringType/Program.cs @@ -0,0 +1,34 @@ +using Syncfusion.XlsIO; +using System.IO; + +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(Path.GetFullPath(@"../../../Data/Input.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Creating an AutoFilter + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A11"]; + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Specifying first condition + IAutoFilterCondition firstCondition = filter.FirstCondition; + firstCondition.ConditionOperator = ExcelFilterCondition.DoesNotContain; + firstCondition.String = "1000.00"; + + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("../../../Output/Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); + } + } +} \ No newline at end of file diff --git a/FAQ/Filtering/.NET/Custom Filter String Type/README.md b/FAQ/Filtering/.NET/Custom Filter String Type/README.md new file mode 100644 index 00000000..e1f342d2 --- /dev/null +++ b/FAQ/Filtering/.NET/Custom Filter String Type/README.md @@ -0,0 +1,46 @@ +# How to apply custom filtering to string data types using XlsIO? + +Step 1: Create a New C# Console Application Project. + +Step 2: Name the Project. + +Step 3: Install the [Syncfusion.XlsIO.Net.Core](https://www.nuget.org/packages/Syncfusion.XlsIO.Net.Core) NuGet package as reference to your .NET Standard applications from [NuGet.org](https://www.nuget.org). + +Step 4: Include the following namespaces in the **Program.cs** file. + +```csharp +using System; +using System.IO; +using Syncfusion.XlsIO; +``` + +Step 5: Include the below code snippet in **Program.cs** to apply custom filtering to string data types using XlsIO. + +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + FileStream inputStream = new FileStream(Path.GetFullPath(@"../../../Data/Input.xlsx"), FileMode.Open, FileAccess.Read); + IWorkbook workbook = application.Workbooks.Open(inputStream); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Creating an AutoFilter + worksheet.AutoFilters.FilterRange = worksheet.Range["A1:A11"]; + IAutoFilter filter = worksheet.AutoFilters[0]; + + //Specifying first condition + IAutoFilterCondition firstCondition = filter.FirstCondition; + firstCondition.ConditionOperator = ExcelFilterCondition.DoesNotContain; + firstCondition.String = "1000.00"; + + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("../../../Output/Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + + //Dispose streams + outputStream.Dispose(); + inputStream.Dispose(); +} +``` +