javascript send to excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bob

    javascript send to excel

    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=javasc ript>
    function exportToExcel()
    {
    var oExcel = new ActiveXObject(" Excel.Applicati on");
    var oBook = oExcel.Workbook s.Add;
    var oSheet = oBook.Worksheet s(1);
    for (var y=0;y<detailsTa ble.rows.length ;y++)
    // detailsTable is the table where the content to be exported is
    {
    for (var x=0;x<detailsTa ble.rows(y).cel ls.length;x++)
    {
    oSheet.Cells(y+ 1,x+1) =
    detailsTable.ro ws(y).cells(x). innerText;
    }
    }
    oExcel.Visible = true;
    oExcel.UserCont rol = true;
    }
    </script>

    <button onclick="export ToExcel();">Exp ort to Excel File</button>


    <table name="detailsTa ble">
    <tr>
    <td> hello
    </td>
    </tr>
    </table>


  • VK

    #2
    Re: javascript send to excel

    [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).






    Comment

    Working...