BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hi, I'd like to hide column header from all columns during Excel Export.
Thank you.
Hi Rodrigo,
Thank you for reaching out to Syncfusion support.
To customize the column headers when performing an excelExport action in the Grid component, you can use the excelHeaderQueryCellInfo event and the following code:.
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).AllowExcelExport().Columns(col => { col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).Width("120").Add(); col.Field("CustomerID").HeaderText("CustomerID").Width("120").Add(); col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").Add(); col.Field("ShipCity").HeaderText("ShipCity").Width("120").Add(); }).Created("created").ToolbarClick("toolbarClick").ExcelHeaderQueryCellInfo("excelHeaderQueryCellInfo").Toolbar(new List<string>() { "ExcelExport" }).Render())
<script> function toolbarClick(args) { var gridObj = document.getElementById("Grid").ej2_instances[0]; if (args.item.id === 'Grid_excelexport') { gridObj.excelExport(); } } // to customize the column header on excel exporting function excelHeaderQueryCellInfo(args) { args.cell.value = ''; }
// to remove the blank cell function created(args) { var gridObj = document.getElementById("Grid").ej2_instances[0]; var processGridExportObject = gridObj.excelExportModule.__proto__.processGridExport; gridObj.excelExportModule.__proto__.processGridExport = function ( gobj, props, r ) { var rows = processGridExportObject.call(this, gobj, props, r); rows.shift(); rows.forEach((item, index) => { item.index = index + 1; }); return rows; } } </script> |
For more information, you can refer to the API documentation at https://ej2.syncfusion.com/documentation/api/grid/#excelheaderquerycellinfo
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/excel_exporting-1646041417
Regards,
Vinitha Balasubramanian