Services / Excel Services / Import Service / Import Excel into FlexGrid
Import Excel into FlexGrid

This section shows how to call the Web API service project through client application and add import function to enable importing Excel data into FlexGrid control.

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.
  2. Add import functionality, using Client JavaScript Helper, which will be triggered on button click event.
    Add the following code to Views|MVCFlexGrid|Index.cshtml to import excel data into FlexGrid control.
    Index.cshtml
    Copy Code
    <script type="text/javascript">
        var gridcontrol;
        c1.mvc.Utils.documentReady(function () {
            gridcontrol = wijmo.Control.getControl('#flexGrid')
        });
        function importFlex() {
        var file = document.getElementById("fileInput").files[0];
        var importer = new wijmo.grid.ExcelImporter();
        importer.requestImport(gridcontrol,
        "http://demos.componentone.com/ASPNET/C1WebAPIService/api/import/excel", file, true)
        }
    </script>
    
                   
  3. Provide an input control, for example button, to initiate import request in client application.
    • 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 import functionality.

    Index.cshtml
    Copy Code
    <div>
        <span>Import</span>
        <input type="file" value="Import" id="fileInput" class="upload" onchange="importFlex()" />
    </div>
    

Back to Top

Step 2: Run the Client Project

MVC Application

HTML Application

A button to select file to be imported appears along with the control, in the output. Use this button to import data from the desired file into the control.

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

Back to Top