Get Icon Sets, Data Bars or Color Scales Objects used in Conditional Formatting
Contents
[
Hide
]
Sometimes, you need to retrieve icon sets that are used in the conditional formatting of a cell or a range of cells and you want to create an image file based on it. You might require to read the data bars or color scales used in the conditional formatting. Aspose.Cells supports this feature.
The following code sample shows how to read icon sets that are used for conditional formatting. With Aspose.Cell’s simple API, the icon set’s image data is saved as an image.
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open a template Excel file | |
Workbook workbook = new Workbook(dataDir+ "book1.xlsx"); | |
// Get the first worksheet in the workbook | |
Worksheet sheet = workbook.Worksheets[0]; | |
// Get the A1 cell | |
Cell cell = sheet.Cells["A1"]; | |
// Get the conditional formatting result object | |
ConditionalFormattingResult cfr = cell.GetConditionalFormattingResult(); | |
// Get the icon set | |
ConditionalFormattingIcon icon = cfr.ConditionalFormattingIcon; | |
// Create the image file based on the icon's image data | |
File.WriteAllBytes(dataDir+ "imgIcon.out.jpg", icon.ImageData); |