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

RadGrid Export to ExcelML *with* Hierarchy Intact

10 Answers 458 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Romany
Top achievements
Rank 1
Romany asked on 09 Jul 2008, 01:16 AM
Hello:

I have a fairly simple page which pulls the MasterTableView data from one dataset and the DetailTables data from another dataset.

Exporting to Excel with hierarchy works in normal Excel mode. However, a new requirement is that the parent headers have background shading. Using ExcelML will not export with the hierarchy; only the parent rows get exported.

I am using version 2008.01.0618.20 currently after upgrading from 2008.01.0415.20.

The ASPX page looks like this:
<MasterTableView DataKeyNames="fooData" Name="fooName" HierarchyLoadMode="ServerBind" HierarchyDefaultExpanded="true" AllowPaging="true" UseAllDataFields="true" CanRetrieveAllData="true"
  <DetailTables> 
    <telerik:GridTableView runat="server" Name="Details" DataKeyNames="fooDetail" Width="100%" HierarchyDefaultExpanded="true"
      <ParentTableRelation> 
        <telerik:GridRelationFields DetailKeyField="fooDetail" MasterKeyField="fooData" /> 
      </ParentTableRelation> 
      <Columns> 
 
Etc...



And, in the code-behind:

RadGrid.ExportSettings.FileName = "fooData" 
RadGrid.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML 
RadGrid.ExportSettings.IgnorePaging = "true" 
RadGrid.ExportSettings.ExportOnlyData = "true" 
 
'This code block worked for regular Excel export 
For Each gi As GridItem In RadGrid.Items 
  gi.Expanded = True 
Next 
 
RadGrid.MasterTableView.ExportToExcel() 

This code worked perfectly for regular Excel but not for ExcelML.
The only difference is that I added the following line, which is required:
RadGrid.ExportSettings.ExportOnlyData = "true"

Thank You,
Romany

10 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 11 Jul 2008, 08:38 AM
Hi Romany,

Unfortunately the current version of RadGrid's ExcelML does not support hierarchy export. We have added this feature in our To-Do list for future control releases.

Please excuse us for any inconvenience this might cause.

Kind regards,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
shadow
Top achievements
Rank 2
answered on 11 Apr 2010, 08:10 PM
Hi Telerik,

I am using Q3, 2009 SP2.
I want to export the hierarchy RadGrid to excel format, does this feature support with my version.


0
Rosen
Telerik team
answered on 12 Apr 2010, 08:21 AM
Hi Farid,

Indeed the version you are refering to does supports exporting hierarchy grids.

All the best,
Rosen
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
shadow
Top achievements
Rank 2
answered on 12 Apr 2010, 01:09 PM
Thank you Telerik,

Can you please let me know how to export a hierarchy grid to excelMl format.
I am trying to do this but now able, I am getting an exception, here I am sending you the details of exception and
My code.

One more thing, I am exporting an simple grid to excel and it is not Exporting the grid header to excel file, very strange.
Please help me in these issue.


Code:

            gvInvoice.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;
            gvInvoice.ExportSettings.IgnorePaging = true;
            gvInvoice.ExportSettings.ExportOnlyData = true;
            foreach (Telerik.Web.UI.GridItem gi in gvInvoice.Items)
            {
                gi.Expanded = true;
            }
            gvInvoice.MasterTableView.ExportToExcel();


Just for reminder I am using Q3, 2009 SP2.

I am binding grid with DataTable in code behind file.
Thanks 
0
Rosen
Telerik team
answered on 13 Apr 2010, 12:00 PM
Hello Farid,

I have attached a sample page which demonstrates how to achieve the functionality in question.

Regards,
Rosen
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
shadow
Top achievements
Rank 2
answered on 22 Apr 2010, 02:32 PM
Hi Telerik,

Thank you for your support,
But I am sorry to say my problem is still not saved.

I have used the export code you supplied in latest reply.

But now I am getting this exception


An error occurred and we were unable to process your request. 

Object reference not set to an instance of an object.

http://localhost/Connected/reports/InvoiceReport.aspx


System.NullReferenceException: Object reference not set to an instance of an object. at Telerik.Web.UI.Grid.Export.TableViewExporter.ExcelExportRenderForm(HtmlTextWriter nullWriter, Control form) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) at Telerik.Web.UI.Grid.Export.TableViewExporter.ExcelExportRenderPage(HtmlTextWriter nullWriter, Control page) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Page.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)



0
Rosen
Telerik team
answered on 23 Apr 2010, 02:50 PM
Hello Farid,

Can you please post your page's declaration and code-behind (using the codeblock dialog)?

Regards,
Rosen
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
shadow
Top achievements
Rank 2
answered on 23 Apr 2010, 04:15 PM

using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using asapNet; 
using Telerik.Web.UI; 
 
 
public partial class Reports_InvoiceReport : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!IsPostBack) 
        { 
 
            tbStartDate.Text = DateTime.Now.AddDays(-30).ToShortDateString(); 
            tbEndDate.Text = DateTime.Now.ToShortDateString(); 
            Customers custs = new Customers(); 
            custs.Advanced.CustomSql = "Select C.CustomerID, P.FirstName + ', ' + P.LastName Name From Customer C LEFT JOIN Person P ON P.PersonID=C.PersonID WHERE OrganizationID=" + SessionFacade.OrganizationID.ToString() + " ORDER BY LastName"; 
            custs.Load(); 
            ddlCustomer.DataSource = custs.DataTable; 
 
            ddlCustomer.DataBind(); 
        } 
    } 
    protected void btnFilter_Click(object sender, EventArgs e) 
    { 
        BindGrid(false); 
    } 
    private void BindGrid(bool Export) 
    { 
        Invoices invs = new Invoices(); 
        invs.Advanced.CustomSql = "SELECT I.InvoiceID, I.InvoiceDate, P.FirstName, P.LastName, I.InvoiceStatusCD, I.InvoiceSubTotal, I.SalesTax, I.Discount, I.InvoiceTotal FROM Invoice I LEFT JOIN Customer C ON C.CustomerId=I.CustomerID LEFT JOIN Person P ON P.PersonID=C.PersonID WHERE I.CustomerID=" + ddlCustomer.SelectedValue + 
                " AND InvoiceDate BETWEEN '" + tbStartDate.Text + 
                "' AND '" + tbEndDate.Text + 
                "' AND I.OrganizationID=" + SessionFacade.OrganizationID.ToString(); 
 
 
        if (ddlInvoiceStatus.SelectedValue == "0") 
        { 
 
        } 
        else if (ddlInvoiceStatus.SelectedValue == "1") 
        { 
            invs.Advanced.CustomSql += " AND InvoiceStatusCD<>'VOID'"; 
        } 
        else 
        { 
            invs.Advanced.CustomSql += " AND InvoiceStatusCD='" + ddlInvoiceStatus.SelectedValue + "'"; 
        } 
 
        invs.Advanced.CustomSql += " ORDER BY InvoiceId DESC"; 
 
        invs.Load(); 
 
 
        gvInvoice.DataSource = invs.DataTable; 
        gvInvoice.DataBind(); 
 
        gvExport.DataSource = invs.DataTable; 
        gvExport.DataBind(); 
    } 
    protected void gvInvoice_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) 
    { 
        Telerik.Web.UI.GridDataItem dataItem = (Telerik.Web.UI.GridDataItem)e.DetailTableView.ParentItem; 
        switch (e.DetailTableView.Name) 
        { 
            case "InvoiceItems": 
                { 
                    string invoiceID = dataItem.GetDataKeyValue("InvoiceID").ToString(); 
                    e.DetailTableView.DataSource = DBConnect.HData.getDataSet("Select dbo.f_GetItemName(ItemTypeCD, ItemID) ItemName, * From InvoiceItem Where InvoiceID=" + invoiceID); 
                    break; 
                } 
            case "Enrollments": 
                { 
                    string invItemID = dataItem.GetDataKeyValue("InvoiceItemID").ToString(); 
                    InvoiceItem iItem = new InvoiceItem(int.Parse(invItemID)); 
                    if (iItem.ItemTypeCd == "EVENT" && iItem.EventEnrollmentID > 0) 
                    { 
                        EventEnrollments enrollment = new EventEnrollments(); 
                        enrollment.Advanced.CustomSql = "Select E.EnrollmentDate, E.EnrollmentStatusCD, P.FirstName pFirstName, P.LastName pLastName From EventEnrollment E LEFT JOIN Customer C ON C.CustomerId=E.StudentID LEFT JOIN Person P ON P.PersonID=C.PersonID  Where EventEnrollmentID=" + iItem.EventEnrollmentID.ToString(); 
                        enrollment.Load(); 
                        e.DetailTableView.DataSource = enrollment
                        break; 
                    } 
                    break; 
                } 
            case "InvoiceTransactions": 
                { 
                    string invoiceID = dataItem.GetDataKeyValue("InvoiceID").ToString(); 
                    e.DetailTableView.DataSource = DBConnect.HData.getDataSet("Select * From InvoiceTransaction Where InvoiceID=" + invoiceID); 
                    break; 
                } 
        } 
    } 
    protected void lbExcel_Click(object sender, EventArgs e) 
    { 
        try 
        { 
            //gvExport.ExportSettings.FileName = "Customer Invoice Report - Excel"
            //gvExport.ExportSettings.ExportOnlyData = true
            //gvExport.ExportSettings.OpenInNewWindow = true
            //gvExport.MasterTableView.ExportToExcel(); 
 
 
            gvInvoice.MasterTableView.HierarchyLoadMode = GridChildLoadMode.ServerBind; 
            gvInvoice.ExportSettings.ExportOnlyData = true
            gvInvoice.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML; 
            gvInvoice.ExportSettings.IgnorePaging = true
            gvInvoice.MasterTableView.ExportToExcel(); 
        } 
        catch (Exception ex) 
        { 
            lblMsg.Text = ex.Message; 
        } 
    } 
 
<%@ Page Language="C#" MasterPageFile="~/Reports/AsapReporting.master" AutoEventWireup="true" 
    CodeFile="InvoiceReport.aspx.cs" Inherits="Reports_InvoiceReport" %> 
 
<%@ Register Src="../Controls/DateTimeStarderdControl.ascx" TagName="DateTimeStarderdControl" 
    TagPrefix="uc2" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register Src="../Controls/Waiter.ascx" TagName="Waiter" TagPrefix="uc1" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"
       <asp:UpdateProgress ID="UpdateProgress1" runat="server"
        <ProgressTemplate> 
            <uc1:Waiter ID="Waiter1" runat="server" /> 
        </ProgressTemplate> 
    </asp:UpdateProgress> 
    <asp:UpdatePanel ID="UpdatePanel1" runat="server"
     <Triggers> 
        <asp:PostBackTrigger ControlID="lbExcel" /> 
    </Triggers> 
        <ContentTemplate> 
    <div class="contentBoxBGreen" style="width: 98%"
        <h2> 
            Invoice Report</h2> 
        <table> 
            <tr> 
                <td> 
                    Invoice Status:</td> 
                <td> 
                    <asp:DropDownList ID="ddlInvoiceStatus" runat="server"
                        <asp:ListItem Text="Paid" Value="PAID"></asp:ListItem> 
                        <asp:ListItem Text="Partial" Value="PARTIAL"></asp:ListItem> 
                        <asp:ListItem Text="Pend" Value="PEND"></asp:ListItem> 
                        <asp:ListItem Text="Processing" Value="PROCESSING"></asp:ListItem> 
                        <asp:ListItem Text="Unpaid" Value="UNPAID"></asp:ListItem> 
                        <asp:ListItem Text="Void" Value="VOID"></asp:ListItem> 
                        <asp:ListItem Text="All (except Void)" Value="0"></asp:ListItem> 
                        <asp:ListItem Text="All (include Void)" Value="1"></asp:ListItem> 
                    </asp:DropDownList></td
                <td> 
                    Customer:</td> 
                <td> 
                    <asp:DropDownList ID="ddlCustomer" runat="server" DataTextField="Name" DataValueField="CustomerID"
                    </asp:DropDownList></td
            </tr> 
            <tr> 
                <td> 
                    From Date:</td> 
                <td> 
                    <uc2:DateTimeStarderdControl ID="tbStartDate" runat="server" IsRequired="true" /> 
                </td> 
                <td> 
                    To Date:</td> 
                <td> 
                    <uc2:DateTimeStarderdControl ID="tbEndDate" runat="server" IsRequired="true" /> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                </td> 
                <td> 
                    <td> 
                    </td> 
                    <td align="right"
                        <asp:Button ID="btnFilter" runat="server" OnClick="btnFilter_Click" Text="Filter" /></td
            </tr> 
        </table> 
        <asp:Label ID="lblMsg" runat="server" ForeColor="Red"></asp:Label> 
        <div style="text-align: right;"
            <asp:LinkButton ID="lbExcel" runat="server" OnClick="lbExcel_Click">Export to Excel</asp:LinkButton> 
        </div> 
    </div> 
    <br /> 
    <telerik:RadGrid ID="gvInvoice" runat="server" AutoGenerateColumns="False" GridLines="None" 
        OnDetailTableDataBind="gvInvoice_DetailTableDataBind"
        <MasterTableView DataKeyNames="InvoiceID" Width="100%"
            <DetailTables> 
                <telerik:GridTableView Name="InvoiceItems" DataKeyNames="InvoiceItemID" Width="100%" 
                    runat="server" Caption="Invoice Items" Font-Bold="False"
                    <DetailTables> 
                        <telerik:GridTableView Name="Enrollments" Width="100%" runat="server" ExpandCollapseColumn-ButtonType="ImageButton" 
                            ExpandCollapseColumn-CollapseImageUrl="../Images/Expendplus.gif" ExpandCollapseColumn-ExpandImageUrl="../Images/Collepseminus.gif"
                            <Columns> 
                                <telerik:GridBoundColumn DataField="pFirstName" HeaderText="First Name" UniqueName="pFirstName"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="pLastName" HeaderText="Last Name" UniqueName="pLastName"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="EnrollmentStatusCd" HeaderText="Enrollment StatusCd" 
                                    UniqueName="EnrollmentStatusCd"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="EnrollmentDate" HeaderText="Enrollment Date" 
                                    UniqueName="EnrollmentDate"
                                </telerik:GridBoundColumn> 
                            </Columns> 
                        </telerik:GridTableView> 
                    </DetailTables> 
                    <Columns> 
                        <telerik:GridBoundColumn DataField="ItemName" HeaderText="Item Name" UniqueName="ItemName"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="FeeItemCost" HeaderText="Item Cost" UniqueName="FeeItemCost" 
                            DataType="System.Decimal" DataFormatString="{0:C}"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Quantity" HeaderText="Qty" UniqueName="Quantity"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Discount" HeaderText="Discount" UniqueName="Discount" 
                            DataType="System.Decimal" DataFormatString="{0:C}"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="TotalItemCost" HeaderText="Total Cost" UniqueName="TotalItemCost" 
                            DataType="System.Decimal" DataFormatString="{0:C}"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="RefundAmount" HeaderText="Refund Amount" UniqueName="RefundAmount" 
                            DataType="System.Decimal" DataFormatString="{0:C}"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="PaymentApplied" HeaderText="Payment Applied" 
                            UniqueName="PaymentApplied" DataType="System.Decimal" DataFormatString="{0:C}"
                        </telerik:GridBoundColumn> 
                    </Columns> 
                    <ExpandCollapseColumn Visible="True" ButtonType="ImageButton" CollapseImageUrl="~/Images/SingleMinus.gif" 
                        ExpandImageUrl="~/Images/SinglePlus.gif" HeaderText="Invoice Items Details"
                    </ExpandCollapseColumn> 
                </telerik:GridTableView> 
                <telerik:GridTableView Name="InvoiceTransactions" Width="100%" runat="server" Caption="Invoice Transactions"
                    <Columns> 
                        <telerik:GridBoundColumn DataField="TransactionDate" HeaderText="Transaction Date" 
                            UniqueName="TransactionDate"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="PaymentAmount" HeaderText="Payment Amount" UniqueName="PaymentAmount" 
                            DataType="System.Decimal" DataFormatString="{0:C}"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="InvoiceTransactionCode" HeaderText="Invoice Transaction Code" 
                            UniqueName="InvoiceTransactionCode"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="PaymentType" HeaderText="Payment Type" UniqueName="PaymentType"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="GatewayTransactionID" HeaderText="Gateway TransactionID" 
                            UniqueName="GatewayTransactionID"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="ProcessedByAppCd" HeaderText="Processed By AppCd" 
                            UniqueName="ProcessedByAppCd"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="TransactionNotes" HeaderText="Transaction Notes" 
                            UniqueName="TransactionNotes"
                        </telerik:GridBoundColumn> 
                    </Columns> 
                    <ExpandCollapseColumn HeaderText="Invoce Transactions Details"
                    </ExpandCollapseColumn> 
                </telerik:GridTableView> 
            </DetailTables> 
            <Columns> 
                <telerik:GridBoundColumn DataField="InvoiceID" HeaderText="Invoice Id" UniqueName="column"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="InvoiceDate" HeaderText="Invoice Date" UniqueName="InvoiceDate"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="FirstName"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="LastName"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="InvoiceStatusCD" HeaderText="Invoice Status" 
                    UniqueName="InvoiceStatusCD"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="InvoiceSubTotal" HeaderText="Sub Total" UniqueName="SubTotal" 
                    DataType="System.Decimal" DataFormatString="{0:C}"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="SalesTax" HeaderText="Sales Tax" UniqueName="SalesTax" 
                    DataType="System.Decimal" DataFormatString="{0:C}"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Discount" HeaderText="Discount" UniqueName="Discount" 
                    DataType="System.Decimal" DataFormatString="{0:C}"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="InvoiceTotal" HeaderText="Total" UniqueName="Total" 
                    DataType="System.Decimal" DataFormatString="{0:C}"
                </telerik:GridBoundColumn> 
            </Columns> 
            <ExpandCollapseColumn Visible="True" ButtonType="ImageButton" CollapseImageUrl="~/Images/SinglePlus.gif" 
                ExpandImageUrl="~/Images/SingleMinus.gif"
            </ExpandCollapseColumn> 
        </MasterTableView> 
    </telerik:RadGrid> 
    <asp:Panel ID="pvlExport" runat="server" Visible="false"
        <telerik:RadGrid ID="gvExport" runat="server" AutoGenerateColumns="False" GridLines="both"
            <MasterTableView> 
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px" /> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="InvoiceID" HeaderText="Invoice Id" UniqueName="column"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="InvoiceDate" HeaderText="Invoice Date" UniqueName="InvoiceDate"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="FirstName"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="LastName"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="InvoiceStatusCD" HeaderText="Invoice Status" 
                        UniqueName="InvoiceStatusCD"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="InvoiceSubTotal" HeaderText="Sub Total" UniqueName="SubTotal" 
                        DataType="System.Decimal" DataFormatString="{0:C}"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="SalesTax" HeaderText="Sales Tax" UniqueName="SalesTax" 
                        DataType="System.Decimal" DataFormatString="{0:C}"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Discount" HeaderText="Discount" UniqueName="Discount" 
                        DataType="System.Decimal" DataFormatString="{0:C}"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="InvoiceTotal" HeaderText="Total" UniqueName="Total" 
                        DataType="System.Decimal" DataFormatString="{0:C}"
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
    </asp:Panel> 
          </ContentTemplate> 
    </asp:UpdatePanel> 
    <br /> 
</asp:Content> 
 
0
Rosen
Telerik team
answered on 28 Apr 2010, 08:58 AM
Farid,

The error is caused by the fact that you are using simple databinding to populate the RadGrid. In order to use export to ExcelML, you should bind the grid control through AdvancedDataBinding or declaratively by DataSourceControl, as shown in the sample I have sent you and stated in the documentation here.

Kind regards,
Rosen
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
Asutosh
Top achievements
Rank 1
answered on 17 Jun 2014, 12:04 PM
hi

i am exporting heirarchy radgrid in excel

how to export radgrid in excel without OnNeedDataSource

i am binding datasource to radgrid on button click event 

if i am not use OnNeedDataSource,it give me object reference is null

my code for binding grid is 

 grd_firstchart_aco.DataSource = table;

 grd_firstchart_aco.DataBind();
and code for export to excel is below
  grd_forth_aco.ExportSettings.ExportOnlyData = true;
        grd_forth_aco.ExportSettings.IgnorePaging = true;
        grd_forth_aco.ExportSettings.OpenInNewWindow = true;
        grd_forth_aco.ExportSettings.FileName = "fileName";
        grd_forth_aco.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
        grd_forth_aco.ExportSettings.HideStructureColumns = true;

        grd_forth_aco.MasterTableView.HierarchyDefaultExpanded = true;
        grd_forth_aco.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;

        grd_forth_aco.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
        grd_forth_aco.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;

        grd_forth_aco.MasterTableView.ExportToExcel();
thanks

Tags
Grid
Asked by
Romany
Top achievements
Rank 1
Answers by
Rosen
Telerik team
shadow
Top achievements
Rank 2
Asutosh
Top achievements
Rank 1
Share this question
or