Exporting DataGrid As Excel

Discussion in 'ASP .Net' started by batista, Oct 27, 2005.

  1. batista

    batista Guest

    Hi,

    I have a web datagrid and i want to give user option
    to export it as excel file.

    How is it implemented?

    Bye.
    batista, Oct 27, 2005
    #1
    1. Advertising

  2. exportToExcel = function() {
    var i;
    var j;
    var mycell;
    var objXL;
    try {
    objXL = new ActiveXObject("Excel.Application");
    if (objXL==null) {
    alert("Excel must be installed");
    return;
    }
    }
    catch(e){
    alert("Error creating Excel ActiveX ");
    return;
    }
    var objWB = objXL.Workbooks.Add();
    var objWS = objWB.ActiveSheet;

    var tbl = actualTable; // here goes your table object

    for (i=0; i < tbl.rows.length; i++) {
    for (j=0; j < tbl.rows(i).cells.length; j++) {
    mycell = tbl.rows(i).cells(j);
    objWS.Cells(i+1,j+1).Value = mycell.innerText;

    if ((mycell.innerText.indexOf("/") >= 0) && (mycell.innerText.length
    <= 10))
    {
    objWS.Cells(i+1,j+1).NumberFormat = "dd/mm/yyyy";
    objWS.Cells(i+1,j+1).HorizontalAlignment = -4108;
    objWS.Cells(i+1,j+1).Font.color = mycell.style.color;
    }
    }
    }

    objWS.Range("A1", "L1").Font.Bold = true;
    objWS.Range("A1", "Z1").EntireColumn.AutoFit();

    objXL.Visible = true;
    };

    Something like this ...
    Tasos Vogiatzoglou, Oct 27, 2005
    #2
    1. Advertising

  3. batista

    batista Guest

    thnks for reply,

    I have an aspnet datagrid. now at this line

    var tbl = actualTable; // here goes your table object

    i can get the object of aspdtagrid but how do i access
    the rows length, cells length etc in the remaining lines.
    I mean js is giving error.

    And wat if i want to open a save file dialog when the user
    clicks on the excel link.How do i implemet this?

    Bye.
    batista, Oct 27, 2005
    #3
  4. =?Utf-8?B?c3Jpbmk=?=, Oct 27, 2005
    #4
  5. actualTable = the DOM object representing the table ...
    document.getElementById('tableId');
    Tasos Vogiatzoglou, Oct 31, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravindra
    Replies:
    0
    Views:
    759
    Ravindra
    Dec 14, 2005
  2. =?Utf-8?B?TmVpbA==?=

    Exporting DataGrid to Excel

    =?Utf-8?B?TmVpbA==?=, Feb 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    472
    =?Utf-8?B?cGRtMg==?=
    Apr 3, 2004
  3. http://www.visual-basic-data-mining.net/forum

    Exporting Datagrid's data to an Excel Sheet.

    http://www.visual-basic-data-mining.net/forum, Oct 25, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    572
    Steve C. Orr [MVP, MCSD]
    Oct 25, 2004
  4. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,359
    Carl Prothman [MVP]
    Jan 12, 2005
  5. Doogie
    Replies:
    1
    Views:
    435
    sloan
    Nov 19, 2008
Loading...

Share This Page