filmov
tv
Get the JSON data from WEB API and save it into excel file | Part 14

Показать описание
Get the JSON data from WEB API and save it into excel file:
Here we can learn how to save the json data into Excel.
Need the client webAPI:
Method Name: Get
Now our aim to save the data into excel file.
Write a code to consume the data:
static void Main(string[] args)
{
Consume_WebAPI().Wait();
}
static async Task Consume_WebAPI()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/employee/list");
if (response.IsSuccessStatusCode)
{
dynamic result = await response.Content.ReadAsStringAsync();
DataTable dt = (DataTable)JsonConvert.DeserializeObject(result, (typeof(DataTable)));
Console.ReadKey();
}
}
Must Add name space using System.Drawing; and Microsoft.Office.Interop.Excel & System.Drawing.Common and Newtonsoft.Json from Nuget package
Add a class “UtlityClass” and make a function “Form_DataTable_To_Excel”
class UtlityClass
{
public bool Form_DataTable_To_Excel(DataTable Data_Table, string WorkSheet_Name, string Location_path, string ReporType)
{
// HERE NEED to write the code to save the data into excel sheet, for this , Please watch this video
}}
Here we can learn how to save the json data into Excel.
Need the client webAPI:
Method Name: Get
Now our aim to save the data into excel file.
Write a code to consume the data:
static void Main(string[] args)
{
Consume_WebAPI().Wait();
}
static async Task Consume_WebAPI()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/employee/list");
if (response.IsSuccessStatusCode)
{
dynamic result = await response.Content.ReadAsStringAsync();
DataTable dt = (DataTable)JsonConvert.DeserializeObject(result, (typeof(DataTable)));
Console.ReadKey();
}
}
Must Add name space using System.Drawing; and Microsoft.Office.Interop.Excel & System.Drawing.Common and Newtonsoft.Json from Nuget package
Add a class “UtlityClass” and make a function “Form_DataTable_To_Excel”
class UtlityClass
{
public bool Form_DataTable_To_Excel(DataTable Data_Table, string WorkSheet_Name, string Location_path, string ReporType)
{
// HERE NEED to write the code to save the data into excel sheet, for this , Please watch this video
}}
Комментарии