ABAP 读取EXCEL文件到内表

1、选择excel文件:

PARAMETERS: P_FILE  LIKE RLGRAP-FILENAME OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
STATIC = 'X'
MASK = ',*.XLS,*.XLS'
CHANGING
FILE_NAME = P_FILE
EXCEPTIONS
MASK_TOO_LONG =
OTHERS =
.
  DATA: lt_file_table TYPE filetable.
DATA: lv_fn TYPE LINE OF filetable.
DATA: lv_rc TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
* WINDOW_TITLE =
* DEFAULT_EXTENSION =
* DEFAULT_FILENAME =
file_filter = cl_gui_frontend_services=>filetype_excel
CHANGING
file_table = lt_file_table
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed =
cntl_error =
error_no_gui =
not_supported_by_gui =
OTHERS = .

2、导入到与excel文件字段一致的内表:

TYPE-POOLS TRUXS.
DATA GT_RAW TYPE TRUXS_T_TEXT_DATA.
TYPES: BEGIN OF GTY_EXCEL,
COL1 TYPE STRING,
COL2 TYPE STRING,
END OF GTY_EXCEL.
DATA: GT_EXCEL TYPE TABLE OF GTY_EXCEL,
GS_EXCEL TYPE GTY_EXCEL.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = GT_RAW
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = GT_EXCEL
  EXCEPTIONS
CONVERSION_FAILED =
OTHERS =
.

3、类似函数

TEXT_CONVERT_CSV_TO_SAP
TEXT_CONVERT_TEX_TO_SAP
TEXT_CONVERT_TXT_TO_SAP
TEXT_CONVERT_XLS_TO_SAP
TEXT_CONVERT_XML_TO_SAP

SAP_CONVERT_TO_CSV_FORMAT
SAP_CONVERT_TO_TEX_FORMAT
SAP_CONVERT_TO_TXT_FORMAT
SAP_CONVERT_TO_XLS_FORMAT
SAP_CONVERT_TO_XML_FORMAT

上一篇:NSIS检测.NET Framework并在线下载


下一篇:折腾iPhone的生活——运营商信号显示数据化