1

I am using kendo grid in my ember app. i have to hide the first and last column in export to Excel and I have to modify the column width in the Excel sheet.

How to hide the object from the array?

Here is my code:

excelExport : function(e) {
     e.preventDefault();
     var str = e.sender.columns;
     var sheet = e.workbook.sheets[0];
     var tindex = str.map(function(d) { return d['title']; }).indexOf('Action');
     var dindex = str.map(function(d) { return d['field']; }).indexOf('documentKey');

     sheet.columns.removeObject(dindex);sheet.columns.removeObject(tindex);

     var excelSheetColumns = sheet.columns.filter(function(d){
     console.log(">>>>>>"+d);    
     //d.removeObject(tindex);
     //d.removeObject(dindex);            

     d.width = 50;
     return d;
});

var workbook = new kendo.ooxml.Workbook({
    sheets:e.workbook.sheets
});

kendo.saveAs({
    dataURI: workbook.toDataURL(),
    fileName:"export.xlsx"
});
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ALICE
  • 93
  • 2
  • 9

1 Answers1

2

Try this:

var excelSheetColumns=sheet.columns.slice(2);
excelSheetColumns.forEach(function(col){col.width=50;});
var workbook = new kendo.ooxml.Workbook({
  sheets:excelSheetColumns
});
ykaragol
  • 6,139
  • 3
  • 29
  • 56
  • not working..how u will hide the first coloumn from theexcel sheet?? – ALICE Jul 06 '17 at 09:58
  • By using `excelSheetColumns`. I've updated the answer. – ykaragol Jul 06 '17 at 11:05
  • this is working but i need to remove 1st coloumn and last column from my excelsheet. All together i have 9 coloumn. – ALICE Jul 06 '17 at 18:15
  • `var excelSheetColumns=sheet.columns.slice(1);` removes first element. `excelSheetColumns.pop();` removes last element. Have a look at [this question](https://stackoverflow.com/questions/4644139/to-remove-first-and-last-element-in-array) – ykaragol Jul 06 '17 at 20:42
  • not working.. while downloading i am getting an empty worksheet – ALICE Jul 07 '17 at 07:08