[]
This section demonstrates how to call the Web API service through a client application to convert the excel file available in storage (remote storage or storage at the same server) to a different file format.
Step 2: Run the Client Project
The following example makes a call to the Web API service through HTML as well as WinForms client applications. These clients send a GET request to the service, which returns a response stream. This response stream is then saved in the desired excel file format.
In the following example, the service URL takes name and location of excel workbook (present in storage) in WorkBookFileName parameter and the desired file format, json, in Type parameter. The specified excel workbook, results.xlsx, resides in root folder of the hosted service.
Complete the following steps to call the Web API service.
csharp
public void ConvertExcel() {
var apiURL = string.IsNullOrEmpty(C1TextBox1.Text) ? "https://demos.componentone.com/ASPNET/5/C1WebAPI/3.0.20193.222/api/excel?FileName=excel&type=json&workbookfilename=ExcelRoot%2FGrouping.xlsx" : C1TextBox1.Text;
WebRequest request = WebRequest.Create(apiURL);
WebResponse response = request.GetResponse();
var fileStream = File.Create("D:\\ExcelConvert.json");
response.GetResponseStream().CopyTo(fileStream);
}
<form action="https://developer.mescius.com/componentone/demos/aspnet/c1WebAPI/latest/api/excel" method="GET">
<label for="fileName">File Name:</label>
<input type="text" id="fileName" name="fileName" value="ExcelConvert" />
<br />
<label for="fileFormat">File Format:</label>
<input type="text" id="fileFormat" name="type" value="json" />
<br />
<label for="WorkBookFileName">WorkBook File Name:</label>
<input type="text" id="WorkBookFileName" name="WorkBookFileName" value="root/Grouping.xlsx" />
<input type="submit" value="Convert Excel Format"/>
</form>
WinForms Application
HTML Application
type=note
Explore detailed demo samples of REST API service to convert workbook formats at: