javascript send to excel

Discussion in 'Javascript' started by bob, Sep 11, 2004.

  1. bob

    bob Guest

    Hi Everyone,

    I've tried looking at loads of sites but none have helped me so I hope
    someone here can.
    I'm bringing up a webpage with a table which i want to send to excel via a
    button without re-running the webpage query to load the table again.

    I've tried the code below and lots of different alternatives but no joy,
    this one seems to get further than the others though, when I click the
    button I get the following error "Automation server can't create object"
    line 4 char 1
    Excel is on the server and client pc running the page, the folder has write
    access in iis aswell, any ideas or alternative coding?

    Many thanks,
    Rob

    <script language=javascript>
    function exportToExcel()
    {
    var oExcel = new ActiveXObject("Excel.Application");
    var oBook = oExcel.Workbooks.Add;
    var oSheet = oBook.Worksheets(1);
    for (var y=0;y<detailsTable.rows.length;y++)
    // detailsTable is the table where the content to be exported is
    {
    for (var x=0;x<detailsTable.rows(y).cells.length;x++)
    {
    oSheet.Cells(y+1,x+1) =
    detailsTable.rows(y).cells(x).innerText;
    }
    }
    oExcel.Visible = true;
    oExcel.UserControl = true;
    }
    </script>

    <button onclick="exportToExcel();">Export to Excel File</button>


    <table name="detailsTable">
    <tr>
    <td> hello
    </td>
    </tr>
    </table>
    bob, Sep 11, 2004
    #1
    1. Advertising

  2. bob

    VK Guest

    [presuming you have IE installed]

    Change the page extension from .html to .hta

    Run again, grand permission when asked and enjoy (unless there are some
    coding errors in the script itself, I did not check it).

    Later may take some to read about HTA (Hyper Text Application), automation,
    and mostly about browser security model (msdn.microsoft.com would be a good
    start).
    VK, Sep 11, 2004
    #2
    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. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,026
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  2. Nathan Sokalski
    Replies:
    3
    Views:
    1,927
    Larry Lard
    Nov 23, 2005
  3. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,480
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  4. Chris Reay

    Does Socket.send send all bytes?

    Chris Reay, Nov 3, 2003, in forum: Ruby
    Replies:
    2
    Views:
    205
    Chris Reay
    Nov 4, 2003
  5. Ryan Parmeter
    Replies:
    4
    Views:
    235
    Douglas Wells
    Sep 5, 2007
Loading...

Share This Page