3

我正在尝试使用 SAP ABAP OLE OBJECT 打开受密码保护的 excel 文件,如下所示:

DATA: lt_excel_line(4096) OCCURS 10 WITH HEADER LINE.
DATA: app       TYPE ole2_object,
      workbook  TYPE ole2_object,
      worksheet TYPE ole2_object.

CREATE OBJECT app 'EXCEL.APPLICATION'.
SET PROPERTY OF app 'VISIBLE' = 0.

CALL METHOD OF app 'WORKBOOKS' = workbook.

CALL METHOD OF workbook 'OPEN'
  EXPORTING
  #1 = '<filename>'
  #5 = '<password>'.           

文件名和密码绝对正确,下面的 VBA 代码按要求打开文件没问题:

Dim wb1 As Workbook
Set wb1 = Workbooks.Open Filename:="<filename>", Password:="<password>")

但是 ABAP 代码总是返回 sy-subrc = 2。有人知道会发生什么吗?或者我还能尝试什么?感谢任何帮助。

4

1 回答 1

2

I think the problem is with the parameters being positional only (just a guess), as the SAP GUI automation does not support parameter names. There are 3 parameters between Filename and Password, so you numbered them correctly, but I guess the SAP GUI automation controller does not see it that way.

I replicated your problem and got it working as follows:

CALL METHOD OF workbook 'OPEN' = document
  EXPORTING
  #1 = '<filename>'
  #2 = 0              "UpdateLinks
  #3 = 0              "ReadOnly
  #4 = 1              "Format
  #5 = '<password>'.

Here I am explicitly passing the parameters UpdateLinks, ReadOnly and Format.

I tested it first in VBA. It seems Format (#4) must be set to true. I don't know what that does.

Remember to set the document handle as a return from this call as I do here, otherwise you don't have a reference to it!

于 2013-04-23T09:56:32.720 回答