Services > Excel Services > Export Service > 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 2: Run the Client Project
The following image shows how the FlexGrid appears after completing the steps above:
Complete the following steps to call the Web API service.
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> |
JavaScript |
Copy Code
|
---|---|
<script type="text/javascript"> function exportFlex() { var exporter = new wijmo.grid.ExcelExporter(); var grid = wijmo.Control.getControl("#TheFlexGrid"); exporter.requestExport(grid, "http://demos.componentone.com/ASPNET/WebAPI/api/export/excel", { fileName: "export", type: wijmo.ExportFileType.Xls, }); } </script> |
Note: To use Wijmo 5 controls in your HTML application, you need to include references to few Wijmo files in your HTML pages. You may either download these wijmo files and copy them to appropriate folders in your application, or reference Wijmo files hosted in cloud on our Content Delivery Network (CDN). If you download and place the Wijmo script files in a folder named "Scripts", css files in a folder named "Styles", and script files specific to Wijmo controls to "Controls" folder, then add the following references within <head> tags of your HTML pages:
|
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> |
Add the following markup within the <body> tags to create button for export function.
HTML |
Copy Code
|
---|---|
<button onclick="exportFlex()" title="Export">Export</button> |
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: |