This is part 2 of blog series that aim to give you a kickoff and show how to use RadSpreadProcessing like a pro. While in part 1 we created a workbook, entered all the expense data and set formulas for the total rows, now we will focus on applying styles, using number formats, adding images. In case you have missed the first blog post, don’t worry. You can catch up by going through the blog post 1 here or download the source code from our SDK example.
Our aim for this post is to transform the raw data document into a stylish report. Here is how we will change the worksheet:
One conspicuous difference between the two documents above is the colors, so let’s start by setting appropriate colors. Specifically, let’s make sure our document has a dark background and light fore color. To achieve this, we need to set a theme of the workbook and create styles that fit our needs. A theme serves as a palette of colors and fonts that will be used throughout the workbook, while a style applies the colors and fonts of the theme to the cells. The combination of themes and styles provide a powerful styling mechanism that allow you to create flexible look and feel. So, let’s set a custom theme that specify the default colors and fonts we will use throughout the document:
ThemeColorScheme colorScheme =
Color.FromArgb(255, 65, 65, 65),
Color.FromArgb(255, 240, 240, 240),
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 255, 255, 255),
Color.FromArgb(255, 116, 202, 218),
Color.FromArgb(255, 146, 204, 70),
Color.FromArgb(255, 241, 96, 61),
Color.FromArgb(255, 143, 145, 158),
Color.FromArgb(255, 141, 119, 251),
Color.FromArgb(255, 91, 119, 153),
Color.FromArgb(255, 5, 99, 193),
Color.FromArgb(255, 149, 79, 114));
// Followed hyperlink
ThemeFontScheme fontScheme =
DocumentTheme theme =
, colorScheme, fontScheme);
.workbook.Theme = theme;
Now that we have the full palette of colors and fonts, let’s apply them to our document. One way to achieve the desired result is through modifying the Normal style. Since all cells in the worksheet are by default applied the Normal style, any changes done to the style will affect the whole worksheet. Thus, setting the font size or font family of the Normal style will have immediate effect over the worksheet.
CellStyle normalStyle =
normalStyle.Fill = PatternFill.CreateSolidFill(
normalStyle.FontSize = UnitHelper.PointToDip(10);
normalStyle.VerticalAlignment = RadVerticalAlignment.Center;
Through setting the theme and tuning the Normal style we have achieved the following result.
Further, we need to tweak a bit the cells containing the company name and title of the document, the header cells and the total rows. To do so, we will create separate styles for each of these. Note that each of the styles need only specify the changes that differ from the Normal style.
CellStyle companyNameStyle =
companyNameStyle.FontSize = UnitHelper.PointToDip(48);
companyNameStyle.HorizontalAlignment = RadHorizontalAlignment.Left;
CellStyle expensePeriodStyle =
"Segoe UI Light"
expensePeriodStyle.FontSize = UnitHelper.PointToDip(20);
expensePeriodStyle.HorizontalAlignment = RadHorizontalAlignment.Right;
CellStyle columnHeadersStyle =
columnHeadersStyle.FontSize = UnitHelper.PointToDip(14);
CellStyle departmentTotalStyle =
departmentTotalStyle.FontSize = UnitHelper.PointToDip(14);
CellStyle totalStyle =
totalStyle.Fill = PatternFill.CreateSolidFill(
totalStyle.FontSize = UnitHelper.PointToDip(14);
Now that all styles are ready, let’s apply them to the cells:
worksheet.Cells[1, 1, 1, 4].SetStyleName(
worksheet.Cells[2, 1, 3, 4].SetStyleName(
worksheet.Cells[5, 1, 5, 4].SetStyleName(
worksheet.Cells[28, 1, 30, 4].SetStyleName(
worksheet.Cells[31, 1, 31, 4].SetStyleName(
The result from setting the styles may be seen in the image below:
To make the data in the Date and Amount columns more presentable, let’s format the data, so that the dates appears as d/MMM/yyyy and amounts appear with the currency symbol. To do so, we have to create two CellValueFormat instances and apply them to the columns. The following snippet illustrates how this can be achieved:
"d MMM yyyy"
worksheet.Cells[6, 3, 31, 3].SetFormat(
worksheet.Cells[6, 4, 31, 4].SetFormat(
Finally, we need to add the company logo above the Expense Report title. To do so, we should create a FloatingImage object and provide the worksheet and the index of the cell it should be positioned. Also, if you would like to tune the position of the image in the worksheet, you can use the horizontal and vertical offset properties in the FloatingImage constructor. Further, we need to specify the width and height of the image and add it to the Shapes collection of the worksheet.
FloatingImage image =
CellIndex(1, 4), 25, 10);
(Stream stream = GetResourceStream(
image.Width = 65;
image.Height = 65;
In this blog we changed the theme, created and applied styles and number formats, and added an image to our document. Stay tuned for blog post 3 that will show you how to use filtering and export to PDF features.
Now let's continue to part 3.
Deyan Yosifov is a developer on the Telerik XAML Team. Apart from software, Deyan has passion for mathematics and architecture. In his spare time, he enjoys practicing sports and more specifically football and badminton.
Subscribe to be the first to get our expert-written articles and tutorials for developers!