Services / Excel Services / Export Service / Export FlexGrid to Excel
Export FlexGrid to Excel

This section shows how to call the Web API service project through a client application and add export function for exporting FlexGrid data as an excel.

Step 1: Call the Service

Step 2: Run the Client Project

The following image shows how the FlexGrid appears after completing the steps above:

Step 1: Call the Service

Complete the following steps to call the Web API service.

  1. Add C1 Web API Client JavaScript file and its reference to your MVC or HTML project (For further details refer to C1 Web API Client JavaScript).
  2. Create a function, using Client JavaScript Helper, to implement the export functionality.
    Add the following code to Views|MVCFlexGrid|Index.cshtml to export FlexGrid data to excel.
    Index.cshtml
    Copy Code
    <script type="text/javascript">    
        function exportFlex() {
        var exporter = new c1.mvc.grid.ExcelExporter();
        fileType = document.getElementById("mySelect").value;
        var gridcontrol = wijmo.Control.getControl("#flexGrid");
        exporter.requestExport(gridcontrol,
        "http://demos.componentone.com/ASPNET/C1WebAPIService/api/export/excel", {
            fileName: "exportFlexGrid",
            type: fileType,
            });
        }
    </script>
    
  3. Add a button and call the export functionality on its button click for initiating export request.
    • Add the following code in Views | MVCFlexGrid | Index.cshtml to add buttons for export and import functionalities.

    Add the following code in Views | MVCFlexGrid | Index.cshtml to add buttons for export functionality.

    Index.cshtml
    Copy Code
    <div>
        <select id="mySelect">
            <option selected>Xls</option>
            <option>Xlsx</option>
            <option>Csv</option>
        </select> 
    <button onclick="exportFlex()" title="Export">Export</button>
    </div>
    

Back to Top

Step 2: Run the Client Project

MVC Application

HTML Application

Export button appears along with the control, in the output. Use this button to export the data in the control to Excel format.

Explore detailed demo samples of export service for MVC and Wijmo5 FlexGrid control in:

Back to Top