diff --git a/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors.sln b/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors.sln new file mode 100644 index 00000000..936de745 --- /dev/null +++ b/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36127.28 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HighLightCellsWithErrors", "HighLightCellsWithErrors\HighLightCellsWithErrors.csproj", "{2640FE48-0576-497D-A510-967D9CF72201}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2640FE48-0576-497D-A510-967D9CF72201}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2640FE48-0576-497D-A510-967D9CF72201}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2640FE48-0576-497D-A510-967D9CF72201}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2640FE48-0576-497D-A510-967D9CF72201}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {311E5A9F-EE7B-4384-9CAA-B5CC318B459B} + EndGlobalSection +EndGlobal diff --git a/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/HighLightCellsWithErrors.csproj b/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/HighLightCellsWithErrors.csproj new file mode 100644 index 00000000..4a5e6d1b --- /dev/null +++ b/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/HighLightCellsWithErrors.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Highlight_cells_with_errors + enable + enable + + + + + + + + + Always + + + + diff --git a/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/Output/.gitkeep b/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/Program.cs b/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/Program.cs new file mode 100644 index 00000000..cce30928 --- /dev/null +++ b/Use Cases/Conditional Formatting/.NET/Highlight cells with errors/HighLightCellsWithErrors/Program.cs @@ -0,0 +1,45 @@ +using Syncfusion.XlsIO; + +class Program +{ + public static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Add some data and errors + worksheet.Range["A1"].Text = "Sample Data"; + + //Creates a #DIV/0! error + worksheet.Range["A2"].Formula = "=1/0"; + + //Creates a #N/A error + worksheet.Range["A3"].Formula = "=VLOOKUP(\"NonExistent\",B1:C5,2,FALSE)"; + + //Define the range to apply formatting + IRange range = worksheet.Range["A1:A10"]; + + //Add conditional formatting to highlight cells with errors + IConditionalFormats conditionalFormats = range.ConditionalFormats; + IConditionalFormat conditionalFormat = conditionalFormats.AddCondition(); + + //Set format type to ContainsErrors + conditionalFormat.FormatType = ExcelCFType.ContainsErrors; + + //Apply red background to cells containing errors + conditionalFormat.BackColor = ExcelKnownColors.Red; + + #region Save + //Saving the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + #endregion + + //Dispose streams + outputStream.Dispose(); + } + } +} \ No newline at end of file