Excel Export - Adding text and functions

5 posts, 0 answers
  1. Mario
    Mario avatar
    2 posts
    Member since:
    Mar 2008

    Posted 09 Oct 2009 Link to this post

     

    Good afternoon, I tried to export a radgrid to Excel with success using 

    Telerik.Web.UI.GridExcelExportFormat.ExcelML with ExportOnlyData/IgnorePaging/OpenInNewWindow all set to true. I have search for a couple of days a way to add content to the Excel sheet before adding the radgrid. I mean, I need to add some text to the Excel file and execute some macro on the Excel sheet. How can I do this? The radgrid is using Ajax.

     

    Any help would be most appreciated. Shoud a use an Excel template and feed the datagrid into it? By the way, I am using Excel 2007 but hope everything work's also in Excel 2003.

    I use the function ExcelMLExportRowCreated and ExcelMLExportStylesCreated to format the loook and feel of the columns with success.

     

     

    Thank's for your precious time :)

     

    Mario

  2. Mario
    Mario avatar
    2 posts
    Member since:
    Mar 2008

    Posted 13 Oct 2009 Link to this post

    Any response yet?

    Please let me know if I can help or redirect furter toward a solution...

    Tks :)
  3. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 21 Oct 2009 Link to this post

    Hello Mario,

    You can add custom text above RadGrid this way:
    protected void RadGrid1_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)
    {
        if (e.RowType == GridExportExcelMLRowType.HeaderRow)
        {
            RowElement newRow = new RowElement();
            CellElement newCell = new CellElement();
            int colsCount = RadGrid1.MasterTableView.AutoGeneratedColumns.Length;
            int itemsCount = RadGrid1.MasterTableView.Items.Count;
            newCell.Data.DataItem = "Test Test";
            newRow.Cells.Add(newCell);
            e.Worksheet.Table.Rows.Insert(0, newRow);
            e.Worksheet.AutoFilter.Range = "R2C1:R" + itemsCount + "C" + colsCount;
        }
    }

    I attached simple project to this post. Let me know if you need more information.

    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.
  4. Vasssek
    Vasssek avatar
    190 posts
    Member since:
    Aug 2010

    Posted 14 Jan 2020 in reply to Daniel Link to this post

    Hi,

    could you please provide code, how ot add sum formula when exporting to xlsx format. I suppose it should be done in InfrastructureExporting event.

    Thank you.

  5. Attila Antal
    Admin
    Attila Antal avatar
    590 posts

    Posted 17 Jan 2020 Link to this post

    Hi Vasssek,

    The ExportInfraStructure will allow you to get access to the output the Grid created but before passed to the Document Processing libraries to actually build the Excel file, see Export Infrastructure. "The Export Infrastructure is designed to be a middle tier structure that sits between an export library and server control."

    The Telerik Document Processing (TDP) libraries are the ones that you can use to interact with documents even creating formulas, see General Information - Formulas. For implementing formulas, you'll have to get the XLSX structure out of the Grid and process it further with the Telerik Document Processing (TDP) libraries. 

    We have RadGrid online demo where the XLSX output is extracted, then imported into the TDP libraries for further processing, see Grid - Export Multiple Grids. In this particular example, you will see that the output is extracted from each grid, and the TDP libraries are used to construct a document with as many Sheets in the same WorkBook as many Grids are extracted. In your case, however, you can get the output, implement the formula instructed in the TDP documentation and return it in the Response for downloading.

     

    See examples using the TDP libraries in different scenarios:

     

    Kind regards,
    Attila Antal
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
Back to Top