Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Bahae Eddine on Dec 04, 2007 07:11
open dhtmlx forum
Export grid dat to an Excel file

Hello ,

I ask if everyone of you know how in can export data from a grid to an Excell file ?

Thanks in advance.
Answer posted by Stanislav on Dec 04, 2007 09:49
There is no way to export directly to Excell, but grid can be serialized to XML or CSV string ( which can be opened by Excel )
If you will need to send the result file back to user, the process will look as
    a) serialize file to csv string
    b) send it back to server
    c) server returns same data with correct content type





Answer posted by Bahae Eddine on Dec 04, 2007 10:16

Hello,

a lot of Thanks to you .

I'm still thinking to serialize data of the grid to CSV ,it works but what i need is i should have some toolbar in which i will have the possibility to read this file with the microsoft Excell .in other words i wish have an Excell file format.

Any help

 

 

Answer posted by Support on May 19, 2008 06:17
Native Excel format is binary, so you will need some kind of server processing in any case, it can be formed fully on client side. ( probably it can't, but it is non trivial task )
Answer posted by Bahae Eddine on Dec 04, 2007 10:25

Have any example for doing this ?

 

Answer posted on Dec 05, 2007 01:32
There is no examples of such client side code, but I can send you an example of CSV-excell code  ( javascript + PHP )
Answer posted by Chien Hoang on Jan 08, 2008 15:08

Hi Bahae,

I raised this question long time ago. Actually, we can do it from client-side with Automation server. I posted an exemple here and it worked.
You can try these lines of code and let me know. Infact, I think we should have an easier way to transform xml to excel. If you have any suggestion/idea, please advise me via mailto:chienhoang@yahoo.com

Good luck,

-Chien Hoang

function toExcel(){
 var jrow = mygrid.getRowsNum();
 var jstr  = mygrid.getAllItemIds();
  jrows = new Array();
  jrows = jstr.split(',')
 var jcol = mygrid.getColumnCount(); 
 var xls = new ActiveXObject("Excel.Application")
 xls.visible = true
 xls.Workbooks.Add
 /*****************************************/
 var row =0;
 for (i = -1; i<jrows.length; i++){
  row++
  col =0;
  for (j=0; j<jcol; j++){
   col++
   if (i<0){
    xls.Cells( row, col).Value = mygrid.getHeaderCol(j);
   }
   else{
    xls.Cells( row, col).Value = mygrid.cells(jrows[i],j).getValue();
   }
  }
 }
 var rng = xls.Columns(String.fromCharCode(65, 58, 65 + jcol))
 rng.AutoFit
 //if (isave=1) {xls.ActiveWorkbook.Save ()}
 // xls.ActiveWorkbook.Close ()
}

Answer posted by Brian on Feb 20, 2008 13:26
Are there any examples that I can get using PHP & javascript?
Answer posted by Hans on May 18, 2008 13:08

I think Stanislav's answer is the right way to do it. Writing a server page that outputs data to Excel is very easy and works on most platforms.

Chien's solution is using ActiveXobject which works in IE only, and will most probably make Excel hang on the client machine. Especially after a couple of attempts.
My 5 cents.