Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Chien Hoang on Jul 04, 2007 10:30
open dhtmlx forum
Export the Grid to Excel???

Hello,
I used th free version of dhtmlxGrid and wanted to export the grid to Excel from client and I used the following function to perform and it worked well:
<script>
function export2excel(){
    var jrow    =    mygrid.getRowsNum();
    var jcol    =    mygrid.getColumnCount()-1;
    var myhead    =    "Sales,Book Title,Author,Price,In Store,Shipping,Bestseller,Date of Publication"
    jhead    =    new Array();
    jhead    =    myhead.split(',')
    var xls = new ActiveXObject("Excel.Application")
    xls.visible = true
    xls.Workbooks.Add
    row = 0
    for (i = 0; i <= jrow; i++){
        row++
        col=0
        if (i>0){
            for (j = 0; j <= jcol; j++){
             col++
            xls.Cells( row, col).Value = mygrid.cells(i,j).getValue();
            }
        }
        else{
            for (j = 0; j <= jcol; j++){
            xls.Cells( 1, j+1).Value = jhead [j];
            }
        }
    }
    var rng = xls.Columns(String.fromCharCode(65, 58, 65 + jcol))
    rng.AutoFit
}
</script>
The problem is I really want to use it as a built-in function so that I don't need to clarify Header, Number of rows, Number of Cols. etc.

Anyone can help?

Thanks,
-Chien Hoang
Email: chienhoang@yahoo.com
Answer posted on Jul 04, 2007 13:24
Because solution are IE-centric we do not plan to implement such functionality as part of dhtmlxGrid, but you can fill Excel.Application from csv string

The dhtmlxGrid_nxml.js extension included in latest standard package has next method for grid serialization ( with optional headers ) as CSV string

    var csv=grid.serializeToCSV();


Answer posted by Chien Hoang on Jul 05, 2007 05:57
Thank you very much.
Answer posted by Alexandra (Support) on Dec 07, 2014 03:19

I hope this information will be enough for you. But you also can have a look at data processor data and wordpress calendar of events.