Skip to content
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,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();
}
```

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

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<None Update="Output\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>