Export Excel (alter excel date time now)

5 posts, 0 answers
  1. Murilo Savi
    Murilo Savi avatar
    15 posts
    Member since:
    Mar 2010

    Posted 12 Mar 2014 Link to this post

    I would like to add a column in excel generated with the day's date, plus the name of the report. I found no matter how to do, could someone help?
  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 17 Mar 2014 Link to this post

    Hi Murilo,

    Dynamically adding a column when exporting is triggered is possible by subscribing to the OnItemCommand event and including such as demonstrated below:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "ExportToExcel")
            {
                RadGrid1.MasterTableView.Columns.Add(new GridBoundColumn()
                {
                    UniqueName="currentDate",
                    HeaderText = "currentDate"
                });
                RadGrid1.Rebind();
            }
        }
    Note that in order to populate the values for that new column you should subscribe to the OnItemDataBound as well.
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            GridDataItem item = e.Item as GridDataItem;
            if (item != null && item.OwnerTableView.GetColumnSafe("currentDate")!=null)
            {
                item["currentDate"].Text = DateTime.Now.ToString();
            }
        }

    In attachments you can find a sample website which illustrates an implementation of such a scenario. The logic in the sample will add a new column and populate it with the current date.

    Regards,
    Angel Petrov
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Murilo Savi
    Murilo Savi avatar
    15 posts
    Member since:
    Mar 2010

    Posted 17 Mar 2014 in reply to Angel Petrov Link to this post

    RadGrid1.MasterTableView and 
    RadGrid1_ItemDataBound not exist on pivotgrid.
  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 19 Mar 2014 Link to this post

    Hello Murilo,

    Please accept my apologies for misunderstanding the requirement.

    The code I provided in my previous post will work when the content of a RadGrid is being exported. However the same can not be achieved when RadPivotGrid is used. The reason for this is that the pivot structure is more complex than that of the grid. For now you can only export the visible content of the RadPivotGrid.

    Regards,
    Angel Petrov
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  6. Murilo Savi
    Murilo Savi avatar
    15 posts
    Member since:
    Mar 2010

    Posted 19 Mar 2014 in reply to Angel Petrov Link to this post

    ok, thankz
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017