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

preview_player
Показать описание
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

}}
Рекомендации по теме
Комментарии
Автор

Hi Syed Ali, the video Was great enough. i might appreciate more! I am using the ready-made API tool of Sheet Best which is easy enough for me to connect, edit or anything like that. that's why I won't try to create API for excel file though coding!

tonmoitanvi
Автор

Hi Syed, you've done a good job. Well done. Could you please post the remaining source code in the description. Thank you.

kwadwoasante
Автор

Sir I am working on a Maven Project with MongoDB database

rajkumarbaishya
Автор

Hey Syed, great work mate. Could you please post the entire source code in the comments or send me the link of the source. Your help will be truly appreciated.

himanshumetai
visit shbcf.ru