サイトがありASP.Net
ます。以下は、ストリームをExcelに書き込む私の方法です。
public void JsonToExcel(string jsonData, HttpResponseBase response)
{
try
{
ExcelPackage excel = new ExcelPackage();
var worksheet = excel.Workbook.Worksheets.Add("Sheet1");
//below line is throwing the error
worksheet.Cells[1, 1].LoadFromCollection(jsonData, true);
using (MemoryStream swObj = new MemoryStream())
{
string fileName = DateTime.Now.ToLongDateString() + ".xlsx";
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AddHeader("content-disposition", "attachment; filename=" + fileName + "");
excel.SaveAs(swObj);
swObj.WriteTo(response.OutputStream);
return;
}
}
catch (Exception ex)
{
//handle exception
return;
}
finally
{
response.Flush();
response.End();
}
関数のこの行で -worksheet.Cells[1, 1].LoadFromCollection(jsonData, true);
次の例外が発生しています
インデックスが配列の範囲外だった
に設定してみましたworksheet.Cells[0,0]
EPPlus 4.1.0パッケージを使用しています。
JSON サンプル :-
string jsonData = @"jsonData = [
{
""DocumentName"": ""Test Document"",
""ActionDate"": ""2015-09-25T16:06:25.083"",
""ActionType"": ""View"",
""ActionPerformedBy"": ""Sreeja SJ""
},
{
""DocumentName"": ""Test Document"",
""ActionDate"": ""2015-09-25T16:12:02.497"",
""ActionType"": ""View"",
""ActionPerformedBy"": ""Sreeja SJ""
},
{
""DocumentName"": ""Test Document"",
""ActionDate"": ""2015-09-25T16:13:48.013"",
""ActionType"": ""View"",
""ActionPerformedBy"": ""Sreeja SJ""
}]";