This is a migrated thread and some comments may be shown as answers.
Excel Export - Adding text and functions
4 Answers 60 Views
This is a migrated thread and some comments may be shown as answers.
Mario
Top achievements
Rank 1
Mario asked on 09 Oct 2009, 06:03 PM
 

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

4 Answers, 1 is accepted

Sort by
0
Mario
Top achievements
Rank 1
answered on 13 Oct 2009, 06:48 PM
Any response yet?

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

Tks :)
0
Daniel
Telerik team
answered on 21 Oct 2009, 01:39 PM
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.
0
Vasssek
Top achievements
Rank 1
answered on 14 Jan 2020, 06:15 PM

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.

0
Attila Antal
Telerik team
answered on 17 Jan 2020, 02:00 PM

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.
Tags
Grid
Asked by
Mario
Top achievements
Rank 1
Answers by
Mario
Top achievements
Rank 1
Daniel
Telerik team
Vasssek
Top achievements
Rank 1
Attila Antal
Telerik team
Share this question
or