public void ExcelExport()
{
string treegridModel = HttpContext.Current.Request.Params["TreeGridModel"];
TreeGridProperties treegridProperty = ConvertGridObject(treegridModel);
//…
exp.Export(treegridProperty,(IEnumerable)data, "ExcelExport.xlsx", ExcelVersion.Excel2010, new TreeGridExportSettings() { Theme = ExportTheme.FlatAzure });
} |
private TreeGridProperties ConvertGridObject(string treegridProperty)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable div = (IEnumerable)serializer.Deserialize(treegridProperty, typeof(IEnumerable));
TreeGridProperties treegridProp = new TreeGridProperties();
foreach (KeyValuePair<string, object> ds in div)
{
var property = treegridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (property != null)
{
Type type = property.PropertyType;
string serialize = serializer.Serialize(ds.Value);
object value = serializer.Deserialize(serialize, type);
property.SetValue(treegridProp, value, null);
}
}
return treegridProp;
} |
Good afternoon,
I tried to implement it according to the example you sent, but when I try to export it it gives the following
error: Could not load file or assembly 'Syncfusion.Pdf.Base, Version = 15.2450.0.46, Culture = neutral, PublicKeyToken = 3d67ed1f87d44c89' or One of its dependencies. The localized assembly manifest definition does not match the assembly reference. (Exception of HRESULT: 0x80131040)
Ehe file Syncfusion.Pdf.Base is the only one with version 15.1460.0.33
Translated text in Google Translate.
Thanks,
Regards,
Daniela.
Hi,
Now with the
problem of reference neat, it continues giving error, being the export
to excel giving null reference and the export to pdf is exporting
without data. Follow the download link for the project being used: https://drive.google.com/file/d/0B-Djm-qROoSzRnVVMmRIRjNKRUU/view?usp=sharing
Thanks,
By Google Translate,
Regards,
Daniela.
function toolbarclick(args) {
var id = $(args.currentTarget).attr("id");
this.exportGrid = this["export"];
if (id == "TreeGridContainer_pdfExport") {
this.exportGrid('api/TreeGrid/PdfExport', "", false);
args.cancel = true;
}
if (id == "TreeGridContainer_excelExport") {
this.exportGrid('api/TreeGrid/ExcelExport', "", false);
args.cancel = true;
}
} |
Good afternoon,
So in my tests I'm getting information from the bank and moving on to a dynamic list variable. After that, I format for json and deal without javascript. So, all dynamically, being the dataSource of the ejTreeGrid, updated after some filters. Follow the code below:
Controller:
var list = new List<dynamic>();
var listaFilial = new List<dynamic>();
dynamic objEmpresa = new ExpandoObject();
objEmpresa.Empresa = emp + " - " + res.Where(x => x.Codempresa == emp).Select(x => x.Nomefantasiaempresa).FirstOrDefault();
objEmpresa.Categoria = "";
objEmpresa.Data = dataini.ToString();
objEmpresa.Total = res.Count(x => x.Codempresa == emp);
objEmpresa.Children = listaFilial.ToList();
List.Add(objEmpresa );
Var jsonResult = Json (list, JsonRequestBehavior.AllowGet);
JsonResult.MaxJsonLength = int.MaxValue;
Return jsonResult;
JS:
Data.push ({
Company: res [i] [0] .Value,
Category: res [i] [1] .Value,
Date: res [i] [2] .Value,
Total: res [i] [3] .Value,
Value: res [i] [4] .Value,
Children: fil
});
$ ("# TreeGridContainer") ejTreeGrid ({
DataSource: Data });
To export to pdf I do according to your example:
Function toolbarclick (args) {
Var id = $ (args.currentTarget) .attr ("id");
This.exportGrid = this ["export"];
If (id == "TreeGridContainer_pdfExport") {
This.exportGrid ('PdfExport', "", true);
Args.cancel = true;
}
//if (id == "TreeGridContainer_excelExport") {
//this.exportGrid (window.baseurl + 'api / TreeGrid / ExcelExport', "", false);
// args.cancel = true;
// }
}
Your example shows how to do it using webApi, but I do not intend to use it. And since I'm doing the list dynamically, without a model, would you know how I could get the information that is on the grid?
Thanks,
By Google Translate
Regards,
Daniela.