RadGrid Export to excel issue

4 posts, 0 answers
  1. Benjamin
    Benjamin avatar
    51 posts
    Member since:
    Jul 2016

    Posted 26 Jul Link to this post

    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.}

  2. Benjamin
    Benjamin avatar
    51 posts
    Member since:
    Jul 2016

    Posted 26 Jul in reply to Benjamin Link to this post

    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 

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Benjamin
    Benjamin avatar
    51 posts
    Member since:
    Jul 2016

    Posted 26 Jul in reply to Benjamin Link to this post

    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
  5. Benjamin
    Benjamin avatar
    51 posts
    Member since:
    Jul 2016

    Posted 26 Jul in reply to Benjamin Link to this post

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

    should any need help refer to here

Back to Top