public IActionResult Execl() { var excelCarrier = new ExcelMapper(@"C:\Temp\CarrierPhone.xlsx").Fetch <Carrier>(); var count = excelCarrier.Count(); List <Carrier> lCarriers = new List <Carrier>(); var webClient = new System.Net.WebClient(); string json = string.Empty; foreach (var item in excelCarrier) { json = webClient.DownloadString("http://www.carrierlookup.com/index.php/api/lookup?key=bda67624bc1026d9f1f83c98faca2d363e5be4f9&number=" + item.number); var carrier = JsonConvert.DeserializeObject <Carrier>(json); lCarriers.Add(carrier); } //List<Carrier> lCarriers = new List<Carrier>(); //string access_key = "62280dd7ba2060067dfde424c9ac5c78"; //string number = "18099659415"; //string country_code = "+13463318984"; //string format = "1"; //string url = "http://apilayer.net/api/validate?"; //strGet = "http://apilayer.net/api/validate?access_key=62280dd7ba2060067dfde424c9ac5c78&number=18099659415&country_code=&format=1"; //string strGet = url + "access_key=" + access_key + "&number=" + number + "&country_code=" + "&format=" + format; //var webClient = new System.Net.WebClient(); //string json = webClient.DownloadString(strGet); //var carrier = JsonConvert.DeserializeObject<Carrier>(json); //lCarriers.Add(carrier); using (var workbook = new XLWorkbook()) { var worksheet = workbook.Worksheets.Add("Phone Carrier"); var currentRow = 1; worksheet.Cell(currentRow, 1).Value = "Phone"; worksheet.Cell(currentRow, 2).Value = "Country"; worksheet.Cell(currentRow, 3).Value = "Carrier"; worksheet.Cell(currentRow, 4).Value = "Line Type"; foreach (Carrier item in lCarriers) { currentRow++; worksheet.Cell(currentRow, 1).Value = item.number; worksheet.Cell(currentRow, 2).Value = item.country_name; worksheet.Cell(currentRow, 3).Value = item.carrier; worksheet.Cell(currentRow, 4).Value = item.line_type; } using (var stream = new MemoryStream()) { workbook.SaveAs(stream); var content = stream.ToArray(); return(File(content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "CarrierPhoneInfo.xlsx")); } } }