我有一个老的红宝石程序,它从excel文件中提取值,并将摘要存储在另一个excel文件中。为此,程序使用了来自Ruby的库win32ole。切换到具有Windows 7 64位(而不是Windows XP 32位)、Office 2007而不是Office 2003的新计算机后,程序现在在存储生成的excel文件时抛出错误:
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该方案的有关部分如下:
def generateReport
...
report.save(basicdir + reportfile)
...
end在报告中:
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第120行是@workbook.SaveAs(filename)。此时filename的值是c:/projekte/itcampus/feedback-analyse/feedback_report.xls。经过一些调试,我注意到,由于我的红宝石异常处理不好,在红宝石解释器停止后,有两个excel挂起实例。因此,问题似乎确实是由于Windows 7上Excel中处理路径的变化造成的。
是否有人知道下列问题的答案:
的Windows应用程序中找到哪个API可用?
我尝试过的Ruby解释器是:
i386-mingw32
发布于 2011-09-20 06:54:52
感谢所有在我的问题上提出意见和评论的人。最后,我找到了一个解决办法。
class EasyExcel
....
def save(filename)
saveCache
dos_file = filename.gsub(/\//, "\\\\")
@workbook.SaveAs(filename)
end这将将(ruby)路径中的每个正斜杠替换为2个反斜杠,该斜杠将在末尾计算为1个反斜杠。
所以打开一个excel
@workbook = @excel.Application.Workbooks.Open(@path)(使用@path,类似于
C:/projekte/itcampus/feedback-analyse/feedback/Bewertungsbogen_XX1404.xls)起作用,但是
@workbook.SaveAs("c:/projekte/itcampus/feedback-analyse/feedback_report.xls")不会的。很奇怪!
发布于 2016-08-19 09:42:15
我在Windows 2008 (64位)上也有类似的问题,使用filename.gsub(/\//, "\\\\")和expand_path的解决方案没有帮助。
当我和我的用户调用它时,它工作了,在后台进程中的相同程序被称为OLE错误。
解决方案(我不是开玩笑,它成功了):创建一个文件夹C:\Windows\SysWOW64\config\systemprofile\Desktop。
Windows2008Server
x64:创建以下目录:
C:\Windows\SysWOW64\config\systemprofile\Desktop
对于Windows2008Server x86:创建以下目录:
C:\Windows\System32\config\systemprofile\Desktop
就这样!!瞧!!你们都准备好去…了。。
发布于 2011-09-20 06:02:14
在使用COM和切换到Windows 7时,您可能会遇到许多与用户权限有关的问题。您是否尝试以管理员权限运行您的程序?
https://stackoverflow.com/questions/7467193
复制相似问题