Telerik UI for ASP.NET AJAX

Overview

ExcelML is XML-based file format. It complies to the Microsoft XMLSS specification and is supported in Microsoft Office 2003 and later. It is different from the rest of the export formats supported by RadGrid since its engine builds the output directly from the datasource and not from the page.

Note

ExcelML format works best with advanced data-binding or data source control. You will receive "NullReferenceException" if you use simple data-binding and !IsPostBack (Not IsPostBack) check.

There are two events, dedicated for the ExcelML format: ExcelMLExportRowCreated and ExcelMLExportStylesCreated.

Caution

It is expected to receive the following warning when opening the generated xls file in Microsoft Office 2007.

The file you are trying to open, 'Filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening this file. Do you want to open the file now?

The cause of this warning message is explained in details in the following blog posts:

MSDN blogs: Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site

Grinn blog: "The file you are trying to open, '[filename]', is in a different format"

Caution

When exporting arrays, ArrayList, custom objects, LinqDataSource you should set UseAllDataFields="true" in MasterTableView.

Caution

It is mandatory to set the ExportOnlyData property to true when using ExcelML format. Otherwise, an exception will be thrown.

Note

Due to limitation in the ExcelML engine, when exporting RadGrid with grouping, all groups will be expanded regardless of their actual state.

Note

From Q2 2013 ExcelML supports exporting of GridHyperLinkColumn. It is important to know that when its DataTextField property is set, other columns bound to the same field are not exported. Also when Text property of the GridHyperLinkColumn is set and DataField is not defined, columns added to the DataNavigateUrlFields are not exported.

ExcelMLRowCreated

This event is handy when the developer wants to modify the structure of the exported table or when assigning styles to grid table elements. It occurs when the ExcelML engine creates a new row.

ExcelMLStylesCreated

RadGrid fires this event when creating the build-in styles. It could be used not only for modifying the predefined styles but also to define your own (already assigned to a grid table element on ExcelMLExportRowCreated) custom style.

You can access the styles' collection through the Styles property (GridExportExcelMLStyleCreatedArgs).

ExcelMLWorkbookCreated

This event triggers when the XMLSS structure is fully created. It could be useful when you need to traverse that structure or get the whole XML.

Built-in styles

The ID's of the built-in styles are listed below:

  • headerStyle

  • itemStyle

  • alternatingItemStyle

  • dateItemStyle

  • alternatingDateItemStyle

The following code-snippet modifies the default itemStyle/alternatingItemStyle:

Custom styles

In order to define a custom style, you should assign it to the desired element (on GridExportExcelMLRowCreated) and then add the style to the collection on GridExportExcelMLStyleCreated event.

Styling header/footer

You add the symbols from the table below to data of the header / footer elements in order to format them:

Metadata

Represents

&L

Left-aligned data

&R

Right-aligned data

&C

Center-aligned data

&D

Date

&T

Time

&P

Page number

&N

Number of pages

&\0022fontname\,fontstyle\0022&fontsize

Font name, style, and size

&B

Bold

&I

Italic

StyleElement object

This object contains the whole information about a particular style. Fonts, colors, borders, number formats, cell alignment, etc could be applied by modifying the StyleElement.

 

Colors

Text color

StyleElement.FontStyle.Color

Cell background color

StyleElement.InteriorStyle.Color

Cell background pattern

StyleElement.InteriorStyle.Pattern

Border color

BorderStyles.Border

Alignment

Horizontal alignment

StyleElement.AlignmentElement.HorizontalAlignment

Vertical alignment

StyleElement.AlignmentElement.VerticalAlignment

Fonts

Bold

StyleElement.FontStyle.Bold

Italic

StyleElement.FontStyle.Italic

Underline

StyleElement.FontStyle.Underline

Font name

StyleElement.FontStyle.FontName

Size

StyleElement.FontStyle.Size

Other

Borders

StyleElement.Borders

NumberFormat

StyleElement.NumberFormat

For more information about the number formats/borders, please visit the following link:

XML Spreadsheet reference

Number formats

In addition to the predefined formats,you could add your own custom formats.

Borders

Each StyleElement has a Borders property (BorderStylesCollection) that contains the definition of each border. Border position should be specified using the PositionType enumeration:

 

0

1

2

3

4

None

Left

Top

Right

Bottom

Hiding columns

You can use the HideStructureColumns property to hide GridRowIndicatorColumn, GridExpandColumn and GridGroupSplitterColumn. For the other columns types, you can use the following approach:

Note

From Q2 2013 we introduced a new propery named Exportable. This property allows you to choose whether a certain column should be included in the exported file or not. By setting this property to false the related column will be excluded from the exported file. Its default value is true.

Auto Filter

ExcelML is the only excel format which provides build in auto filter functionality. To remove the filter controls from the header row set the Range property to empty string. (e.Worksheet.AutoFilter.Range = ""). By setting the range you could move the filter on a different place within the excel sheet. Only the data placed below the filtering dropdown menu will be included in the filter range. (Example: e.Worksheet.AutoFilter.Range = "R4C1: R4C5")

Generally speaking, R1C1 notation is another way to create cell references which uses numbers for both the rows and columns. R1C1 stands for row index and column index number. This notation is only useful in RadGrid for setting the AutoFilter range.

Cells Protection

ExcelML is one of the excel format which supports cells protection. When you enable the worksheet protection all the cells will be protected as the default state of the cells is “locked”. In order to unlock them you have to create a custom StyleElement and set its IsProtected property to false. Then you could apply this style to the cells which should be unlocked.

The example below demonstrates how you could remove the protection on each second row:

Print option

ExcelML export format provide two print options which allow you to modify the printed output. The first option is FitHeight which specifies the maximum count of the pages in which the content is distributed to. Meaningful when FitToPage is true. The second one is PaperSize which specifies the paper size in a value from the PaperKind enumeration.

The following code snippet demonstrates how to use them.