ABAP:如何把excel中的文件导入到内表中

 
如何把EXCEL文件导入ABAP内表中?
可以使用功能模块ALSM_EXCEL_TO_INTERNAL_TABLE 读取excel文件中的内容,放入类型为alsmex_tabline的内中。然后你可以把这个表中的内容插入到你想放入的内表中:

REPORT ZIMPEXCEL .
TYPES: BEGIN OF ty_upload,
         field1(12) TYPE c,
         field2(12) TYPE c,
         field3(12) TYPE c,
       END OF ty_upload.

DATA: it_upload TYPE STANDARD TABLE OF ty_upload,
      wa_upload TYPE ty_upload,
      itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY.

FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  EXPORTING
    FILENAME                      = 'c:/test.xls'
    I_BEGIN_COL                   = 1
    I_BEGIN_ROW                   = 1
    I_END_COL                     = 3
    I_END_ROW                     = 65535
  TABLES
    INTERN                        = itab
  EXCEPTIONS
    INCONSISTENT_PARAMETERS       = 1
    UPLOAD_OLE                    = 2
    OTHERS                        = 3.
IF SY-SUBRC <> 0.
ENDIF.
SORT itab BY row.
LOOP AT itab ASSIGNING <wa_itab>.
  CASE <wa_itab>-col.
  WHEN '0001'.
    wa_upload-field1 = <wa_itab>-value.
  WHEN '0002'.
    wa_upload-field2 = <wa_itab>-value.
  WHEN '0003'.
    wa_upload-field3 = <wa_itab>-value.
  ENDCASE.
  AT END OF row.
    APPEND wa_upload TO it_upload.
    CLEAR wa_upload.
  ENDAT.
ENDLOOP.
 

发布了274 篇原创文章 · 获赞 4 · 访问量 49万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览