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.

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






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



 



 

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 )


Have any example for doing this ?



 

There is no examples of such client side code, but I can send you an example of CSV-excell code  ( javascript + PHP )


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 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 ()
}

Are there any examples that I can get using PHP & javascript?


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.