[]
        
(Showing Draft Content)

Generate Excel from XML Posted from Client

This section demonstrates how to call the Web API service through a client application and generate excel from XML data file, posted from client.

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 POST 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, user provides XML data file through the client applications. Moreover, the end user needs to specify the service URL, name and appropriate file format of generated excel file through client project. It is so, because the parameters or query string for generating excel are sent in the HTTP message body of the POST request and not in the request URL.

Step 1: Call the Service

Complete the following steps to call the Web API service.

csharpC#

private void button1_Click(object sender, EventArgs e) {
  var result = openFileDialog1.ShowDialog();
  if (result == DialogResult.OK || result == DialogResult.Yes) {
    _filePath = openFileDialog1.FileName;
    if (!string.IsNullOrEmpty(_filePath)) {
      label1.Text = _filePath;
    }
  }
}

HTML

<form action="https://demos.componentone.com/ASPNET/5/C1WebAPI/3.0.20193.222/api/excel" method="POST" enctype="multipart/form-data">
        <label for="dataFile">Xml data file:</label>
        <input type="file" id="dataFile" name="dataFile" accept=".xml" />
        <br/><br/>
        <label for="fileName">File Name:</label>
        <input type="text" id="fileName" name="fileName" value="test"/>
        <br /><br />
        <label for="fileFormat">File Format:</label>
        <input type="text" id="fileFormat" name="type" value="xlsx" />
        <br /><br />
        <input type="submit" value="POST"/>
</form>

Step 2: Run the Client Project

WinForms Application

HTML Application

  • Save your HTML file and open it in a browser.
  • Select and post XML data file.
  • Set name and appropriate file format for generated excel, and click Generate Excel button.

type=note

Explore detailed demo samples of REST API service to generate excel from XML data file at: