Excel Export Exception

6 posts, 0 answers
  1. Adam
    Adam avatar
    6 posts
    Member since:
    Dec 2008

    Posted 23 Mar 2009 Link to this post

    I created a simple test app that builds a .NET Data Table and binds it using DataBoundColumns to a RadGrid using version 2009.1.311.35.  I have set the ExportSettings as ExportOnlyData=true, IgnorePaging=true and OpenInNewWindow=true.  Everything works fine if I set the Excel Format to Html, but if I set it to ExcelML I get the following error:

    Object reference not set to an instance of an object. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

    Stack Trace: 


    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Web.UI.Grid.Export.TableViewExporter.ExcelExportRenderForm(HtmlTextWriter nullWriter, Control form) +1395
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
       System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +8676409
       System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
       System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
       System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
       Telerik.Web.UI.Grid.Export.TableViewExporter.ExcelExportRenderPage(HtmlTextWriter nullWriter, Control page) +146
       System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
       System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
       System.Web.UI.Page.Render(HtmlTextWriter writer) +29
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
       System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

     Do I need to have Excel installed on the server for it to export to Excel?  Is there some setting I am missing?  I am following the demo located http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx and other than my data source being from a built data table instead of a database table, everything else is the same.

    Adam Gritt
  2. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 23 Mar 2009 Link to this post

    Hello Adam,

    Is it possible to provide a sample project illustrating the depicted problem? We will provide straight to-the-point answer as soon as we are able to debug it locally.

    Regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam
    Adam avatar
    6 posts
    Member since:
    Dec 2008

    Posted 23 Mar 2009 Link to this post

    I can do.  I will put it together and submit it as a support ticket.
  5. Guido Tapia
    Guido Tapia avatar
    87 posts
    Member since:
    Jul 2012

    Posted 01 Apr 2009 Link to this post

    Hi Adam,

    Can you post the workaround (if any) for this problem as I'm encountering exactly the same issue.  Did you manage to identify the cause of this problem?

    Thanks

    Guido
  6. Edward
    Edward avatar
    20 posts
    Member since:
    Mar 2009

    Posted 25 Nov 2009 Link to this post

    Running in to the same issue here

    Here is the markup

            <div style="padding: 14px"
                    <telerik:RadGrid ID="RadGrid2" runat="server"
                            <ExportSettings ExportOnlyData="True" FileName="MeasureExport"
                                    <Excel Format="ExcelML" /> 
                            </ExportSettings> 
                            <MasterTableView CommandItemDisplay="Top" UseAllDataFields="True"
                                    <CommandItemSettings ExportToExcelImageUrl="~/images/icxls.gif" ShowExportToExcelButton="True" /> 
                            </MasterTableView> 
                    </telerik:RadGrid> 
            </div> 

    I am just handing the Grid a DataTable in the code-behind.
    When I switch the html format it works but Excel warns about opening a file that is in the wrong format.
                            RadGrid2.DataSource = _table
                            RadGrid2.DataBind(); 

  7. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 25 Nov 2009 Link to this post

    Hello Edward,

    Modify your markup/code-behind this way and you will be able to sidestep the error:
    <telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource">
     ....

    protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        RadGrid2.DataSource = _table;
    }

    ExcelML engine should have access to your data source after postback and therefor it doesn't work in most scenarios when using simple data binding (with Not IsPostBack check)

    Please examine the following links:
    Simple Data-binding
    Advanced Data-binding

    The warning message you mentioned was discussed many times before - it is well explained here:
    Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site
    The file you are trying to open, '[filename]', is in a different format" Excel Error

    Best regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017