FlexSheet brings spreadsheet functionality like Microsoft Excel to WPF applications. It is inherited from FlexGrid, so in addition to the full functionality of the FlexGrid control, FlexSheet provides more features built-in such as worksheet management, a powerful formula engine, support style format, etc. Here, I will introduce the main features of FlexSheet for WPF.

ComponentOne FlexSheet for WPF

Manage Multiple Worksheets in a Tabbed Interface

FlexSheet provides the ability to manage multiple sheets in a single tabbed user interface. Users can select, add, remove, move, and rename the sheets, and you can also perform the same actions from code. In the following code snippet, I'm adding three sheets containing 50 rows and 10 columns and activating the second sheet (index 1):

flexSheet.AddSheet("Sheet1", 50, 10);
flexSheet.AddSheet("Sheet2", 50, 10);
flexSheet.AddSheet("Sheet3", 50, 10);
flexSheet.Sheets.SelectedIndex = 1;

The entire workbook can be saved to a file that's compatible with Excel (XLS or XLSX format).

Perform Complex Functions: Aggregation, Trigonometry, Statistics

FlexSheet is equipped with a flexible and powerful expression analysis engine. In addition to basic arithmetic functions it supports aggregation, trigonometric and statistics as well, so it can handle complex operations. When the entered text starts with "=", it will be recognized as a formula. The formula is analyzed by FlexSheet, and the result of the formula will be displayed in the cell.

When a cell containing a formula is referenced in code the calculated result is returned. To see the formula itself, you can use the GetFormula method of the ExcelRow class. In the following example, "3.0" is returned as the value of the cell,  and "= SUM (1, 2, 3, 4, 5) / 5" is returned as the formula.

var row = flexSheet.Rows[2] as ExcelRow;
var col = flexSheet.Columns[3] as Column;

flexSheet[row.Index, col] = "=SUM(1, 2, 3, 4, 5) / 5";
var value = flexSheet[row.Index, col];
var formula = row.GetFormula(col);

Format Cell Styles

FlexSheet provides the ability to easily set cell styles (color, font, borders, etc.) and format (such as numbers, currency, date, etc). Setting the style and formatting is done through the ExcelCellStyle class. ExcelCellStyle is extended from the FlexGrid CellStyle class, so members for setting the borders and formatting is added to it. The following code draws a border on the right and bottom edges of the cell, and then sets it to percentage format:

var row = flexSheet.Rows[2] as ExcelRow;
var col = flexSheet.Columns[3] as Column;

var style = new ExcelCellStyle();
style.BorderThickness = new Thickness(0, 0, 2, 5);
style.BorderBrush = new SolidColorBrush(Colors.Red);
style.Format = "P";
row.SetCellStyle(col, style);

The format string follows the same .NET strings as the double.ToString (string) method.

Insert Comments, Undo History, Print Preview and More!

In addition to these features, FlexSheet offers a lot of other useful features such as insert comments and images, undo/redo history stack, print preview, etc. You can download FlexSheet for WPF as part of ComponentOne Studio.

Download a C# FlexSheet code sample, and view other source codes for a variety of FlexSheet examples.