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

Regarding .xlsx export in Radgrid

1 Answer 41 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Ananya asked on 28 Jan 2020, 07:18 AM

In RadGrid1_InfrastructureExporting function , I m not able to apply styling on partial text of  a particular cell.

Ex - if cell[1,1] = hello world. How to make "hello" as bold.

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 31 Jan 2020, 08:02 AM

Hi Ananya,

The InfrastructureExporting function you can style the whole cell content, but the easiest way to style part of the cell text is to use a template column, exporting it to XLX file with a similar setup:

        <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
             AutoGenerateColumns="false" PageSize="10" AllowPaging="false">
            <MasterTableView ClientDataKeyNames="Count" CommandItemDisplay="Top">
                    <telerik:GridBoundColumn HeaderText="ID" DataField="Id"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="ProductName" DataField="ProductName">
                        <ItemStyle ForeColor="Red" />
                    <telerik:GridBoundColumn HeaderText="Count" DataField="Count"></telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="ProductName">
                            <span style="font-weight: 900"><%# Eval("ProductName").ToString().Split(' ')[0]%></span>
                            <%# Eval("ProductName").ToString().Split(' ')[1]%>
                <CommandItemSettings ShowExportToExcelButton="true" />
            <ExportSettings ExportOnlyData="true"></ExportSettings>

    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        (sender as RadGrid).DataSource = GetData();

    private DataTable GetData()
        DataTable dt = new DataTable();


        for (int i = 0; i < 15; i++)
            dt.Rows.Add("Id_" + i, "Product name " + i, i + 400);

        return dt;

Please, give solution a try and let us know should we can help you any further on this matter.

Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question