Saturday, March 8, 2014

How to use Export Excel in DHTMLX Grid

1. In order to use export  to excel in dhtmlgrid. We  need to  download( and add the following two library reference to the project.

                  1. DHTMLX.Export.Excel

                  2.  Openxml

2. Need to include “dhtmlxgrid_export.js” script file reference from the following location “../codebase/ext/” directory to  your web page.

3. Use “toExcel” function with your dhtmlgrid. Which will expects serverside controller action url. In this action we need to define logic to download dhtmlgrid to excel.


Sample Code:



Client Side Code:



Server Side Code:


ExcelTest Contoller:


Need to include “DHTMLX.Export.Excel” namespace to the controller.


using DHTMLX.Export.Excel;


        public ActionResult ExportGridToExcel()


            var generator = new ExcelWriter();

            var xml = this.Request.Form["grid_xml"];

            xml = this.Server.UrlDecode(xml);

            var stream = generator.Generate(xml);

            return File(stream.ToArray(), generator.ContentType, "grid.xlsx");



In the “grid_xml”. “grid_” will be ghtmlgrid name.