SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2013
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    data table to excel

    hello guys, i have this simple code to convert data from table to excel file and it's not working. Maybe because i'm using ubuntu instead of windows.

    PHP Code:
    <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 (0x.lengthi++)
    {
    var 
    x[i].cells

    for (0y.lengthj++)
    {
    xls.Cellsi+1j+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> 

    Any idea what's wrong and how to fix this? much appreciated guys. ^^,

  2. #2
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Hey Marvin,

    This is definitely because you're not using Internet Explorer. Check out the ActiveXObject function reference.

    Note: I'll move your question to the correct forum, as this question is a JavaScript question, not a PHP question.

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As Mal says, ActiveX is an Internet Explorer thing, if you want this javascript to work you will need to use Internet Explorer.

    My suggestion for an alternative to IE is to create a simple spreadsheet in excel (or libreoffice if you're on ubuntu). When you have some sample data in the spreadsheet, choose 'save as'. One of the formats you can save your spreadsheet in is a html file - select the html option. When you look at the source code of the html file that is saved, you will see the markup is actually very simple (once you get past the extra stuff that excel adds before/after the table element).

    You can use this format as a basis to create a similar table structure in your own webpage. When you open that html file with excel, excel should know how to read the html table as a spreadsheet. I've done this before and it does take some messing around to get it to work, but if you're feeling experimental this is a possible option. Your mileage may vary and I would not put any sort of expectation on this to work reliably, however for your own personal use this may be a reasonable solution.

    Otherwise... use Internet Explorer and ActiveX objects...


Bookmarks

Posting Permissions

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