View Single Post
  #1 (permalink)  
Old February 7th, 2007, 06:46 AM
interrupt interrupt is offline
Friend of Wrox
Join Date: May 2004
Location: , , .
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
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

if(rowCount ==7)
rowCount = 1

rowCount = 1
colCount = 1

eWApp = null;

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:

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

This allows me to close the object with:

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

'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.
Reply With Quote