Click to See Complete Forum and Search --> : html table to excel spreadsheet using javascript without php
klshivani
04-04-2006, 07:40 AM
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 :confused:
felgall
04-04-2006, 04:00 PM
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.
klshivani
04-05-2006, 01:06 AM
<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>
neobrat
07-05-2007, 05:27 PM
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!
ray326
07-05-2007, 11:08 PM
Of course there are a lot of assumptions rolled into that Javascript function.
felgall
07-06-2007, 12:21 AM
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.
ray326
07-06-2007, 04:42 PM
There may be an assumption that Excel is installed, too.
greettech
11-19-2007, 04:21 AM
<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.