NullReferenceException ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), "Xlsx")

3 posts, 0 answers
  1. gao
    gao avatar
    4 posts
    Member since:
    Jun 2018

    Posted 02 Jun 2018 Link to this post

    [NullReferenceException: 未将对象引用设置到对象的实例。] Telerik.Web.UI.Grid.Export.TableViewExporter.ExcelExportRenderForm(HtmlTextWriter nullWriter, Control form) +2339 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +116 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +130 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +46 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +78 System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +49 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +116 System.Web.UI.Page.Render(HtmlTextWriter writer) +38 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +78 Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +952 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +116 System.Web.UI.Page.Render(HtmlTextWriter writer) +38 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +78 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8752

     

      <telerik:RadGrid ID="rgvAccountConfim" runat="server" AllowMultiRowSelection="true"
                            MasterTableView-ShowHeadersWhenNoRecords="true" ShowFooter="true"   Skin="Web20"  
                            HeaderStyle-HorizontalAlign="Center" OnItemDataBound="RadGridHospital_ItemDataBound">
                            <MasterTableView AutoGenerateColumns="False" AllowNaturalSort="false" 
                                DataKeyNames="MoneyConfirmListID,CusName,ReceiveMoneyPlanID,OrderCode,ListCode,ReceivePrice,CusReceivable,CusInvoiceReceivable,bizType"
                                ClientDataKeyNames="MoneyConfirmListID" CommandItemDisplay="None">
                                <NoRecordsTemplate>
                                    没有符合条件的记录。</NoRecordsTemplate>
                                <Columns>
                                    <telerik:GridClientSelectColumn UniqueName="Row" HeaderStyle-Width="30" ItemStyle-HorizontalAlign="Center">
                                    </telerik:GridClientSelectColumn>
                                    <telerik:GridBoundColumn DataField="DepDistrictName" HeaderText="销售区域" ReadOnly="true"
                                        UniqueName="DepDistrictName" HeaderStyle-Width="120" />
                                    <telerik:GridBoundColumn DataField="SaleUserName" HeaderText="销售人员" ReadOnly="true"
                                        UniqueName="SaleUserName" HeaderStyle-Width="70" />
                                    <telerik:GridBoundColumn DataField="CusName" HeaderText="客户名称" ReadOnly="true" UniqueName="CusName"
                                        HeaderStyle-Width="180" />
                                    <telerik:GridBoundColumn DataField="LinkmanName" HeaderText="主联系人" ReadOnly="true"
                                        UniqueName="LinkmanName" HeaderStyle-Width="70" />
                                      <telerik:GridBoundColumn DataField="DataDicDetailIValue" HeaderText="回款方式" ReadOnly="true"
                                        UniqueName="DataDicDetailIValue" HeaderStyle-Width="100" />
                                    <telerik:GridBoundColumn DataField="CusReceivable" HeaderText="发货应收款(元)" ReadOnly="true"
                                        UniqueName="CusReceivable" HeaderStyle-Width="120" ItemStyle-HorizontalAlign="Right" />
                                    <telerik:GridBoundColumn DataField="CusInvoiceReceivable" HeaderText="开票应收款(元)" ReadOnly="true"
                                        UniqueName="CusInvoiceReceivable" HeaderStyle-Width="120" ItemStyle-HorizontalAlign="Right" Display="false" />
                                    <telerik:GridBoundColumn DataField="ReceivePrice" HeaderText="本次收款(元)" ReadOnly="true"
                                        UniqueName="ReceivePrice" HeaderStyle-Width="120" ItemStyle-HorizontalAlign="Right" />
                                     <telerik:GridBoundColumn DataField="SumbillingPrice" HeaderText="税金(元)" ReadOnly="true"
                                            UniqueName="SumbillingPrice" HeaderStyle-Width="100" ItemStyle-HorizontalAlign="Right" />
                                    <telerik:GridTemplateColumn HeaderText="相关订单" HeaderStyle-Width="80" ReadOnly="true">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="linkOrderCode" runat="server" Text='<%# Eval("OrderCode")%>'></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="ReceiveDate" HeaderText="提交日期" ReadOnly="true"
                                        SortExpression="ReceiveDate" UniqueName="ReceiveDate" HeaderStyle-Width="80"
                                        DataFormatString="{0:yyyy-MM-dd}" />
                                    <telerik:GridBoundColumn DataField="Description" HeaderText="提交人" ReadOnly="true"
                                        UniqueName="Description" HeaderStyle-Width="70" Display="false" />
                                    <telerik:GridBoundColumn DataField="ReceiveRemark" HeaderText="备注" ReadOnly="true"
                                        UniqueName="ReceiveRemark" HeaderStyle-Width="200" />
                                    <telerik:GridTemplateColumn HeaderText="状态" HeaderStyle-Width="60">
                                        <ItemTemplate>
                                            <asp:Label ID="lblInPrice" runat="server" Text='<%#GetState(Eval("IsState").ToString())%>'></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="ConfirmUserName" HeaderText="确认人" ReadOnly="true"
                                        UniqueName="ConfirmUserName" HeaderStyle-Width="120" Display="false" />
                                    <telerik:GridTemplateColumn HeaderText="操作" HeaderStyle-Width="170" UniqueName="Confirm">
                                        <ItemTemplate>
                                            <input type="button" id="lbtnConfirm" runat="server"   class ="btn_radgrid_shoukuanqueren" />
                                             <input id="btnPayConfirm" type="button" runat="server" class="greenButtonCss" value="打印收款单"
                                         title="打印收款单" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="回款类型" HeaderStyle-Width="80">
                                        <ItemTemplate>
                                            <asp:Label ID="lblIsRight" runat="server" Text='<%#GetArriveState(Eval("IsRight").ToString())%>'></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="DepositaryBank" HeaderText="开户银行" ReadOnly="true"
                                        UniqueName="DepositaryBank" HeaderStyle-Width="125"  />
                                    <telerik:GridBoundColumn DataField="BankAccountNumber" HeaderText="开户行帐号" ReadOnly="true"
                                        UniqueName="BankAccountNumber" HeaderStyle-Width="135"  />
                                    <telerik:GridBoundColumn DataField="PayeeName" HeaderText="收款人姓名" ReadOnly="true"
                                        UniqueName="PayeeName" HeaderStyle-Width="120"  />   
                                    <%--<telerik:GridBoundColumn DataField="BizType" HeaderText ="收款类型" HeaderStyle-Width="80" ></telerik:GridBoundColumn>  --%>                        
                                </Columns>
                            </MasterTableView>  <headerstyle horizontalalign="Center" Wrap="false" />
                             <ClientSettings AllowColumnsReorder="true"  ReorderColumnsOnClient="true" ClientMessages-DragToGroupOrReorder="拖动调整列显示顺序" ClientMessages-DragToResize="拖动调整列宽" >
                                <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
                                <ClientEvents OnRowSelected="GridRowClick" />
                                <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="200" />
                            <Resizing   EnableRealTimeResize="True" ResizeGridOnColumnResize="True"  AllowColumnResize="True"></Resizing> </ClientSettings>
                        </telerik:RadGrid>

     

    protected void btnExport_Click(object sender, EventArgs e)
            {
                rgvAccountConfim.ExportSettings.Excel.Format = (GridExcelExportFormat)Enum.Parse(typeof(GridExcelExportFormat), "Xlsx");
                rgvAccountConfim.ExportSettings.ExportOnlyData = true;
                rgvAccountConfim.ExportSettings.OpenInNewWindow = true;
                rgvAccountConfim.MasterTableView.GetColumn("Confirm").Display = false;
                rgvAccountConfim.MasterTableView.GetColumn("Row").Display = false;
                rgvAccountConfim.MasterTableView.ExportToExcel();
               
            }

  2. Eyup
    Admin
    Eyup avatar
    3962 posts

    Posted 06 Jun 2018 Link to this post

    Hi Gao,

    Please make sure that you are using a recent version of the controls, which includes the Xlsx exporting option. You can also check that by slightly modifying the corresponding code-behind line as follows:
    rgvAccountConfim.ExportSettings.Excel.Format = GridExcelExportFormat.Xlsx

    You can also check the following article:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/exporting/export-formats/xlsx-and-docx-export

    Please give it a try and let me know whether this resolves the issue.

    Regards,
    Eyup
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. gao
    gao avatar
    4 posts
    Member since:
    Jun 2018

    Posted 06 Jun 2018 in reply to Eyup Link to this post

    I have checked all of these things, and it is still wrong to use this setup and quote all DLL.
Back to Top