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

Radgrid excel export-column header always centered.

3 Answers 245 Views
Grid
This is a migrated thread and some comments may be shown as answers.
aykut
Top achievements
Rank 1
aykut asked on 27 Aug 2010, 04:03 PM
When I export grid to excel column headers always centered. I cannot change it. radgrid's all column headersactuallt left aligned. this situation exists even in live demos. http://localhost:8301/radcontrols_aspnetajax/grid/examples/generalfeatures/exporting/defaultcs.aspx
can I change the headers's alignment while exported ? there's only one ticket at this forum and there's no answer to that. (I already tried offered solutions)
thanks.

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 27 Aug 2010, 09:37 PM
Hello Aykut,

Please try the following:
bool isExport = false;
protected void Button1_Click(object sender, EventArgs e)
{
    isExport = true;
    RadGrid1.ExportSettings.ExportOnlyData = true;
    RadGrid1.ExportSettings.IgnorePaging = true;
    RadGrid1.MasterTableView.ExportToExcel();
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem && isExport)
        foreach(TableCell cell in e.Item.Cells)
            cell.Style.Add("text-align", "left");
}

Word/Excel export (HTML-based)

Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
aykut
Top achievements
Rank 1
answered on 28 Aug 2010, 11:04 AM
This is what I am looking for my friend. I tried it and works well.
thank you.
0
Jörgen Hyving
Top achievements
Rank 1
answered on 11 Nov 2010, 02:51 PM
Or you could simplify it like this:
protected void r1_GridExporting(object sender, GridExportingArgs e)
{
    if (e.ExportType == ExportType.Excel)
    {
        string css = "<style> td {text-align:left}</style>";
        e.ExportOutput = e.ExportOutput.Replace("</head>", css + "</head>");
 
    }
}
Best regards, 

Jorgen
Tags
Grid
Asked by
aykut
Top achievements
Rank 1
Answers by
Daniel
Telerik team
aykut
Top achievements
Rank 1
Jörgen Hyving
Top achievements
Rank 1
Share this question
or