RadControls for ASP.NET AJAX

RadControls for ASP.NET AJAX

Basics

The Export Infrastructure is designed to be a middle tier structure that sits between an export library and server control. Currently it has only one renderer - for binary XLS (BIFF) files. Although it has been used internally for RadGrid, it is in fact independent and could be used in a wide range of scenarios. For example:

  • for generating a binary XLS file on-the-fly

  • for implementing XLS export for your own custom controls and/or Telerik controls that doesn't support export to Excel out-of-the-box

  • for direct manipulation of the output generated by controls that uses it internally (RadGrid)

Structure

The core structure is very simple and easy to use. Due to the fact that its building blocks are familiar elements like Table, Column, Row, Cell, etc everyone can take advantage of its features without reading bulky documentations and most importantly, the developer doesn't need to know how the endpoint (the export library) actually works and therefore he also doesn't need to think of its peculiarities and limitations.

Note

Cell, Column, and Row indices start from 1.

Cell

Name

Description

Table

Reference to the Table object

RowIndex

Index of the parent row

ColIndex

Index of the parent column

Index

The index of the cell (Point). Note that the cell indices start from 1, not from 0.

Style

Container for the cell styles

Value

Get/set the value of the given cell

Colspan

The column span of the cell

Rowspan

The row span of the current cell

Text

The value of the cell converted to text

Format

Get/set the numeric format of the cell value

Column

Name

Description

Table

Reference to the Table object

Style

Container for the Column styles

Width

The width of the current Column

Cells

Returns a collection containing the cells belonging to this Column

Index

The index of the current Column. Note that the column indices start from 1, not from 0.

Row

Name

Description

Table

Reference to the Table object

Style

Container for the Row styles

Height

The height of the current Row

Cells

Returns a collection containing the cells belonging to this Row

Index

The index of the current Row. Note that the row indices start from 1, not from 0.

Table

Name

Description

Index

The index of the current Table in the ExportStructure

Title

The title (name) of the Table

Cells

Returns a collection containing the Cells belonging to this Table

Rows

Returns a collection containing the Rows belonging to this Table

Columns

Returns a collection containing the Columns belonging to this Table

Style

Container for the Table styles

ExportStructure

Name

Description

Tables

Returns a collection containing the Rows belonging to this ExportStructure

ExportStyle

Name

Description

BackColor

Background color

BorderBottomColor

Color of the bottom border

BorderLeftColor

Color of the left border

BorderRightColor

Color of the right border

BorderTopColor

Color of the top border

BorderBottomStyle

Style of the bottom border

BorderLeftStyle

Style of the left border

BorderRightStyle

Style of the right border

BorderTopStyle

Style of the top border

Font

FontInfo object. Contains the font information for the given instance.

ForeColor

Foreground color

HorizontalAlign

Horizontal text alignment

VerticalAlign

Vertical text alignment

IsEmpty

Determines whether the current Style is empty

HasBorderStyles

Returns true, if the current Style has at least one border

Basic Operations

Below, you can find some examples demonstrating how you could use the export infrastructure. Note that there is no need to create Row and Column objects except if you need to set row/column-specific properties like width/height for example.

Using the Export Infrastructure - Example 1

Using the Export Infrastructure - Example 2

ShiftRowsDown method gives you the opportunity to insert new rows at the chosen position. The first argument of the method is the start row index, and the second argument is the number of the new rows which would be inserted. A possible use case is when the user wants to insert a custom header above the exported RadGrid, the customer could use this method to shift the rows down, up to the desired point. Although it is a part of the Export Infrastructure API, it is mostly suitable when exporting from RadGrid.

Rendering

As mentioned in the beginning of this topic, at this point there is only one renderer available. You could use it to generate a XLS file from a given structure. Simply create an instance of the XlsBiffRenderer class, provide a reference to the ExportStructure object and then invoke the Render method. When executed, it will return a byte array that could be either saved in a file or sent to the client via the Response object.

Using the XlsBiffRenderer

Image Support

From Q3 2012 we provide Image support when using the Export Infrastructure. You just need instantiate the ExportStructure class, and then insert the image in a cell of your choice inside the table.

In the InsertImage method you should pass the cell or range of cells where the image will be located and the image path. Both relative and absolute paths are supported. It is also possible to create a new Image object directly and then add it to the Images collection of the Table object. You can specify a third boolean argument, indicating whether the image should be auto-sized to fit the cell(s) which hold it.

The method has the following overloads:

  • void InsertImage(Range range, string imageUrl)

  • void InsertImage(Range range, byte[] imageData)

  • void InsertImage(Cell cell, string imageUrl)

  • void InsertImage(Cell cell, string imageUrl, bool autoSize)

  • void InsertImage(Cell cell, byte[] imageData)

  • void InsertImage(Cell cell, byte[] imageData, bool autoSize)

Note

Automatic resizing is supported only when the image is inserted within a single cell (range is not supported).

Limitations

  • No hierarchy support

  • No grouping support

  • No automatic column/row resizing