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文件没有问题