Jul 26, 2019, 9:43 AM
Export to excel and csv
Hi guy,
I tried export data to excel and csv by the following code.
In the C# code
I using ext.net version 4.8.2.0
Someone help me please
Many thanks
I tried export data to excel and csv by the following code.
In the C# code
[DirectMethod]
public void DownloadFile(string type)
{
string json = GridData.Value.ToString();
StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
System.Xml.XmlNode xml = eSubmit.Xml;
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
switch (type)
{
case "Excel":
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment; filename=submittedData.xls");
System.Xml.Xsl.XslCompiledTransform xtExcel = new System.Xml.Xsl.XslCompiledTransform();
xtExcel.Load(HttpContext.Current.Server.MapPath("Excel.xsl"));
xtExcel.Transform(xml, null, response.OutputStream);
break;
case "CSV":
response.ContentType = "application/octet-stream";
response.AddHeader("Content-Disposition", "attachment; filename=submittedData.csv");
System.Xml.Xsl.XslCompiledTransform xtCsv = new System.Xml.Xsl.XslCompiledTransform();
xtCsv.Load(HttpContext.Current.Server.MapPath("Csv.xsl"));
xtCsv.Transform(xml, null, response.OutputStream);
break;
}
response.End();
}
and javascript code...ToExcel: function () {
GalaxyReport.FORMS._1.saveData();
App.direct.DownloadFile('Excel',{
isUpload: true,
buffer: 300,
success: function (result) {
Ext.Msg.alert('Message', result);
setTimeout(function () {
}, 2000);
},
failure: function (error, response) {
Ext.Msg.show({ title: 'Message', icon: Ext.MessageBox.ERROR, msg: error, buttons: Ext.Msg.OK });
}
});
setTimeout(function () {
}, 2000);
},
ToCSV: function () {
GalaxyReport.FORMS._1.saveData();
App.direct.DownloadFile('CSV',{
isUpload: true,
buffer: 300,
success: function (result) {
Ext.Msg.alert('Message', result);
setTimeout(function () {
}, 2000);
},
failure: function (error, response) {
Ext.Msg.show({ title: 'Message', icon: Ext.MessageBox.ERROR, msg: error, buttons: Ext.Msg.OK });
}
});
setTimeout(function () {
}, 2000);
},
saveData: function () {
var grid = Ext.getCmp("gplVoucher");
var d = Ext.getCmp("GridData");
d.setValue(Ext.encode(grid.getRowsValues({ selectedOnly: false })));
}
btnToExcel.Listeners.Click.Handler = SCOPE + ".ToExcel();";
btnToCSV.Listeners.Click.Handler = SCOPE + ".ToCSV();";
When i run in visual studio it work fine, but when i publish to the host, it download with blank data for excel file and something code for csv file.I using ext.net version 4.8.2.0
Someone help me please
Many thanks