首页 > 代码库 > EXCEL上传DEMO
EXCEL上传DEMO
DATA: filetab TYPE filetable WITH HEADER LINE .
DATA: rc TYPE i.
DATA: outtab TYPE TABLE OF mara WITH HEADER LINE .
DATA: itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
DATA:g_file TYPE rlgrap-filename.
FIELD-SYMBOLS: <fs>.
PARAMETERS: p_file TYPE string.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
default_filename = p_file
CHANGING
rc = rc
file_table = filetab[].
READ TABLE filetab INDEX 1.
IF sy-subrc EQ 0.
p_file = filetab-filename.
ENDIF.
START-OF-SELECTION.
g_file = p_file. "注意两个文件用于不同的函数,所以类型不同
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE‘
EXPORTING
filename = g_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 255
i_end_row = 65536
TABLES
intern = itab[].
DELETE itab WHERE row = 1. "删除字段名行
LOOP AT itab.
ON CHANGE OF itab-row.
IF sy-tabix NE 1.
APPEND outtab.
CLEAR outtab.
ENDIF.
ENDON.
ASSIGN COMPONENT itab-col OF STRUCTURE outtab TO <fs>. "动态方法将值传到相应的内表
<fs> = itab-value.
ENDLOOP.
APPEND outtab. "这句不要忘记,要把最后一条APPEND到内表中
EXCEL上传DEMO