I have an old ruby program that extracts values from an excel file and saves the summary in another excel file. For this purpose, the program uses the win32ole library from Ruby. After switching to a new computer with 64-bit Windows 7 (instead of Windows XP 32 bits), Office 2007 instead of Office 2003, the program now gives an error when saving the received excel file:
ana.rb:120:in `method_missing': SaveAs (WIN32OLERuntimeError) OLE error code:800A03EC in Microsoft Office Excel 'c:/my/dir' could not be accessed. The file could be corrupt, is on a server that does not react, or the file is write protected. (German: Auf 'c:/my/dir' konnte nicht zugegriffen werden. Unter Umstaenden ist die Datei beschaedigt, befindet sich auf einem Server, der nicht mehr reagiert, oder die Datei ist schreibgeschuzetzt.) HRESULT error code:0x80020009 Ausnahmefehler aufgetreten. from ana.rb:120:in `save' from ana.rb:54:in `generateReport' from ana.rb:13:in `ana' from ana.rb:191
Relevant parts of the program:
def generateReport ... report.save(basicdir + reportfile) ... end
with report:
class EasyExcel def initialize(path) @path = path @excel = excel = WIN32OLE.new("excel.application") @workbook = @excel.Application.Workbooks.Open(@path) @cache = Array.new end def save(filename) saveCache @workbook.SaveAs(filename) end
Line 120 is @workbook.SaveAs(filename) . The value of filename at this point is c:/projekte/itcampus/feedback-analyse/feedback_report.xls . After some debugging, I noticed that due to my poor handling of Ruby exceptions, after stopping the ruby interpreter, there are 2 excel hang instances. It seems that the problem is really related to changes in the processing path in Excel in Windows 7.
Does anyone know the answers to the following questions:
- What could be the reason for the failure: 64-bit rather than 32-bit, using Office 2007 instead of 2003, or both?
- Workaround or fix for using bridge for Windows 7 64bit and applications like Word or Excel from Ruby?
- How can I find which API is available from a Windows application from Ruby?
the Ruby interpreter I tried:
- ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
- ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
source share