-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from SyncfusionExamples/877948-Revamping-CF-X…
…lsIO 877948 - Add samples for conditional formatting
- Loading branch information
Showing
12 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Conditional Formatting/Color Scales/NET Standard/Color Scales/Color Scales.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") = "Color Scales", "Color Scales\Color Scales.csproj", "{937742B3-3F47-4BDF-A744-A404F03229DE}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{937742B3-3F47-4BDF-A744-A404F03229DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{937742B3-3F47-4BDF-A744-A404F03229DE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{937742B3-3F47-4BDF-A744-A404F03229DE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{937742B3-3F47-4BDF-A744-A404F03229DE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {D6361E70-7C26-499E-B89E-9A8427596CA5} | ||
EndGlobalSection | ||
EndGlobal |
15 changes: 15 additions & 0 deletions
15
...tional Formatting/Color Scales/NET Standard/Color Scales/Color Scales/Color Scales.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Color_Scales</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="25.2.5" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file added
BIN
+10.3 KB
...al Formatting/Color Scales/NET Standard/Color Scales/Color Scales/Data/InputTemplate.xlsx
Binary file not shown.
61 changes: 61 additions & 0 deletions
61
Conditional Formatting/Color Scales/NET Standard/Color Scales/Color Scales/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.IO; | ||
using Syncfusion.XlsIO; | ||
using Syncfusion.Drawing; | ||
|
||
namespace Color_Scales | ||
{ | ||
class Program | ||
{ | ||
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, ExcelOpenType.Automatic); | ||
IWorksheet worksheet = workbook.Worksheets[0]; | ||
|
||
//Create color scales for the data in specified range | ||
IConditionalFormats conditionalFormats = worksheet.Range["D7:D46"].ConditionalFormats; | ||
IConditionalFormat conditionalFormat = conditionalFormats.AddCondition(); | ||
conditionalFormat.FormatType = ExcelCFType.ColorScale; | ||
IColorScale colorScale = conditionalFormat.ColorScale; | ||
|
||
//Sets 3 - color scale | ||
colorScale.SetConditionCount(3); | ||
colorScale.Criteria[0].FormatColorRGB = Color.FromArgb(230, 197, 218); | ||
colorScale.Criteria[0].Type = ConditionValueType.LowestValue; | ||
colorScale.Criteria[0].Value = "0"; | ||
|
||
colorScale.Criteria[1].FormatColorRGB = Color.FromArgb(244, 210, 178); | ||
colorScale.Criteria[1].Type = ConditionValueType.Percentile; | ||
colorScale.Criteria[1].Value = "50"; | ||
|
||
colorScale.Criteria[2].FormatColorRGB = Color.FromArgb(245, 247, 171); | ||
colorScale.Criteria[2].Type = ConditionValueType.HighestValue; | ||
colorScale.Criteria[2].Value = "0"; | ||
|
||
conditionalFormat.FirstFormulaR1C1 = "=R[1]C[0]"; | ||
conditionalFormat.SecondFormulaR1C1 = "=R[1]C[1]"; | ||
|
||
#region Save | ||
//Saving the workbook | ||
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write); | ||
workbook.SaveAs(outputStream); | ||
#endregion | ||
|
||
//Dispose streams | ||
outputStream.Dispose(); | ||
inputStream.Dispose(); | ||
|
||
System.Diagnostics.Process process = new System.Diagnostics.Process(); | ||
process.StartInfo = new System.Diagnostics.ProcessStartInfo("Output.xlsx") | ||
{ | ||
UseShellExecute = true | ||
}; | ||
process.Start(); | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Conditional Formatting/Data Bars/NET Standard/Data Bars/Data Bars.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") = "Data Bars", "Data Bars\Data Bars.csproj", "{95F64BC8-7C6A-43E7-83DC-6ABE654D2378}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{95F64BC8-7C6A-43E7-83DC-6ABE654D2378}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{95F64BC8-7C6A-43E7-83DC-6ABE654D2378}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{95F64BC8-7C6A-43E7-83DC-6ABE654D2378}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{95F64BC8-7C6A-43E7-83DC-6ABE654D2378}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {1272551D-7C4C-4F0B-AC47-466FE7D572D3} | ||
EndGlobalSection | ||
EndGlobal |
15 changes: 15 additions & 0 deletions
15
Conditional Formatting/Data Bars/NET Standard/Data Bars/Data Bars/Data Bars.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Data_Bars</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="25.2.5" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file added
BIN
+10.2 KB
Conditional Formatting/Data Bars/NET Standard/Data Bars/Data Bars/Data/InputTemplate.xlsx
Binary file not shown.
55 changes: 55 additions & 0 deletions
55
Conditional Formatting/Data Bars/NET Standard/Data Bars/Data Bars/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.IO; | ||
using Syncfusion.XlsIO; | ||
using Syncfusion.Drawing; | ||
|
||
namespace Data_Bars | ||
{ | ||
class Program | ||
{ | ||
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, ExcelOpenType.Automatic); | ||
IWorksheet worksheet = workbook.Worksheets[0]; | ||
|
||
//Create data bars for the data in specified range | ||
IConditionalFormats conditionalFormats = worksheet.Range["C7:C46"].ConditionalFormats; | ||
IConditionalFormat conditionalFormat = conditionalFormats.AddCondition(); | ||
conditionalFormat.FormatType = ExcelCFType.DataBar; | ||
IDataBar dataBar = conditionalFormat.DataBar; | ||
|
||
//Set the constraints | ||
dataBar.MinPoint.Type = ConditionValueType.LowestValue; | ||
dataBar.MaxPoint.Type = ConditionValueType.HighestValue; | ||
|
||
//Set color for Bar | ||
dataBar.BarColor = Color.FromArgb(156, 208, 243); | ||
|
||
//Hide the values in data bar | ||
dataBar.ShowValue = false; | ||
dataBar.BarColor = Color.Aqua; | ||
|
||
#region Save | ||
//Saving the workbook | ||
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write); | ||
workbook.SaveAs(outputStream); | ||
#endregion | ||
|
||
//Dispose streams | ||
outputStream.Dispose(); | ||
inputStream.Dispose(); | ||
|
||
System.Diagnostics.Process process = new System.Diagnostics.Process(); | ||
process.StartInfo = new System.Diagnostics.ProcessStartInfo("Output.xlsx") | ||
{ | ||
UseShellExecute = true | ||
}; | ||
process.Start(); | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Conditional Formatting/Icon Sets/NET Standard/Icon Sets/Icon Sets.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") = "Icon Sets", "Icon Sets\Icon Sets.csproj", "{5C96807B-A148-4C73-BA0B-D1811E51F922}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5C96807B-A148-4C73-BA0B-D1811E51F922}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5C96807B-A148-4C73-BA0B-D1811E51F922}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5C96807B-A148-4C73-BA0B-D1811E51F922}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5C96807B-A148-4C73-BA0B-D1811E51F922}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A1FF0723-755A-4BD7-B192-9B03F57E571E} | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+10.3 KB
Conditional Formatting/Icon Sets/NET Standard/Icon Sets/Icon Sets/Data/InputTemplate.xlsx
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
Conditional Formatting/Icon Sets/NET Standard/Icon Sets/Icon Sets/Icon Sets.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Icon_Sets</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="25.2.5" /> | ||
</ItemGroup> | ||
|
||
</Project> |
52 changes: 52 additions & 0 deletions
52
Conditional Formatting/Icon Sets/NET Standard/Icon Sets/Icon Sets/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.IO; | ||
using Syncfusion.XlsIO; | ||
using Syncfusion.Drawing; | ||
|
||
namespace Advanced_Conditional_Formats | ||
{ | ||
class Program | ||
{ | ||
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, ExcelOpenType.Automatic); | ||
IWorksheet worksheet = workbook.Worksheets[0]; | ||
|
||
//Create icon sets for the data in specified range | ||
IConditionalFormats conditionalFormats = worksheet.Range["E7:E46"].ConditionalFormats; | ||
IConditionalFormat conditionalFormat = conditionalFormats.AddCondition(); | ||
conditionalFormat.FormatType = ExcelCFType.IconSet; | ||
IIconSet iconSet = conditionalFormat.IconSet; | ||
|
||
//Apply three symbols icon and hide the data in the specified range | ||
iconSet.IconSet = ExcelIconSetType.ThreeSymbols; | ||
iconSet.IconCriteria[1].Type = ConditionValueType.Percent; | ||
iconSet.IconCriteria[1].Value = "50"; | ||
iconSet.IconCriteria[2].Type = ConditionValueType.Percent; | ||
iconSet.IconCriteria[2].Value = "50"; | ||
iconSet.ShowIconOnly = true; | ||
|
||
#region Save | ||
//Saving the workbook | ||
FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.Write); | ||
workbook.SaveAs(outputStream); | ||
#endregion | ||
|
||
//Dispose streams | ||
outputStream.Dispose(); | ||
inputStream.Dispose(); | ||
|
||
System.Diagnostics.Process process = new System.Diagnostics.Process(); | ||
process.StartInfo = new System.Diagnostics.ProcessStartInfo("Output.xlsx") | ||
{ | ||
UseShellExecute = true | ||
}; | ||
process.Start(); | ||
} | ||
} | ||
} | ||
} |