The C1Studio Web API Edition is a set of APIs that enable exporting of FlexChart and Gauges to images, and import and export of Excel sheets with FlexGrid. The APIs are available as Visual Studio templates with support for Web API 2.2 and a beta support for Web API 3.0 (next update for web api 3.0 is scheduled for September 2015). Let's walk through an example of creating a Web API that uses the C1Studio Web APIs. Later we'll demonstrate how to consume this Web API to export Excel sheets from FlexGrid in a client application.
Create a new Project inside Visual Studio using "C1 Web API Application Hosted in IIS" template. This automatically adds the necessary libraries and license information to the project. I've named the project "C1WebAPIService":
Observe the references—files that are added to the service project.
The project has references to C1.Web.API & C1.C1Excel libraries. It also has a license.licx file that has license information.
Deploy the project to IIS.
These Web APIs can be consumed by any ASP.NET MVC or Javascript application that use ComponentOne Studio FlexGrid, FlexChart & Gauge controls. In this example, we'll export a sales report to Excel sheet from an ASP.NET MVC project.
Add a reference for the above file to _Layout.cs file under head tags.
Add a button to the View that calls a javascript function "exportExcel" to export the sales report data inside FlexGrid to Excel.
<script><br/> function exportExcel() {<br/> var exporter = new c1.mvc.grid.ExcelExporter();<br/> var grid = wijmo.Control.getControl("#Sales");<br/> exporter.requestExport(grid, "http://localhost/c1webapiservice/api/export/Excel", {<br/> fileName: "salesReport",<br/> type: wijmo.ExportFileType.Xlsx,<br/> includeColumnHeader:true<br/> });<br/></script>
The "webapiclient" has a "ExcelExporter" class that uses the "requestExport" method to export to Excel. This method takes various parameters:
Run the application and click on exportExcel button. You'll observe that the exported file persists the grouping and cell formatting applied to FlexGrid. You can download the client sample from SalesReport.
You can refer to WebAPIExplorer sample to see various export\import options for different controls. This release of Web API Edition is a preview release. Stay tuned for some power packed features and Rest APIs scheduled for 2015 V3 release.