Hello support,
I think you should post an example in the documentation or download link to export data from grid to excel.
The questions are many.
Best Regards,
FelipeTv.
You can export dhtmlxGrid to the CSV format. Please find example here dhtmlx.com/docs/products/dht … d_csv.html
Thanks for the reply but I think you misunderstood me.
I need a script or command that exports the grid to excel.
Example:
mygrid.export(‘c:\mydiretory\grid.xls’)
Best Regards,
FelipeTv.
dhtmlxGrid is fully client side component. Conversion grid to excell is really
server side task. Grid can serialize itself as XML or CSV - which can be used
to further transformation on server side.
But this script:
<%
Response.ContentType = "application / vnd.ms-excel"
Response.AddHeader "content-disposition", "attachment; filename = ADM.xls"
%>
col1 |
col2 |
col3 |
row1-1 |
row1-2 |
row1-3 |
row2-1 |
row2-2 |
row2-3 Creates an excel on the client side. How could unite the two forms? Best Regards,
FelipeTv. |
dhtmlxGrid hasn’t appropriate methods to convert itself to the .xls format. It can only be serialized to the csv format. If such requirement is critical in your case you can contact sales@dhtmlx.com and request for component customization.
Solution in 3 steps:
Step 1:
Open the file dhtmlxGrid\codebase\ext\dhtmlxgrid_nxml.js
Paste this code:
//TOEXCEL
dhtmlXGridObject.prototype.exportToExcel = function(before,after)
{
var html=“TD {font-family:Arial;text-align:center};”;
var st_hr=null;
if (this._fake)
{
st_hr=this._hrrar;
for (var i=0;i<this._fake._cCount;i++)this._hrrar[i]=null
};
html+="";
if (!this.parentGrid)html+=(before||"");
html += ‘
’+this.getHeaderCol(i)+’ | ’;
’+sub.getSubGrid().exportToExcel()+’ |
’+this.rowsCol[i]._expanded.innerHTML+’ |
if (this.parentGrid)return html;
html+=(after||"");
//Here is the secret!!!
var writeDataXLS = document.getElementById(“toFileXLS”);
writeDataXLS.innerHTML = “”;
var varXLS = document.getElementById(“myGridToXLS”);
varXLS.value = html;
document.formToXLS.submit();
//End the secret
if (this._fake){this._hrrar=st_hr}};
dhtmlXGridObject.prototype._printWidth=function()
{
var width = [];
var total_width = 0;
for (var i=0;i<this._cCount;i++)
{
var w = this.getColWidth(i);
width.push(w);
total_width += w
};
var percent_width = [];
var total_percent_width = 0;
for (var i=0;i<width.length;i++)
{
var p = Math.floor((width[i]/total_width)*100);
total_percent_width += p;
percent_width.push§
};
percent_width[percent_width.length-1] += 100-total_percent_width;
return percent_width
};
//FIM TOEXCEL VIEW
Step 2:
Create file report.asp
Paste tihs code:
<%
Response.ContentType=“application/vnd.ms-excel”
Response.AddHeader “content-disposition”, “attachment; filename=relatorio.xls”
response.Write(request.Form(“dataToXLS”))
%>
Setp 3:
mygrid.asp
Export to Excel
<script src="…/…/codebase/dhtmlxcommon.js">
<script src="…/…/codebase/dhtmlxgrid.js">
<script src="…/…/codebase/ext/dhtmlxgrid_nxml.js">
<script src="…/…/codebase/dhtmlxgridcell.js">
Printable view