SAP ABAP 如何读取EXCEL数据到内表

2024-11-01 08:01:24
推荐回答(1个)
回答1:

读取EXCEL数据到内表并好穗输出调用函数: ALSM_EXCEL_TO_INTERNAL_TABLE *&---------------------------------------------------------------------**& Report ZCMH0009*&*&---------------------------------------------------------------------**& 读取EXCEL 的数据 到内表*&*&---------------------------------------------------------------------*REPORT ZCMH0009.INCLUDE OLE2INCL. "定义OLE变量DATA: BEGIN OF IEXCEL OCCURS 0. INCLUDE STRUCTURE ALSMEX_TABLINE.DATA: END OF IEXCEL.DATA: XLS LIKE RLGRAP-FILENAME VALUE 'C:\sap_usr02.xls'.CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING FILENAME = XLS
I_BEGIN_COL = 1 I_BEGIN_ROW = 1 I_END_COL = 100 " 读取多少列 I_END_ROW = 100 "读取多少行 TABLES INTERN = IEXCEL
EXCEPTIONS INCONSISTENT_PARAMETERS = 1 UPLOAD_OLE = 2 OTHERS = 3."读取后内表保好袜桐存的结构为:第一行记录第一个单元的行值 列友坦值 单元格内容 比如 0001 0001 第一个单元格内容WRITE: /.IF sy-subrc <> 0. WRITE: / XLS,'读入错误!'.ELSE. LOOP AT IEXCEL. WRITE IEXCEL-VALUE(20). "取前20个字符 AT END OF ROW. "每行行尾输出空行 WRITE : /. ENDAT. ENDLOOP.ENDIF.