无法将数据保存到Excel文件中

时间:2018-09-28 10:08:23

标签: c# excel epplus excelpackage

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();
}

什么都没有存储在excel文件“ jsonToExcel”中。我正在使用ExcelPackage将内容存储在excel文件中,并且json文件没有问题

0 个答案:

没有答案