One of the column of datagrid is not exporting to excel

3 Answers 113 Views
General Discussions
Vitaly
Top achievements
Rank 1
Iron
Vitaly asked on 24 Oct 2022, 02:34 PM

Good morning ,

I have a datagrid in my project and for some reason one column does not exporting to excel spreadhseet.

The column name is called 'Location'

Please see my html:

telerik:RadGrid ID="EmplReqGrid" runat="server" Skin="Simple" 
                            GridLines="None" AllowPaging="true" AllowSorting="true" 
                            onexcelmlexportrowcreated="EmplReqGrid_ExcelMLExportRowCreated" 
                            onexcelmlexportstylescreated="EmplReqGrid_ExcelMLExportStylesCreated" 
                            onitemcommand="EmplReqGrid_ItemCommand" onitemcreated="EmplReqGrid_ItemCreated" 
                            onitemdatabound="EmplReqGrid_ItemDataBound" 
                            onneeddatasource="EmplReqGrid_NeedDataSource" 
                            onpageindexchanged="EmplReqGrid_PageIndexChanged" 
                            onpagesizechanged="EmplReqGrid_PageSizeChanged" 
                            onpdfexporting="EmplReqGrid_PdfExporting" 
                            onsortcommand="EmplReqGrid_SortCommand" >
                     <ExportSettings FileName="EmplReqRpt"  OpenInNewWindow="true" IgnorePaging="true" ExportOnlyData="true">
                      <Excel  Format="ExcelML" FileExtension="xls"/>
                      <Pdf FontType="Subset" PaperSize="letter" />
                     </ExportSettings>
                     <MasterTableView AutoGenerateColumns="false" AllowMultiColumnSorting="true" >
                         <HeaderStyle Font-Names="Arial"   BackColor="#3974AE" ForeColor="White" Font-Size="Small"  />
                       <Columns>

                        <telerik:GridBoundColumn HeaderText="Eis-Id" DataField="PRI" UniqueName="PRI" ReadOnly="True" SortExpression="PRI" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" >
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn HeaderText="Name" DataField="NAME" UniqueName="NAME" Display="false" ></telerik:GridBoundColumn>

                        <telerik:GridBoundColumn HeaderText="ReqNo" DataField="TRKNO" UniqueName="TRKNO" ReadOnly="True" SortExpression="TRKNO" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" >
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn HeaderText="Job" DataField="JOB" UniqueName="JOB" ReadOnly="True" SortExpression="JOB" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" >
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn HeaderText="Location" DataField="LOC" UniqueName="LOC" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ReadOnly="true" SortExpression="LOC" >
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn HeaderText="Term" DataField="TERMID" UniqueName="TERMID" ReadOnly="True" SortExpression="TERMID" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="Start Date" DataField="TERMST" UniqueName="TERMST" ReadOnly="true" DataFormatString="{0:MM/dd/yyyy}" SortExpression="TERMST" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn HeaderText="End Date" DataField="TERMEND" UniqueName="TERMEND" ReadOnly="true" DataFormatString="{0:MM/dd/yyyy}" SortExpression="TERMEND" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn HeaderText="No of Days" DataField="NUMP" UniqueName="NUMP" ReadOnly="True" SortExpression="NUMP" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>


                        <telerik:GridBoundColumn HeaderText="Process Status" DataField="APPRFLAG" UniqueName="APPRFLAG" ReadOnly="True" SortExpression="APPRFLAG" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn> 


                        <telerik:GridBoundColumn HeaderText="Rec Status" DataField="STATUS" UniqueName="STATUS" ReadOnly="True" SortExpression="STATUS" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn HeaderText="Process Status Date" DataField="FORMDATE" UniqueName="FORMDATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" SortExpression="FORMDATE" HeaderButtonType="TextButton" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
                        </telerik:GridBoundColumn>

                        <telerik:GridBoundColumn DataField="REQFLAG" UniqueName="REQFLAG" Display="false"></telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="SENDFLAG" UniqueName="SENDFLAG" Display="false"></telerik:GridBoundColumn>

                         <telerik:GridBoundColumn DataField="BEG_FALL" UniqueName="BEG_FALL" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="END_FALL" UniqueName="END_FALL" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="BEG_SPRING" UniqueName="BEG_SPRING" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="END_SPRING" UniqueName="END_SPRING" Display="false"></telerik:GridBoundColumn> 
                         <telerik:GridBoundColumn DataField="BEG_ALL" UniqueName="BEG_ALL" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="END_ALL" UniqueName="END_ALL" Display="false"></telerik:GridBoundColumn> 
                         <telerik:GridBoundColumn DataField="TRKSEQ" UniqueName="TRKSEQ" Display="false"></telerik:GridBoundColumn>  
                         <telerik:GridBoundColumn DataField="FLAG" UniqueName="FLAG" Display="false"></telerik:GridBoundColumn> 
                         <telerik:GridBoundColumn DataField="SCHEDULE" UniqueName="SCHEDULE" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="UPDFLAG " UniqueName="UPDFLAG" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="GALFLAG" UniqueName="GALFLAG" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="LIC_DESCR" UniqueName="LIC_DESCR" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="HSIND" UniqueName="HSIND" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="CFN" UniqueName="CFN" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="APPRNAME" UniqueName="APPRNAME" Display="false"></telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="APPREMAIL" UniqueName="APPREMAIL" Display="false"></telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn HeaderText="Link to Form" UniqueName="ButtonColumn" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="150px" >

                                 <ItemTemplate>
                                  <asp:ImageButton ID="ReqFormBtn" ImageUrl="~/Image/update.jpg" 
                                       BackColor="#5A8EC1"
                                       ToolTip="update,re-submit or print the request" runat="server" CommandName="Redirect" Width="18px" Height="18px" Visible="false" />
                                  <asp:ImageButton ID="ApprFormBtn" ImageUrl="~/Image/Appr_Button.jpg" BackColor="#5A8EC1" 
                                        ToolTip="approve/disapprove request" runat="server" CommandName="Approve" Width="18px" Height="18px" ImageAlign="TextTop" Visible="false" />
                                  <asp:Image ID="Image1" runat="server" ToolTip="HR REQUEST" ImageUrl="~/Image/HR_Request3.jpg" Width="12px" Height="12px" Visible="false" /> 
                                  <%--<asp:ImageButton ID="CancelReqBtn" ImageUrl="~/Image/Cancel_button6.png" runat="server" CommandName="Cancel" ImageAlign="Right" BackColor="Transparent" ToolTip="cancel the request" Width="50px" Height="20px" Visible="false" OnClientClick="ConfirmCancel(value);" />--%>
                                  <asp:ImageButton ID="GalaxyGBtn" runat="server" ImageUrl="~/Image/Galaxy.png" Width="18px" Height="18px" BackColor="#BDCBDE" ToolTip="galaxy generated/updated request" CommandName="GalaxyRequest" Visible="false" />
                                  <asp:ImageButton ID="PlaceHolderBtn" runat="server" ImageUrl="~/Image/PlaceHolder.jpg" Width="17px" Height="17px"  ToolTip="placeholder must be budgeted" Visible="false" BackColor="#BDCBDE" CommandName="PlaceHolderRequest" />
                                  <asp:ImageButton ID="HistoryBtn" runat="server" ImageUrl="~/Image/HistoryReq.png" Width="20px" Height="20px" ToolTip="Archive" BackColor="#BDCBDE" Visible="false" CommandName="HistoryRequest"  /> 
                                 </ItemTemplate>
                        </telerik:GridTemplateColumn> 

                       </Columns>
                     </MasterTableView>
                     <ClientSettings EnableRowHoverStyle="True" EnablePostBackOnRowClick = "false">
                      <Selecting AllowRowSelect="false" /> 
                     </ClientSettings>
                   </telerik:RadGrid>

And here is event which do exporting:

 protected void ExporttoExcel_Click1(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (!IsPostBack)
                    return;

                RadGrid ReqInfoGrid = (RadGrid)EmpReqReport.FindItemByValue("EmployeeData").FindControl("EmplReqGrid");
                ReqInfoGrid.DataSource = Session["dtGrid"];
                ReqInfoGrid.DataBind();
                ReqInfoGrid.MasterTableView.GetColumn("NAME").Display = true;
                ReqInfoGrid.MasterTableView.ExportToExcel();

            }
            catch (Exception ex)
            {
                throw;
            }
        }

Please help me to resolve this issue.

thanks.

Vitaly.

                                                                                                                                                                                                                                                                                                                                                      

3 Answers, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 27 Oct 2022, 08:41 AM

Hi Vitaly,

Thank you for the provided information!

I have reused the provided code to create a runnable sample to test the behavior. I have bound the Grid to a dummy data source just to be able to test the setup. On my side, the exporting is working as expected and the Location column is also included.

I have attached the sample project for your reference. To be able to run and test the sample, add the Telerik.Web.UI.dll to the bin folder of the project. Please try to modify it in a way it replicates the problem and then share the changes so we can be able to experience and investigate the issue locally.

One possible issue with the export is the call to the DataBind() method of the Grid. Please note that when NeedDataSource is used for binding the Grid you must not call the DataBind() method for the Grid, check out How to bind RadGrid properly on server-side.

Looking forward to your feedback.

Kind regards,
Doncho
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Vitaly
Top achievements
Rank 1
Iron
answered on 27 Oct 2022, 04:37 PM

Good Afternoon Doncho,

I would like to clarified some things.

I am getting data from Store Procedure and put that data into Session["dtGrid"].

location from this SP comes with 3 different columns: Distr ,Boro and School and i combined these columns in databound event:.

Please see below:

            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;
                string dist = ((DataRowView)e.Item.DataItem)["DISTR"].ToString().Trim();
                string boro = ((DataRowView)e.Item.DataItem)["BORO"].ToString().Trim();
                string school = ((DataRowView)e.Item.DataItem)["SCHOOL"].ToString().Trim();
                item["LOC"].Text = dist + boro + school;

Also when I export datagrid to PDF working fine and i am getting location in PDF form.

Please advise.

Thank you so much.

Vitaly.

Doncho
Telerik team
commented on 01 Nov 2022, 11:40 AM

Hi Vitaly,

Unlike the other supported Formats, the ExcelML export functionality builds the output directly from the DataSource but not from What is loaded and rendered in the RadGrid, check out the Excel-ExcelML (XLS) Export article for more details on this matter. With this in mind, setting the Text property of a GridCell (item["LOC"].Text = dist + boro + school;) is not considered in the exported file.

Instead, you should make sure that each column that should be present in the Export is an actual field of the DataSource bound to the RadGrid. Alternatively, you can test exporting to the default Html based export format: <Excel  Format="Html"/>.

This is also the reason why the proper binding technique is crucial for the proper functioning of the excel exporting feature.

I hope you will find this information helpful.

In case further assistance is needed, please do not hesitate to open a formal support ticket with us where you can provide us a runnable sample with the problem and we can investigate the specific scenario in detail.

0
Vitaly
Top achievements
Rank 1
Iron
answered on 01 Nov 2022, 02:13 PM

Good morning and thank you for you quick respond.

I checked data source and location there is consist of 3 columns district, boro and school. Maybe this causing the problem?

However, the same Datasource using in PDF export but PDF showing the location.

Please advise.

Thanks.

Vitaly.

Tags
General Discussions
Asked by
Vitaly
Top achievements
Rank 1
Iron
Answers by
Doncho
Telerik team
Vitaly
Top achievements
Rank 1
Iron
Share this question
or