We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Hide Column header on Excel Export

Hi, I'd like to hide column header from all columns during Excel Export.


Thank you.


2 Replies 1 reply marked as answer

VB Vinitha Balasubramanian Syncfusion Team December 21, 2022 02:36 PM UTC

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


Marked as answer

PG Peter Groft January 9, 2023 04:46 AM UTC

  1. Click anywhere in the table.
  2. Go to Table Tools > Design on the Ribbon.
  3. In the Table Style Options group, select the Header Row check box to hide or display the table headers.
  4. If you rename the header rows and then turn off the header row, the original values you input will be retained if you turn the header row back on.
Regards,
Peter


Loader.
Live Chat Icon For mobile
Up arrow icon