javascript send to excel

B

bob

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=javascript>
function exportToExcel()
{
var oExcel = new ActiveXObject("Excel.Application");
var oBook = oExcel.Workbooks.Add;
var oSheet = oBook.Worksheets(1);
for (var y=0;y<detailsTable.rows.length;y++)
// detailsTable is the table where the content to be exported is
{
for (var x=0;x<detailsTable.rows(y).cells.length;x++)
{
oSheet.Cells(y+1,x+1) =
detailsTable.rows(y).cells(x).innerText;
}
}
oExcel.Visible = true;
oExcel.UserControl = true;
}
</script>

<button onclick="exportToExcel();">Export to Excel File</button>


<table name="detailsTable">
<tr>
<td> hello
</td>
</tr>
</table>
 
V

VK

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top