dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: html table to excel spreadsheet using javascript without php

  1. #1
    Join Date
    Apr 2006
    Posts
    2

    html table to excel spreadsheet using javascript without php

    Hi can anyone help me with the script to convert a html table to excel spreadsheet using javascript without php
    MIME header has been included is ther anything to be included in the script

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Javascript doesn't know what a file is. You could probably write a Javascript to convert the content (provided that you have the Excel file specification to know what to convert to what - Microsoft may sell you that for a few million dollars). Of course the Javascript will be so rediculously large as to make huge web pages look microscopic. There is of course then no way for you to save that content once you have let the Javascript finish creating it (possibly a wait of several months).

    To be able to do this at all you would need to use a server side language that understands what Excel is.

  3. #3
    Join Date
    Apr 2006
    Posts
    2

    doesnt this work??It does ,anyways thank you

    <html>

    <head>
    <script type="text/javascript">

    function CreateExcelSheet()
    {


    var x=myTable.rows

    var xls = new ActiveXObject("Excel.Application")
    xls.visible = true
    xls.Workbooks.Add
    for (i = 0; i < x.length; i++)
    {
    var y = x[i].cells

    for (j = 0; j < y.length; j++)
    {
    xls.Cells( i+1, j+1).Value = y[j].innerText
    }
    }




    }
    </script>


    </head>

    <body marginheight="0" marginwidth="0">
    <form>
    <input type="button" onclick="CreateExcelSheet()" value="Create Excel Sheet">
    </form>
    <table id="myTable" border="1">
    <tr> <b><td>Name </td> <td>Age</td></b></tr>
    <tr> <td>Shivani </td> <td>25</td> </tr>
    <tr> <td>Naren </td> <td>28</td> </tr>
    <tr> <td>Logs</td> <td>57</td> </tr>
    <tr> <td>Kas</td> <td>54</td> </tr>
    <tr> <td>Sent </td> <td>26</td> </tr>
    <tr> <td>Bruce </td> <td>7</td> </tr>
    </table>



    </body>

    </html>

  4. #4
    Join Date
    Jul 2007
    Posts
    1

    Thanks

    Thanks for your info shivani.

    I tried to save a spreadsheet from javascript using the command xls.workbooks.save. If i try to close the spreadsheet, even then it asks whether to save the changes. how to prevent this from occuring?

    Thanks in advance!

  5. #5
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    Of course there are a lot of assumptions rolled into that Javascript function.

  6. #6
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    It is actually JScript/ActiveX rather than JavaScript and so the main assumptions to start with is that the browser is Internet Explorer and the Operating System is Windows since that combination is the only one to support those languages.

  7. #7
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    There may be an assumption that Excel is installed, too.

  8. #8
    Join Date
    Nov 2007
    Posts
    2

    Thnak you all

    Quote Originally Posted by klshivani
    <html>

    <head>
    <script type="text/javascript">

    function CreateExcelSheet()
    {


    var x=myTable.rows

    var xls = new ActiveXObject("Excel.Application")
    xls.visible = true
    xls.Workbooks.Add
    for (i = 0; i < x.length; i++)
    {
    var y = x[i].cells

    for (j = 0; j < y.length; j++)
    {
    xls.Cells( i+1, j+1).Value = y[j].innerText
    }
    }




    }
    </script>


    </head>

    <body marginheight="0" marginwidth="0">
    <form>
    <input type="button" onclick="CreateExcelSheet()" value="Create Excel Sheet">
    </form>
    <table id="myTable" border="1">
    <tr> <b><td>Name </td> <td>Age</td></b></tr>
    <tr> <td>Shivani </td> <td>25</td> </tr>
    <tr> <td>Naren </td> <td>28</td> </tr>
    <tr> <td>Logs</td> <td>57</td> </tr>
    <tr> <td>Kas</td> <td>54</td> </tr>
    <tr> <td>Sent </td> <td>26</td> </tr>
    <tr> <td>Bruce </td> <td>7</td> </tr>
    </table>



    </body>

    </html>


    I am verry much thank full to all, this code has reduced my work a lot, thanks again.

  9. #9
    Join Date
    Jul 2012
    Posts
    1
    Hi klshivani....

    First of all this script is really amazing. I like it. However I tried to use your script but it only allow to saved if you enable the "Internet Options-Security Level-Custom Level-"Initialize and script ActiveX controls not marked as safe" first. Is theres any way of doing this script avoiding these setup because most people will not enable this feature in internet explorer for secuirty purpose.

    Thank you.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles