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.
var xls = new ActiveXObject("Excel.Application")
xls.visible = true
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
<body marginheight="0" marginwidth="0">
<input type="button" onclick="CreateExcelSheet()" value="Create Excel Sheet">
<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>
Any idea what's wrong and how to fix this? much appreciated guys. ^^,
This is definitely because you're not using Internet Explorer. Check out the ActiveXObject function reference.
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...
This topic is now closed. New replies are no longer allowed.