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

[Solved] Export to ExcelML with heading information

4 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stacy
Top achievements
Rank 1
Stacy asked on 29 Sep 2009, 06:35 PM
Hello,
Can someone please explain to me how you add a custom heading to the exported excel information?  I need a title that merges across all columns.

Thank you!
Stacy Frank
Sundial Software Co.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Sep 2009, 04:23 AM
Hello Stacy,

You can use the Caption property of the ownertableview to add custom heading to the grid while exporting. The section 'Including additional information as part of the exported document' of the following help document should help you achieve this.
Exporting tips and tricks

Thanks
Princy.
0
Daniel
Telerik team
answered on 02 Oct 2009, 12:44 PM
Hello Stacy,

Alternatively you can insert the mentioned heading manually in the ExcelMLExportRowCreated. Sample code is shown below:
protected void RadGrid1_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e) 
    if (e.RowType == GridExportExcelMLRowType.HeaderRow) 
    { 
        RowElement row = new RowElement(); 
        CellElement cell = new CellElement(); 
        cell.MergeAcross = e.Row.Cells.Count - 1; 
        cell.Data.DataItem = "HeaderTest"
        row.Cells.Add(cell); 
        e.Worksheet.Table.Rows.Insert(0, row); 
    } 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Stacy
Top achievements
Rank 1
answered on 02 Oct 2009, 08:17 PM
thanks for your responses!  Princy, unfortunately the caption doesn't work for me when it is exported in excelML format so that didn't help.  Daniel I was able to add the row per your example below but the filters on the individual columns (excel filters) when exported are then applied to this row.  What I want is to display a title, centered with the name of the report (aka grid) that the user exported.  Many thanks in advance!!!

Stacy Frank
Sundial Software Co
0
Accepted
Daniel
Telerik team
answered on 08 Oct 2009, 12:58 PM
Hello Stacy,

Thank you for the clarification. Please try the following modification:
protected void RadGrid1_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
{
    if (e.RowType == GridExportExcelMLRowType.HeaderRow)
    {
        RowElement row = new RowElement();
        CellElement cell = new CellElement();
        cell.MergeAcross = e.Row.Cells.Count - 1;
        cell.Data.DataItem = RadGrid1.MasterTableView.Caption;
        cell.StyleValue = "specialStyle";
        row.Cells.Add(cell);
        e.Worksheet.Table.Rows.Insert(0, row);
        e.Worksheet.AutoFilter.Range = "R2C1:R2C2";
    }
}
protected void RadGrid1_ExcelMLExportStylesCreated(object source, GridExportExcelMLStyleCreatedArgs e)
{
    StyleElement style = new StyleElement();
    style.Id = "specialStyle";
    style.FontStyle.Bold = true;
    style.FontStyle.Size = 20;
    style.AlignmentElement.HorizontalAlignment = HorizontalAlignmentType.Center;
    e.Styles.Add(style);
}

Let me know if you need further assistance.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Stacy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel
Telerik team
Stacy
Top achievements
Rank 1
Share this question
or