diff --git a/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/README.md b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/README.md new file mode 100644 index 00000000..adc06dee --- /dev/null +++ b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/README.md @@ -0,0 +1,48 @@ +# How to get the RGB values of the cell color 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.Drawing; +using Syncfusion.XlsIO; +``` + +Step 5: Include the below code snippet in **Program.cs** to get the RGB values of the cell color using XlsIO. + +```csharp +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Apply cell color + worksheet.Range["A1"].CellStyle.ColorIndex = ExcelKnownColors.Custom50; + + //Get the RGB values of the cell color + Color color = worksheet.Range["A1"].CellStyle.Color; + byte red = color.R; + byte green = color.G; + byte blue = color.B; + + //Print the RGB values + Console.WriteLine($"Red: {red}, Green: {green}, Blue: {blue}"); + + //Save the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("../../../Output/Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + + //Dispose stream + outputStream.Dispose(); +} +``` + diff --git a/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor.sln b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor.sln new file mode 100644 index 00000000..d7cc9c81 --- /dev/null +++ b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor.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}") = "RGBValueCellColor", "RGBValueCellColor\RGBValueCellColor.csproj", "{B693B811-5C3A-40DD-8C56-573409E2F140}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B693B811-5C3A-40DD-8C56-573409E2F140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B693B811-5C3A-40DD-8C56-573409E2F140}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B693B811-5C3A-40DD-8C56-573409E2F140}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B693B811-5C3A-40DD-8C56-573409E2F140}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {814BB82D-5FD2-45C0-9792-C0DE5FDEB2BC} + EndGlobalSection +EndGlobal diff --git a/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/Output/.gitkeep b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/Output/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/Program.cs b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/Program.cs new file mode 100644 index 00000000..bfbde669 --- /dev/null +++ b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/Program.cs @@ -0,0 +1,40 @@ +using System.IO; +using Syncfusion.XlsIO; +using Syncfusion.Drawing; + + +namespace RGBValueCellColor +{ + class Program + { + public static void Main(string[] args) + { + using (ExcelEngine excelEngine = new ExcelEngine()) + { + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + //Apply cell color + worksheet.Range["A1"].CellStyle.ColorIndex = ExcelKnownColors.Custom50; + + //Get the RGB values of the cell color + Color color = worksheet.Range["A1"].CellStyle.Color; + byte red = color.R; + byte green = color.G; + byte blue = color.B; + + //Print the RGB values + Console.WriteLine($"Red: {red}, Green: {green}, Blue: {blue}"); + + //Save the workbook + FileStream outputStream = new FileStream(Path.GetFullPath("../../../Output/Output.xlsx"), FileMode.Create, FileAccess.Write); + workbook.SaveAs(outputStream); + + //Dispose stream + outputStream.Dispose(); + } + } + } +} diff --git a/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/RGBValueCellColor.csproj b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/RGBValueCellColor.csproj new file mode 100644 index 00000000..eb7e4ca4 --- /dev/null +++ b/FAQ/RGB Value for Cell Color/.NET/RGB Value for Cell Color/RGBValueCellColor/RGBValueCellColor.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + Always + + + +