This is a migrated thread and some comments may be shown as answers.

Export to excel of generic lists

1 Answer 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 27 Jan 2009, 07:51 PM
Hi,
I have a grid wich based on a generic list of custom objects. The grid works fine. One of the columns have a complex custom object as content, at runtime the toString() method is used for output. I tried to use the Exporter to create a excel file with the content of the grid. The exporter delievers only the header of the columns and not the content.

Is there any chance to use a generic list of basic types (i.e. List<string, string, string>) as datasource for the exporter?

Thanks for any hint.
Christian

1 Answer, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 29 Jan 2009, 12:35 PM
Hi Christian,

ExportToExcelML works with cell values. This means that when you run the export, the text of the columns comes from the HeaderText property of a particular column and the cells text comes from the cells values. Here is a code block coming from the ExportToExcelML:

private CellElement CreateCellElement(GridViewCellInfo gridCell) 
        { 
            CellElement cellElement = new CellElement(); 
            object value = null
            if (gridCell.RowInfo is GridViewTableHeaderRowInfo) 
            { 
                value = gridCell.ColumnInfo.HeaderText; 
            } 
            else if (gridCell.Value != null
            { 
                value = gridCell.Value; 
            } 
            else 
            { 
                value = string.Empty; 
            } 
            cellElement.Data.DataItem = value; 
            return cellElement; 
        } 
 
Let me expain it in detail. It checks if the cell row is a header row. If it is, the HeaderText property of the cell is used. If the cell row is not a header row, the cell value is used as an export parameter.

This is how export to excel works internally. Please, send me a sample project demonstrating what you have to do and what exactly is the problem if you cannot proceed after my explanation here. I will do my best to help you with a solution.

Also if you have any additional questions please write me back.

Regards,
Boyko Markov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Christian
Top achievements
Rank 1
Answers by
Boyko Markov
Telerik team
Share this question
or