Hello,
I'm using this code in my grid:
.ToolBar(tools => tools.Excel())
.Excel(excel => excel
.FileName("Ci_view.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("ExportExcelSave", "Ci"))
.AllPages(true)
My question is; how can I exclude some columns from my Excel?
Thanks!!
11 Answers, 1 is accepted
Possible solution is to hide the columns you want to exclude when the excelExport event is fired. The following code block illustrates how to hide a column before the export and then show it back after the export is done:
var
exportFlag =
false
;
$(
"#grid"
).data(
"kendoGrid"
).bind(
"excelExport"
,
function
(e) {
if
(!exportFlag) {
e.sender.hideColumn(1);
// index of the column you want to exclude
e.preventDefault();
exportFlag =
true
;
setTimeout(
function
() {
e.sender.saveAsExcel();
});
}
else
{
e.sender.showColumn(1);
exportFlag =
false
;
}
});
Please give it a try and let me know if it works for you.
Regards,
Georgi
Progress Telerik

Currently the only solution in order to exclude certain column from the exported document is to hide it.
If you would like to request the feature to be included out of the box for the Kendo Grid I can suggest submitting a request in our UserVoice portal. This way the users can vote for the feature. Based on the traction the request gathers with the community the developers will consider implementing it in a future release.
Regards,
Georgi
Progress Telerik


[quote]Jamie said:Hi, I added the functionality given and now the workbook is getting renamed to export.xlsx, any idea why the code provided here would change the name of my document? It was named MembersList.xlsx before that code was added.[/quote]
Nevermind, it works on the live environment, just not staging. Not a dealbreaker. Disregard post. I wish I could delete it lol!

Not exactly useful.
This code hides the column when the user clicks the "Export as Excel" but doesn't show it after the excel export completes.
So the user must click again on the "Export as Excel" button.
There should be another event handler to show the column again.

Something like this should be implemented:
e.sender.saveAsPDF().then(
function
(){
e.sender.showColumn(1);
exportFlag =
false
;
});
Hello Daniel,
The column is hidden before the export but then after the export, the column is shown back. Please take a look in the else clause.
var exportFlag = false;
$("#grid").data("kendoGrid").bind("excelExport", function (e) {
if (!exportFlag) {
e.sender.hideColumn(1); // index of the column you want to exclude
e.preventDefault();
exportFlag = true;
setTimeout(function () {
e.sender.saveAsExcel();
});
} else {
e.sender.showColumn(1);
exportFlag = false;
}
});
For better understanding, please refer to the following sample:
Note that the second column is not present in the exported file, but still the column is visible after the export.
Regards,
Georgi
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Right,
Maybe I should explain my case. I don't use the toolbar button to trigger the export to excel, but a different button:
$("#export-to-excel").on("click", function(e) {
grid.saveAsExcel();
});
So the export starts, but then e.sender.saveAsExcel(); triggers the export once again.
And in my case, it means a second call to the server, to get the data.
Which is not a good idea, because some customers have a lot of records to export.
So I need to trigger the excelExport event only once.
Hi Daniel,
Then you could hide the column within the click handler of the button which exports the grid. I have modified the dojo to demonstrate the same:
Regards,
Georgi
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Great! That solves the problem.
Thank you!