Class WorksheetColorExtensions
Provides extension methods for managing worksheet tab colors in Excel workbooks.
public static class WorksheetColorExtensions
- Inheritance
-
WorksheetColorExtensions
- Inherited Members
Methods
GetTabColor(Worksheet, out byte, out byte, out byte)
Gets the tab color of a worksheet as RGB values.
public static bool GetTabColor(this Worksheet worksheet, out byte red, out byte green, out byte blue)
Parameters
worksheet
WorksheetThe worksheet to get the tab color from.
red
byteOutput parameter to receive the red component.
green
byteOutput parameter to receive the green component.
blue
byteOutput parameter to receive the blue component.
Returns
- bool
True if a tab color is set; otherwise, false.
Exceptions
- ArgumentNullException
Thrown when worksheet is null.
GetTabColorAsHex(Worksheet)
Gets the tab color of a worksheet as a hex color code.
public static string GetTabColorAsHex(this Worksheet worksheet)
Parameters
worksheet
WorksheetThe worksheet to get the tab color from.
Returns
- string
The tab color as a hex color code, or null if no tab color is set.
Exceptions
- ArgumentNullException
Thrown when worksheet is null.
RemoveTabColor(Worksheet)
Removes the tab color from a worksheet.
public static void RemoveTabColor(this Worksheet worksheet)
Parameters
worksheet
WorksheetThe worksheet to remove the tab color from.
Exceptions
- ArgumentNullException
Thrown when worksheet is null.
SetTabColor(Worksheet, byte, byte, byte)
Sets the tab color for a worksheet using RGB values.
public static void SetTabColor(this Worksheet worksheet, byte red, byte green, byte blue)
Parameters
worksheet
WorksheetThe worksheet to set the tab color for.
red
byteThe red component (0-255).
green
byteThe green component (0-255).
blue
byteThe blue component (0-255).
Exceptions
- ArgumentNullException
Thrown when worksheet is null.
- ArgumentOutOfRangeException
Thrown when color components are outside the valid range.
SetTabColorByHex(Worksheet, string)
Sets the tab color for a worksheet using an HTML-style hex color code.
public static void SetTabColorByHex(this Worksheet worksheet, string hexColor)
Parameters
worksheet
WorksheetThe worksheet to set the tab color for.
hexColor
stringThe hex color code (e.g., "FF0000" for red).
Exceptions
- ArgumentNullException
Thrown when worksheet is null.
- ArgumentException
Thrown when hexColor is null, empty, or invalid.