We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

ExportExcel don't work

Thread ID:

Created:

Updated:

Platform:

Replies:

131366 Jul 6,2017 01:20 PM Aug 3,2017 08:50 AM JavaScript 7
loading
Tags: ejTreeGrid
Daniela Menezes Tunes
Asked On July 6, 2017 01:20 PM

Greetings, we are using the treegrid (javascript version) and we need it to export in excel and pdf.
However, the TreeGridProperties property is not accepted into the export method of ExcelExport and when we try using the
GridProperties or GanttProprierties, it throws a nullexception when it attempt to generate.

Error: Object reference not set to an instance of an object.

And when we try to generate the pdf file, it generates no data, even following all the documentation steps.

Regards,
Daniela.

Jayakumar Duraisamy [Syncfusion]
Replied On July 7, 2017 07:48 AM

Hi Daniela, 
Thanks for contacting Syncfusion support. 
We have analyzed your reported issue in our sample. While exporting TreeGrid data, we must use TreeGridProperierties class type of treeGrid model. For that we have to serilzed the treeGrid model object before passing it to export method.  
Please refer following code snippet, 
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; 
        } 
We have prepared a TreeGrid exporting sample using Javascript and MVC API controller for exporting service. 
Please find the sample location as below, 
If you are facing this same issue again, please share your demo sample which able to reproduce the issue. It will helpful for us to serve you better. 
Regards, 
Jayakumar D 


Daniela Menezes Tunes
Replied On July 24, 2017 12:06 PM

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.

Jayakumar Duraisamy [Syncfusion]
Replied On July 25, 2017 09:17 AM

Hi Daniela, 
We have analyzed the reported exception and it says that you are using different assembly version and different framework. It is important that all the assemblies should be same framework and same version refer in your project because these are dependent with one another.  
Note: if dll’s framework version is higher than project framework then it will not work in your project and ensure assembly versions are properly mentioned in web.config file. 
If you are same facing the same issue again then please share you demo project which can able to reproduce the reported issue. It will be helpful for us to serve you better. 
Regards, 
Jayakumar D 


Daniela Menezes Tunes
Replied On July 28, 2017 09:34 AM

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.


Jayakumar Duraisamy [Syncfusion]
Replied On July 31, 2017 09:13 AM

Hi Daniela, 
We have analyzed your given sample and noticed that old scripts and theme files were referred in the sample. It is important that dll’s, scripts & themes files should be same version. 
In your sample, exporting has perform using JS TreeGrid code in MVC platform for that declared separate data sources like JSON data used in client side to render TreeGrid and list used in server side to export TreeGrid. 
But, the field names used for the both data source are different. So, client side column field name and server side data source field are completely mismatch. This is the reason for export Pdf as empty and excel export getting an exception. 
It is mandatory that use common data source for both client and server side. 
We have created a sample in the version of 15.2.0.46 using webAPI controller to handle exporting action. 
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; 
            } 
        } 
Please find the sample location as below, 
Please let us know, if you require any other assistance on this. 
Regards, 
Jayakumar D 


Daniela Menezes Tunes
Replied On August 2, 2017 01:15 PM

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,
  T
otal: 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.



Jayakumar Duraisamy [Syncfusion]
Replied On August 3, 2017 08:50 AM

Hi Daniela, 
We have analyzed your requirement. 
In TreeGrid, export actions are performed at server side, so we can’t export TreeGrid as PDF or Excel without using web API or server side methods. 
For export operation we need to pass TreeGrid model to server side and data source will passed from server code for export action. 
We require some clarification on your requirement. 
  • If you need to perform export action at client side?
  • If you need to use TreeGrid’s current data source instead of server side data for export action?
Please provide some more details about your requirement , it will helpful for us to serve you better. 
Regards, 
Jayakumar D 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;