使用OLE的方法获取本地指定Excel的Sheet的名字列表:
REPORT z_barry_test .
INCLUDE ole2incl.
PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'C:\test.xls'.
DATA: application TYPE ole2_object,
book TYPE ole2_object,
sheet TYPE ole2_object .
DATA: BEGIN OF itab_sheetname OCCURS 0 ,
sheetname(40) ,
END OF itab_sheetname .
DATA: sheetcount TYPE i .
START-OF-SELECTION.
CREATE OBJECT application 'Excel.Application'.
SET PROPERTY OF application 'Visible' = 0 .
CALL METHOD OF application 'Workbooks' = book.
CALL METHOD OF book 'Open'
EXPORTING #1 = p_file.
CALL METHOD OF application 'WORKSHEETS' = sheet.
GET PROPERTY OF sheet 'COUNT' = sheetcount.
DO sheetcount TIMES.
CALL METHOD OF application 'WORKSHEETS' = sheet
EXPORTING #1 = sy-index.
GET PROPERTY OF sheet 'NAME' = itab_sheetname-sheetname .
APPEND itab_sheetname.
ENDDO.
LOOP AT itab_sheetname.
WRITE / itab_sheetname.
ENDLOOP.
GET PROPERTY OF application 'ActiveWorkbook' = book .
* CALL METHOD OF book 'SAVE' .
CALL METHOD OF book 'close'.
CALL METHOD OF application 'QUIT'.
阅读(5706) | 评论(0) | 转发(0) |