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

Excel Export Exception

5 Answers 445 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 23 Mar 2009, 12:27 PM
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

5 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 23 Mar 2009, 01:22 PM
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.
0
Adam
Top achievements
Rank 1
answered on 23 Mar 2009, 01:35 PM
I can do.  I will put it together and submit it as a support ticket.
0
Guido Tapia
Top achievements
Rank 1
answered on 02 Apr 2009, 01:32 AM
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
0
Edward
Top achievements
Rank 1
answered on 25 Nov 2009, 05:33 PM
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(); 

0
Daniel
Telerik team
answered on 25 Nov 2009, 05:59 PM
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.
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Adam
Top achievements
Rank 1
Guido Tapia
Top achievements
Rank 1
Edward
Top achievements
Rank 1
Share this question
or