Version 1.2 Update in Workbooks for .NET – Part III

Learn more about Xeed Workbooks for .NET

We continue our overview of the changes in Workbooks for .NET v1.2.

ThemeColor Class

ThemeColor class was added, which is used to represent a Theme‘s color.

The ThemeColor class has the following properties:

  • Tint: the ThemeColor's tint. Values are from -1 (dark) to +1 (light); 0 by default.
  • Type: the ThemeColor's type.

The available types for ThemeColor currently include:

  • Accent1, Accent2, Accent3, Accent4, Accent5, Accent6
  • Background1, Background2
  • FollowedHyperlink, Hyperlink
  • Text1, Text2

Note: properties that cover the same element are mutually exclusive. For example on the Fill class, setting a value on BackgroundThemeColor will set BackgroundColor to null, and vice versa.

Modify ThemeColor on Border and Font

ThemeColor property was added to the Border and Font classes to specify the Theme’s colors. The ThemeColor property is of type ThemeColor.

// Setting the ThemeColor
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var worksheet = document.Worksheets[ 0 ];

	// Border
	worksheet.Cells[ "B15", "C17" ].Style.Borders[ BorderType.Right ].ThemeColor = new ThemeColor( ThemeColorType.Accent1, -0.5d );

	// Font
	worksheet.Cells[ "C18" ].Style.Font = new Font() { ThemeColor = new ThemeColor( ThemeColorType.Text2, -0.5d ) };

	// save the modifications
	document.Save();
}

Modify BackgroundThemeColor and PatternThemeColor on Fill

Two new properties were added to the Fill class:

  • BackgroundThemeColor: used for filling the background of a Cell, Row, Column or range; null by default.
  • PatternThemeColor: used for filling a Cell, Row, Column or range; null by default. The Cell, Row, Column or range are filled based on the PatternStyle property.

Both the BackgroundThemeColor and PatternThemeColor properties are of type ThemeColor.

// Setting BackgroundThemeColor and PatternThemeColor
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var worksheet = document.Worksheets[ 0 ];

	// Fill
	worksheet.Cells[ "C12" ].Style.Fill = new Fill() { PatternStyle = FillPattern.ThinDiagonalCrosshatch, BackgroundThemeColor = new ThemeColor( ThemeColorType.Background1, -0.5d ), PatternThemeColor = new ThemeColor( ThemeColorType.Accent4, -0.5d ) };

	// save the modifications
	document.Save();
}

Modify TabThemeColor on Worksheet

TabThemeColor property was added to the Worksheet class to specify the theme color for the worksheet’s tabs; null by default. The TabThemeColor property is of type ThemeColor.

// Setting the ThemeColor
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var worksheet = document.Worksheets[ 0 ];
	worksheet.TabThemeColor = new ThemeColor( ThemeColorType.Accent5, -0.5d );

	// save the modifications
	document.Save();
}

Modify Borders on Style

Borders property was added on the Style class to customize the look of the borders. The Borders property is a BorderCollection type object.

The BorderCollection class has the following methods:

  • SetDiagonals: Sets the DiagonalUp and DiagonalDown borders using the same lineStyle and color.
  • SetInside: Sets the Horizontal and Vertical Borders using the same lineStyle and color.
  • SetOutline: Sets the Left, Right, Top and Bottom Borders using the same lineStyle and color.
  • SetThemeDiagonals: Sets the DiagonalUp and DiagonalDown Borders using the same lineStyle and themeColor.
  • SetThemeInside: Sets the Horizontal and Vertical Borders using the same lineStyle and themeColor.
  • SetThemeOutline: Sets the Left, Right, Top and Bottom Borders using the same lineStyle and themeColor.
// Setting the Borders on a Style
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var worksheet = document.Worksheets[ 0 ];

	// Specify the borders
	var cellRange = worksheet.Cells[ "B15", "C17" ];
	cellRange.Style.Borders.SetInside( LineStyle.Medium, Color.DarkGreen );
	cellRange.Style.Borders.SetOutline( LineStyle.Medium, Color.DarkGreen );

	// save the modifications
	document.Save();
}

Modify Fill on Style

Fill property was added on the Style class to customize the look of the fill. The Fill property is a Fill type object.

The Fill class has the following properties:

  • BackgroundColor: the Color used for filling the background of a Cell, Row, Column or range; null by default.
  • BackgroundThemeColor: the ThemeColor used for filling the background of a Cell, Row, Column or range; null by default.
  • PatternColor: the Color of the pattern used for filling a Cell, Row, Column or range; null by default. This will be based on the PatternStyle property.
  • PatternStyle: the Style of the pattern used for filling a Cell, Row, Column or range; FillPattern.None by default. These will be filled based on the PatternColor property.
  • PatternThemeColor: the ThemeColor of the pattern used for filling a Cell, Row, Column or range; null by default. The Cell, Row, Column or range are filled based on the PatternStyle property.
// Setting the Fill on a Style
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var worksheet = document.Worksheets[ 0 ];

	worksheet.Cells[ "C12" ].Style.Fill = new Fill() { PatternStyle = FillPattern.ThinDiagonalCrosshatch, PatternColor = Color.Green, BackgroundColor = Color.Blue };

	// save the modifications
	document.Save();
}

More to come in Part IV, stay tuned!

For more information, please refer to the la documentation.