officefileapi-devexpress-dot-spreadsheet-dot-workbookcolorpalette-dot-item-x28-system-dot-int32-x29.md
Returns or specifies a color in the workbook palette.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
Color this[int index] { get; set; }
Property Item(index As Integer) As Color
| Name | Type | Description |
|---|---|---|
| index | Int32 |
A zero-based index of the color to return or set. Valid indexes are from 0 to 55.
|
| Type | Description |
|---|---|
| Color |
The color at the specified index.
|
| Type | Description |
|---|---|
| IndexOutOfRangeException |
Occurs if the index value is less than 0 or greater than 55.
| | ArgumentException |
Occurs if you assign an empty, transparent, or semi-transparent color to this property. Only opaque colors are allowed.
|
A workbook palette includes 56 RGB colors. The following image illustrates the default palette colors and their indexes:
The Item property allows you to change palette colors, as shown in the example below.
using DevExpress.Spreadsheet;
using System.Drawing;
// ...
using (Workbook workbook = new Workbook())
{
var worksheet = workbook.Worksheets.ActiveWorksheet;
// Customize palette colors.
workbook.ColorPalette[1] = Color.FromArgb(0xD9, 0xDD, 0xDC);
workbook.ColorPalette[2] = Color.FromArgb(0xE0, 0x11, 0x5F);
// Add a value to the "B2" cell.
var cellB2 = worksheet["B2"];
cellB2.Value = "Custom Palette Colors";
// Use custom palette colors to format the cell.
cellB2.Font.Color = workbook.ColorPalette[1];
cellB2.FillColor = workbook.ColorPalette[2];
}
Imports DevExpress.Spreadsheet
Imports System.Drawing
' ...
Using workbook As New Workbook()
Dim worksheet As Worksheet = workbook.Worksheets.ActiveWorksheet
' Customize palette colors.
workbook.ColorPalette(1) = Color.FromArgb(&HD9, &HDD, &HDC)
workbook.ColorPalette(2) = Color.FromArgb(&HE0, &H11, &H5F)
' Add a value to the "B2" cell.
Dim cellB2 As CellRange = worksheet("B2")
cellB2.Value = "Custom Palette Colors"
' Use custom palette colors to format the cell.
cellB2.Font.Color = workbook.ColorPalette(1)
cellB2.FillColor = workbook.ColorPalette(2)
End Using
The image below shows the result.
Use the WorkbookColorPalette.IsCustom property to check whether the workbook palette was customized. Call the WorkbookColorPalette.Reset method to reset custom palette colors to default colors.
See Also