Ruby program with win32ole no longer works under Windows7 64bit

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]
+2
source share
3 answers

Thanks to everyone who added ideas and comments to my question. Finally, I found a workaround.

 class EasyExcel .... def save(filename) saveCache dos_file = filename.gsub(/\//, "\\\\") @workbook.SaveAs(filename) end 

This replaces the (ruby) path with each slash with two backslashes, which will then be evaluated to 1 backslash at the end.

So, open excel with

 @workbook = @excel.Application.Workbooks.Open(@path) 

(with @path something like

 C:/projekte/itcampus/feedback-analyse/feedback/Bewertungsbogen_XX1404.xls 

) works, but

 @workbook.SaveAs("c:/projekte/itcampus/feedback-analyse/feedback_report.xls") 

no. Very strange!

+3
source

I had a similar problem on Windows Server 2008 (64-bit) and the solution using filename.gsub(/\//, "\\\\") and expand_path did not help.

When I called it with my user, it worked, the same program in the background process canceled OLE-Error.

Solution (I'm not joking, it worked): create the folder C:\Windows\SysWOW64\config\systemprofile\Desktop .

I found a solution at https://blogs.msdn.microsoft.com/dataaccesstechnologies/2012/12/19/error-microsoft-office-excel-cannot-access-the-file-while-accessing-microsoft-office-11- 0-object-library-from-ssis / :

For Windows 2008 Server x64: create the following directory:

C: \ Windows \ SysWOW64 \ Config \ systemprofile \ Desktop

For Windows 2008 Server x86: create the following directory:

C: \ Windows \ System32 \ Config \ systemprofile \ Desktop

Here it is! Voila !! Are you all ready to go .....

Alternative link with similar data: https://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows- server-2008-x64? forum = innovateonoffice

+1
source

Many of the problems you may encounter when using COM and switching to Windows 7 are related to user rights. Have you tried to run your program with administrator privileges?

0
source

Source: https://habr.com/ru/post/974385/


All Articles