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

[Solved] Export to excel

7 Answers 370 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vincent Girard
Top achievements
Rank 1
Vincent Girard asked on 18 Feb 2010, 09:03 PM
Hello,

Is it possible to export the grid's data to excel? Just like with the .net AJAX Grid : http://www.telerik.com/products/aspnet-ajax/grid.aspx#exporting-data Do you know if it will be in later release?

Thx a lot!

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 Feb 2010, 08:02 AM
Hi Vincent Girard,

Currently built-in export to Excel capabilities are not in our plans. However it is rather easy to implement export to CSV format using the grid data. You can check this forum thread for a working example. If XLS or XLSX format is required perhaps this blog post would help.

I hope this helps,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Accepted
Atanas Korchev
Telerik team
answered on 19 Feb 2010, 01:25 PM
Hello,

I've just created a KB article how to export the data of the grid in Excel XLS format. You can find the KB here. It is built against the newly released Q1 2010 futures.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Vincent Girard
Top achievements
Rank 1
answered on 19 Feb 2010, 01:50 PM
Thanks a lot for the quik reply! I will check this out today. Do you know if it will work with the last release (2009.3.1223) or it will be only with q1 beta?

You guys rock! I love to use your product for 3 years now! And with MVC open source it's even better!!
0
Atanas Korchev
Telerik team
answered on 19 Feb 2010, 01:58 PM
Hello Vincent Girard,

The sample is made for the futures release 2010.1.218 and will require some modification to work with older versions:

VIEW:
<%= Html.ActionLink("Export to Excel", "Export", new { page = 1, orderBy = "~", filter = "~"}, new { id = "exportLink" }) %>
 
<script type="text/javascript">
    function onDataBound() {
        var grid = $(this).data('tGrid');
        var $exportLink = $('#exportLink');
        var href = $exportLink.attr('href');
        href = href.replace(/page=([^&]*)/, 'page=' + grid.currentPage);
        href = href.replace(/orderBy=([^&]*)/, 'orderBy=' + (grid.orderBy || '~'));
        href = href.replace(/filter=(.*)/, 'filter=' + (grid.filterExpression || '~'));
        $exportLink.attr('href', href);
    }
</script>
     
<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(o => o.OrderID);
            columns.Bound(o => o.ShipAddress);
            columns.Bound(o => o.CustomerID);
            columns.Bound(o => o.ShipCountry);
            columns.Bound(o => o.OrderDate);
        })
        .Pageable()
        .Sortable()
        .Filterable()
        .Ajax( ajax => ajax.Action("IndexAjax", "Home"))
        .ClientEvents(events => events.OnDataBinding("onDataBound"))
%>
Controller:
public ActionResult Export(int page, string orderBy, string filter)
{
    //Get the data representing the current grid state - page, sort and filter
    GridModel model = Model().ToGridModel(page, 10, orderBy, filter);
    var orders = model.Data.Cast<Order>();


Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Vincent Girard
Top achievements
Rank 1
answered on 19 Feb 2010, 09:27 PM
I'm probably doing something wrong here because my Action of the controller get call when the page load, is it normal?

Ok found my problem, it was my error on a link with T4MVC.

Thanks a lot for the help here it works like a charm!

Have a nice weekend!
0
Vincent Girard
Top achievements
Rank 1
answered on 19 Feb 2010, 09:47 PM
One last thing, just so I know, where are the NPOI assemblies comming from?
0
Alex Gyoshev
Telerik team
answered on 22 Feb 2010, 08:19 AM
Hello Vincent,

The project homepage is linked in the KB - it is http://npoi.codeplex.com/.

Best wishes,
Alex Gyoshev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Vincent Girard
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Vincent Girard
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or