How Convert Json string to Excel in Xamarin Forms

AsVAsV USMember ✭✭✭
edited September 2018 in Xamarin.Forms

Hi ,I am trying to convert Json data to Excel in xamarin forms for that I am trying like

        using (var client = new HttpClient())
        using (var formData = new MultipartFormDataContent())
        {
            var fileFormat = "xlsx";
            formData.Add(new StringContent("TestDocument"), "FileName");
            formData.Add(new StringContent(fileFormat), "FileFormat");
            formData.Add(new StringContent(JsonConvert.SerializeObject(jsonData)), "Data");
            //Call WebAPI to get Excel  
            var response = client.PostAsync("http://demos.componentone.com/ASPNET/C1WebAPIService/api/excel", formData).Result;
            if (!response.IsSuccessStatusCode)
            {
                DisplayAlert("Error!", "", "Ok");
                return;
            }
            var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            //Save Excel to Tem directory.  
            var tempFilePath = Path.Combine(tempPath, string.Format("{0}.{1}", "Test", fileFormat));
            string newFileName = string.Empty;
            using (var newFile = File.Create(tempFilePath))
            {
                response.Content.ReadAsStreamAsync().Result.CopyTo(newFile);
                newFileName = newFile.Name;
            }
            Task.Delay(1000);
            Process.Start(newFileName);
        }

It is converting Json to excel with no data.What I am doing wrong or is there any new way to covert can anyone help me for this?

Sign In or Register to comment.