函数名:ALSM_EXCEL_TO_INTERNAL_TABLE
作用:将本地的Excel文件中的数据导入到程序中参考ALSMEX_TABLINE创建的内表。
代码:
DATA: GT_INTERN LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
"被讀取的文件
DATA: G_FILENAME LIKE RLGRAP-FILENAME VALUE 'D:\1.XLS',
"文件讀取開始結束的行號和列號
G_SCOL TYPE I VALUE 1,
G_SROW TYPE I VALUE 1,
G_ECOL TYPE I VALUE 256,
G_EROW TYPE I VALUE 65536.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = G_FILENAME
I_BEGIN_COL = G_SCOL
I_BEGIN_ROW = G_SROW
I_END_COL = G_ECOL
I_END_ROW = G_EROW
TABLES
INTERN = GT_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE: (5)'行號', (5)'列號', '單元格的值', /.
LOOP AT GT_INTERN.
WRITE: (5)GT_INTERN-ROW, (5)GT_INTERN-COL, GT_INTERN-VALUE, /.
ENDLOOP.
结果截图:
Excel文件内容:
程序运行结果: