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

Export to Excel but keeping styles

1 Answer 372 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ezequiel
Top achievements
Rank 2
Ezequiel asked on 12 Aug 2015, 07:48 PM

Hi, I have a grid that I recently upgraded from old Telerik MVC Extensions.

before, the user could select, copy and paste to excel and the styles were keep in Excel.

 Now, I'm adding a button to Export to Excel, but styling is not exported.

 Is there a way to do that?

 

@(Html.Kendo().Grid<ShowNumber>().Name("GridNumber")
.ToolBar(bar => bar.Excel().Text(Shared.buttonExportExcel))

.DataSource(ds => ds.Ajax().Read(read => read.Action("ReadNumber", "QueryNumbers").Data("getFilter")) ​

.Columns(columns =>{
columns.Bound(c => c.Description);
columns.Bound(c => c.Initial);
columns.Bound(c => c.Final);
})
.Events(ev => ev.DataBound("volumeDataBound")))

and this is my javascript for changing styles:

function volumeDataBound(e)
{
    var grid = this;
    var currentRecords = grid.dataSource.view();
 
    for (var i = 0; i < currentRecords.length; i++) {
        //currentRecords[i] is the current dataItem
        var item = currentRecords[i];
        if(item.DataCorrida==null || item.DataCorrida == '') {
            var tr = grid.tbody.find("[data-uid='" + item.uid + "']");
            tr.find("td.k-hierarchy-cell .k-icon").removeClass();
        }
        if (item.IsShipped) {
            grid.tbody.find("tr[data-uid='" + item.uid + "']").addClass("shipped-row");
        }
        else if(item.IsRemoved){
            grid.tbody.find("tr[data-uid='" + item.uid + "']").addClass("removed-row");
        }
        else{
            grid.tbody.find("tr[data-uid='" + item.uid + "']").addClass("regular-row");
        }
    }
}

Also, I'm not sure if this is the best way to change styles.

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 14 Aug 2015, 07:35 AM

Hello Ezequiel,

The currently used Kendo UI theme and custom styles are not included in the exported document. Custom styling could be manually applied by using the excelExport event of the Grid. For example - coloring the alternating rows. All cell properties that could be customized could be found at the following Workbook API documentation page.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Ezequiel
Top achievements
Rank 2
Answers by
Dimiter Madjarov
Telerik team
Share this question
or