因此,我想打开一个受密码保护的 excel 文件,提示用户输入密码,但我想在提示用户之前检查该文件是否确实需要密码。
我目前的方法是这样并且确实有效。
CREATE OBJECT app 'EXCEL.APPLICATION'.
CALL METHOD OF app 'WORKBOOKS' = workbook.
CALL METHOD OF workbook 'OPEN'
EXPORTING
#1 = arch "filename
#2 = 0 "Update links
#3 = 0 "ReadOnly
#4 = 1 "Format
#5 = gv_password. "password
IF sy-subrc NE 0.
CALL METHOD OF app 'QUIT'.
FREE OBJECT app. FREE OBJECT workbook.
CLEAR: app, workbook.
CREATE OBJECT app 'EXCEL.APPLICATION'.
gv_password = <user_entered_password>
CALL METHOD OF app 'WORKBOOKS' = workbook.
CALL METHOD OF workbook 'OPEN'
EXPORTING
#1 = arch "filename
#2 = 0 "Update links
#3 = 0 "ReadOnly
#4 = 1 "Format
#5 = gv_password. "password
ENDIF.
这基本上尝试使用空白密码打开 excel 文件,如果失败会提示用户。不过,这不是一个特别快速或优雅的解决方案。有没有更好的办法?也许在尝试打开之前直接检查属性?谢谢