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

Regarding .xlsx export in Radgrid

1 Answer 54 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ananya
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
0
Vessy
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">
                <Columns>
                    <telerik:GridBoundColumn HeaderText="ID" DataField="Id"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="ProductName" DataField="ProductName">
                        <ItemStyle ForeColor="Red" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Count" DataField="Count"></telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="ProductName">
                        <ItemTemplate>
                            <span style="font-weight: 900"><%# Eval("ProductName").ToString().Split(' ')[0]%></span>
                            <%# Eval("ProductName").ToString().Split(' ')[1]%>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
                <CommandItemSettings ShowExportToExcelButton="true" />
            </MasterTableView>
            <ExportSettings ExportOnlyData="true"></ExportSettings>
        </telerik:RadGrid>

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

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

        dt.Columns.Add("Id");
        dt.Columns.Add("ProductName");
        dt.Columns.Add("Count");

        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.

Regards,
Vessy
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.
Tags
General Discussions
Asked by
Ananya
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or