Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 7th, 2007, 06:46 AM
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
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.
Reply With Quote
  #2 (permalink)  
Old February 7th, 2007, 08:30 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:05 PM.


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