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

RadGrid Export to excel issue

3 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 27 Jul 2016, 02:50 AM

Hi. i am required to export the data from RadGrid into excel on Sharepoint 2013 custom webpart. i have the following issue

  1. the export file is empty. i.e the file does not have any workbook/worksheet being created
  2. i have a external xml with the excel setting and styling from ASP global resource. how can i add this in during export?

ascx markup

01.<telerik:RadGrid RenderMode="Lightweight" runat="server" ID="gridCourse" AllowPaging="True" AutoGenerateColumns="False" AllowSorting="true" PageSize="14"
02.        OnSortCommand="gridCourse_SortCommand" OnPageIndexChanged="gridCourse_PageIndexChanged" OnExcelMLExportRowCreated="gridCourse_ExcelMLExportRowCreated"
03.        OnPageSizeChanged="gridCourse_PageSizeChanged" AllowMultiRowSelection="true">
04.      <MasterTableView PagerStyle-Mode="NumericPages" PagerStyle-Position="TopAndBottom" PagerStyle-HorizontalAlign="Right" UseAllDataFields="true">
05.          <Columns>
06.                <telerik:GridTemplateColumn HeaderStyle-Font-Bold="true" SortExpression="id" UniqueName="id" HeaderText="Course ID" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
07.                    <ItemTemplate>
08.                   <asp:HyperLink ID="lnkId" runat="server" NavigateUrl='<%# string.Format(manageCourseURL, HttpUtility.UrlEncode(Eval("id").ToString())) %>' Text='<%# Eval("id") %>'></asp:HyperLink>
09.                <asp:Label runat="server" ID="lblCourseId" Visible="false" Text='<%# Eval("id") %>'></asp:Label>
10.               </ItemTemplate>
11.                </telerik:GridTemplateColumn>
12.                <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" UniqueName="courseCode" ItemStyle-Width="150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
13.                    SortExpression="courseCode" HeaderText="Course Code" DataField="courseCode">
14.                </telerik:GridBoundColumn>
15.              <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" UniqueName="courseTitle" ItemStyle-Width = "250" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
16.                    SortExpression="courseTitle" HeaderText="Course Title" DataField="courseTitle">
17.                </telerik:GridBoundColumn>
18.              <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" UniqueName="courseType" ItemStyle-Width = "150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
19.                    SortExpression="courseType" HeaderText="Course Type" DataField="courseType">
20.                </telerik:GridBoundColumn>
21.              <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" UniqueName="courseTemplate" ItemStyle-Width = "150" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
22.                    SortExpression="courseTemplate" HeaderText="Course Template" DataField="courseTemplate">
23.                </telerik:GridBoundColumn>
24.              <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" UniqueName="duration" ItemStyle-Width = "80" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
25.                    SortExpression="duration" HeaderText="Duration" DataField="duration">
26.                </telerik:GridBoundColumn>
27.              <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" UniqueName="status" ItemStyle-Width = "60" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
28.                    SortExpression="status" HeaderText="Status" DataField="status">
29.                </telerik:GridBoundColumn>
30.               <telerik:GridBoundColumn HeaderStyle-Font-Bold="true" UniqueName="modifiedDate" ItemStyle-Width = "200" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
31.                    SortExpression="modifiedDate" HeaderText="Last Modified Date" DataField="modifiedDate" DataFormatString="{0:d MMMM yyyy hh:mm tt}" htmlencode="false">
32.                </telerik:GridBoundColumn>
33.              <telerik:GridClientSelectColumn UniqueName="chkCell" ItemStyle-Width="10">
34.                </telerik:GridClientSelectColumn>
35.          </Columns>
36.      </MasterTableView>
37.        <ClientSettings>
38.            <Selecting AllowRowSelect="true"></Selecting>
39.        </ClientSettings>
40.        </telerik:RadGrid>

 

code behind

01.protected void btnExport_Click(object sender, EventArgs e)
02.{
03.    gridCourse.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
04.    gridCourse.ExportSettings.ExportOnlyData = true;
05.    gridCourse.ExportSettings.IgnorePaging = true;
06.    gridCourse.ExportSettings.OpenInNewWindow = true;
07.    gridCourse.ExportSettings.FileName = export.getResourceString("litExportFilename");
08.    gridCourse.ExportToExcel();
09.}
10. 
11.protected void gridCourse_ExcelMLExportRowCreated(object sender, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)
12.{
13.   e.Worksheet.Name = export.getResourceString("litExcelDefaultWorksheetName");
14.}

3 Answers, 1 is accepted

Sort by
0
Benjamin
Top achievements
Rank 1
answered on 27 Jul 2016, 03:18 AM

Hi. i have solve my 1st issue by using onneeddatasource. 

need help on the 2nd issue to set the export setting to use the external xml setting and styling 

0
Benjamin
Top achievements
Rank 1
answered on 27 Jul 2016, 03:43 AM
hi i found that this is able to handle my issue #2. but after using the excel file became empty again. even the demo excel file is also empty excel file for the HTML one
0
Benjamin
Top achievements
Rank 1
answered on 27 Jul 2016, 04:41 AM

hi. i fixed the issue. it seems to be microsoft issue.

should any need help refer to here

Tags
Grid
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Benjamin
Top achievements
Rank 1
Share this question
or