not able to save data into excel file

204 Views Asked by At
using (ExcelPackage package = 
new ExcelPackage(new FileInfo("jsonToExcel.xlsx")))            
{
    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("abc");   
    using (StreamReader reader = new StreamReader(jsonFileName))
    {

        string json = reader.ReadToEnd();

        dynamic array = JsonConvert.DeserializeObject(json);
        int pos = 1;
        foreach (var item in array["columns"])
        {
            worksheet.Cells[1, pos].Value = item["title"];
            pos+=1;
        }
        int Row = 2;

        foreach(var item in array["dataTable"]["itemList"])
        {
            pos = 1;
            worksheet.Cells[Row, pos++].Value = item["itemName"];
            worksheet.Cells[Row, pos++].Value = item["Total"];
            worksheet.Cells[Row, pos++].Value = item["91-150 days"];
            worksheet.Cells[Row, pos++].Value = item["211+ days"];
            worksheet.Cells[Row, pos++].Value = item["151-210 days"];
            worksheet.Cells[Row, pos++].Value = item["0-30 days"];
            Row += 1;
        }
    }
    package.Save();
}

Nothing is getting stored in excel file "jsonToExcel". I am using ExcelPackage for storing the contents in the excel file and there is no problem with the json file

0

There are 0 best solutions below