Answer the question
In order to leave comments, you need to log in
How to generate Excel based on Json?
Good afternoon!
I'm a teapot, but I'm learning. The question arose: how to generate an Excel file based on Json in c # MVC
there is a View where I pass a string to the controller
$.ajax({
type: "POST",
url: "/Naryad/AjaxTest4",
data: JSON.stringify(testDataN),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
function successFunc(data, status) {
alert(data);
}
function errorFunc(errorData) {
alert('Ошибка' + errorData.responseText);
} })
})
[HttpPost]
public ActionResult AjaxTest4(Naryad[] testDataN)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
string tmp = string.Empty;
for (int i = 0; i < testDataN.Length; i++)
{
string oborud = testDataN[i].Oborud;
string on = String.Format("{0}", oborud);
tmp += string.Format("Сервер2 получил данные! Значения: {0}", on + ", " + testDataN[i].Date + ", " + testDataN[i].Staff + ", " + testDataN[i].TypeTo + ", " + testDataN[i].Work + ", " + testDataN[i].Tp + "," + testDataN[i].Tf);
}
return View();
}
Answer the question
In order to leave comments, you need to log in
The easiest way is to convert an array of outfits to csv. And then you can convert from csv to xls using, for example, the EPPlus library ( a simple use case).
The conversion itself is best done in a separate method, rather than in AjaxTest4(). Better even in a separate class, IMHO.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question