From: Alexander Schofield Date: 2002-03-04T11:37:18+09:00 Subject: Re: Using Win32OLE with Excel leaves Excel process hanging I understand what you mean now, but I'm afraid I can't help. Mainly because I can't seem to recreate the problem on my machine (with office 97). Excel is left standing, and Ruby exits fine (when i use rubyw, irb kills it). At the risk of being pelted by stones may I suggest that you prototype this in some M$ technology? Vba or even WSH possibly. It's just a lot easier when you have an object/method browser to play with. Otherwise I found #ole_methods useful from irb in experimenting on the fly. "Robert C. Martin" wrote: > > On Sat, 23 Feb 2002 09:39:25 -0500, Alexander Schofield > wrote: > > Sorry, I should have been clearer. The goal is for the Ruby program > to quit, leaving the Excel window on the screen. The user can then > look at the Excel window for as long as they like and then close it. > By then the Ruby program is long gone. > > So what I need is a way for the Ruby program to detach from the excel. > program, and leave it running. > > >Also > >excel.ActiveWorkbook.Close(0); > >probably wouldn't be a bad idea. > > > >It seems like you were expecting a GC to clean up, in Ruby it can, but > >there are problems interfacing with other progs. Try > >ObjectSpace#define_finalizer for a destructor. > > > >"Robert C. Martin" wrote: > >> > >> I have created a neat little ruby program that generates a useful > >> graph in Excel. I keep the program on my desktop and doubleclick it > >> whenever I want to see the graph. Unfortunately, once I invoke this > >> program, it seems to leave a process running in the system. After > >> 20min or so, it will stop working. What's more, it often prevents > >> other OLE operations from working in other applications. It can be > >> fixed by a logout/logon. I'm using windows 2000. > >> > >> Any ideas? > >> > >> Here is the code for AmazonAnalyzer.rb > >> > >> require 'AmazonAnalyzer' > >> require 'win32ole' > >> > >> if __FILE__ == $0 > >> periodLength = 7 > >> if (ARGV[0] != nil) && (ARGV[0].to_i > 0) > >> periodLength = ARGV[0].to_i > >> end > >> > >> puts "Running Amazon Analyzer with period length #{periodLength}" > >> > >> analyzer = AmazonAnalyzer.new() > >> analyzer.analyzeFile("bookData", periodLength) > >> > >> excel = WIN32OLE.new("excel.application") > >> workbook = excel.Workbooks.Add() > >> > >> col = 'b' > >> row = "1" > >> analyzer.startDate.step(analyzer.endDate,periodLength) {|date| > >> excel.Range(col+row).value = date.to_s > >> col = col.succ > >> } > >> > >> isbns = analyzer.isbns > >> isbns.each {|isbn| > >> col='a' > >> row = row.succ > >> title = analyzer.getTitleFor(isbn) > >> title = title.split(':')[0] > >> title = title.split('(')[0] > >> title = title[0,40] > >> excel.Range(col+row).value = title > >> > >> periods = analyzer.getPeriodsForIsbn(isbn) > >> 0.upto(periods.max) {|period| > >> col = col.succ > >> if periods.include?(period) > >> excel.Range(col+row).value = > >> analyzer.getRange(isbn,period).mean > >> end > >> } > >> } > >> xlLine=4 > >> xlValue=2 > >> xlRows=1 > >> xlScaleLogarithmic = -4133 > >> excel.Range("a1:"+col+row).Select() > >> excelChart = workbook.Charts.Add() > >> excelChart.type = xlLine > >> excelChart.plotBy=xlRows > >> excelChart.Legend.Font.Size=8 > >> excelChart.Axes(xlValue).scaleType = xlScaleLogarithmic > >> excelChart.Axes(xlValue).minimumScale = 100 > >> > >> workbook.saved = true > >> excel.visible = true > >> end > >> > >> Robert C. Martin | "Uncle Bob" > >> Object Mentor Inc.| unclebob @ objectmentor . com > >> PO Box 5757 | Tel: (800) 338-6716 > >> 565 Lakeview Pkwy | Fax: (847) 573-1658 | www.objectmentor.com > >> Suite 135 | | www.XProgramming.com > >> Vernon Hills, IL, | Training and Mentoring | www.junit.org > >> 60061 | OO, XP, Java, C++, Python | > >> > >> "One of the great commandments of science is: > >> 'Mistrust arguments from authority.'" -- Carl Sagan > > Robert C. Martin | "Uncle Bob" > Object Mentor Inc.| unclebob @ objectmentor . com > PO Box 5757 | Tel: (800) 338-6716 > 565 Lakeview Pkwy | Fax: (847) 573-1658 | www.objectmentor.com > Suite 135 | | www.XProgramming.com > Vernon Hills, IL, | Training and Mentoring | www.junit.org > 60061 | OO, XP, Java, C++, Python | > > "One of the great commandments of science is: > 'Mistrust arguments from authority.'" -- Carl Sagan -- Alexander Schofield