Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2007, 06:46 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript & ActiveX Excel Object Process

Hi All,

I might be being a bit retarded here, but I'm having a bit of a silly issue and for some reason I can't wrap my brain around it. I've built a routine that exports the contents of a table into Microsoft Excel, through the use of Javascript and ActiveX. Here's the code:

<script language = "javascript">
var iCellsStr = ""
var hCellsStr = ""
var rangeStr = "ABCDEF"
var rowCount = 1
var colCount = 1
function xcTable()
{
var eWApp = new ActiveXObject("Excel.Application")
eWApp.Visible = true
eWApp.Workbooks.Add()
xlSheet = eWApp.ActiveSheet


for (iCells = 0; iCells < t1.cells.length; iCells++)
{

iCellsStr+=(t1.cells[iCells].innerText + " ")
cellWriteStr = rangeStr.substring(rowCount-1, rowCount) +colCount
xlSheet.Range(cellWriteStr).Value = t1.cells[iCells].innerText


rowCount++
if(rowCount ==7)
{
rowCount = 1
colCount++
}
}

rowCount = 1
colCount = 1

eWApp = null;
}
</script>

What I'd like to be able to do is leave the Excel book open until the user has finished with it (they will close it at their leisure). However, if I do that, there is a process left in the process tree that doesn't get killed when the user exits Excel. If I do the closure from Javascript through the workbook object first, however (following), it does kill the process.

Instead of having:
eWApp.WorkBooks.Add()

I can have:
var eWkBookAdd = eWApp.Workbooks.Add()

This allows me to close the object with:
eWkBookAdd.Close(false)

But if my user wants to work with the data straight away I can't kill the process! I tried setting the eWApp object to null, hoping that when the user was finished with Excel, I could use the GarbageCollect() method, but this didn't work either. In fact it caused a Doctor Watson error in Excel and crashed it. Is there any workaround for this or even a sensible suggestion? Or am I trying to open pandora's box?

Cheers in advance
Joe

'sync' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
__________________
\'sync\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
 
Old February 7th, 2007, 08:30 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can try setting eWAPP.UserControl = true at some stage. Personally I dislike using ActiveSheet and similar in automation, it's too likely to go wrong. I would use:
Code:
var oWorkbook = eWApp.Workbooks.Add()
xlSheet = oWorkbook.Sheets[0] //or oWorkbook.Sheets[1] I can't remember if Sheets is one or zero based.
--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Good way to select & process only one node traxwx XSLT 2 May 21st, 2007 05:08 PM
javascript intellisense & session object VictorVictor ASP.NET 2.0 Professional 0 March 29th, 2007 10:59 AM
Advantages /Disadvantages of ActiveX DLL & ActiveX priyank Beginning VB 6 6 February 19th, 2007 11:34 AM
Javascript && keeps turnig into &amp;&amp; ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
Using an activex event with javascript cirudinezidane Javascript How-To 1 March 9th, 2004 06:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.