Services / Excel Services / Generate Excel Service / Generate Excel from Data Sources in Storage
Generate Excel from Data Sources in Storage

This section demonstrates how to call the Web API service through a client application and generate excel file from dataset or .NET collection present in storage (remote storage or storage at the same server).

Step 1: Call the Service

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 dataset/ collection (present in storage) in DataName parameter and the desired file format, xls, in Type parameter. The specified dataset, named Products, resides in Nwind folder of the hosted service.

Step 1: Call the Service

Complete the following steps to call the Web API service.

  1. Create a WinForms application, as discussed in Configure Client for REST API service. Add one C1Label, one C1TextBox and one C1Button control. Your form will appear as shown below.
  2. Define a method (for example: GetExcel()) in form class of your WinForms application, to call the service application, as shown below.
    C#
    Copy Code
    public void GetExcel() {
      var apiURL = string.IsNullOrEmpty(C1TextBox1.Text) ? "https://developer.mescius.com/componentone/demos/aspnet/c1WebAPI/latest/api/excel?
      FileName = excel & type = xls & dataname = Nwind % 2 FProducts " : C1TextBox1.Text;
      WebRequest request = WebRequest.Create(apiURL);
      WebResponse response = request.GetResponse();
      var fileStream = File.Create("D:\\ExcelfromStorage.xls"); 
      //The file format specified here should be same as that specified in the
      request url
      response.GetResponseStream().CopyTo(fileStream);
    }
    
  3. Call the GetExcel() method on button-click event of Generate Excel button.

Back to Top

Step 2: Run the Client Project

WinForms Application

HTML Application

Explore detailed demo samples of REST API service to generate excel from data sources available in storage at:

Back to Top