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

Export Excel (alter excel date time now)

4 Answers 46 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Murilo Savi
Top achievements
Rank 1
Murilo Savi asked on 12 Mar 2014, 05:04 PM
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?

4 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 17 Mar 2014, 12:06 PM
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.

 
0
Murilo Savi
Top achievements
Rank 1
answered on 17 Mar 2014, 12:36 PM
RadGrid1.MasterTableView and 
RadGrid1_ItemDataBound not exist on pivotgrid.
0
Angel Petrov
Telerik team
answered on 19 Mar 2014, 03:04 PM
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.

 
0
Murilo Savi
Top achievements
Rank 1
answered on 19 Mar 2014, 04:45 PM
ok, thankz
Tags
PivotGrid
Asked by
Murilo Savi
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Murilo Savi
Top achievements
Rank 1
Share this question
or