首页 > 代码库 > 一个上传EXCEL导入示例
一个上传EXCEL导入示例
REPORT ZTEST_UPEXCEL.data: gt_table type TABLE OF SFLIGHT, gs_table like line of gt_table.DATA:lt_excel TYPE TABLE OF ZSTABLINE.DATA ls_excel LIKE LINE OF lt_excel.FIELD-SYMBOLS:<fs>.CONSTANTS: gc_begin_row TYPE i VALUE 1,"Beginning row of excel file gc_begin_col TYPE i VALUE 1, "Beginning column of excel file gc_end_row TYPE i VALUE 999, "Ending row of excel file gc_end_col TYPE i VALUE 999."Ending column of excel filePARAMETERS: p_file LIKE rlgrap-filename. "定义存放上传文件路径名的变量initialization.at selection-screen on VALUE-REQUEST FOR p_file. "这个只用在批处理这边 PERFORM sub_find USING p_file.start-of-selection. CALL FUNCTION ‘ZALSM_EXCEL_TO_INTERNAL_TABLE‘ EXPORTING filename = p_file i_begin_col = 1"gc_begin_row‘ i_begin_row = 1"gc_begin_col i_end_col = 999"gc_end_row i_end_row = 999"gc_end_col TABLES intern = lt_excel* EXCEPTIONS* INCONSISTENT_PARAMETERS = 1* UPLOAD_OLE = 2* OTHERS = 3 . IF sy-subrc <> 0.* Implement suitable error handling here ENDIF. LOOP AT lt_excel INTO ls_excel. ASSIGN COMPONENT ls_excel-col OF STRUCTURE gs_table to <fs>. "把工作区gs_tab中的字段赋给字段符号,而工作区gs_tab中的字段取决于内表中的列ls_excel-col CONDENSE ls_excel-value. " 去掉空格 <fs> = ls_excel-value. at end of row. "如果是最后一行就把工作区gs_tab存到内表gt_tab中 "gs_tab-row = ls_excel-row. APPEND gs_table TO gt_table. CLEAR: gs_table. ENDAT. ENDLOOP. INSERT SFLIGHT FROM TABLE GT_TABLE ACCEPTING DUPLICATE KEYS. IF SY-SUBRC = 0. COMMIT WORK. MESSAGE ‘维护成功‘ type ‘S‘. ENDIF.*&---------------------------------------------------------------------**& Form SUB_FIND*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->P_P_FILE text*----------------------------------------------------------------------*FORM SUB_FIND USING P_P_FILE.* DATA: LD_DEFAULT_EXTENSION TYPE STRING VALUE ‘CSV‘. DATA: LT_FILE_TAB TYPE FILETABLE. DATA: LS_FILE_LINE TYPE FILE_TABLE. DATA: LD_RC TYPE I, LW_TITLE TYPE STRING, LW_FILTER TYPE STRING.* 变量赋值 LW_TITLE = ‘选择文件‘. LW_FILTER = ‘Excel文件|*.xl;*.xls;*.xlsx|‘. CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG EXPORTING WINDOW_TITLE = LW_TITLE FILE_FILTER = LW_FILTER INITIAL_DIRECTORY = ‘C:\‘ CHANGING FILE_TABLE = LT_FILE_TAB RC = LD_RC EXCEPTIONS FILE_OPEN_DIALOG_FAILED = 1 CNTL_ERROR = 2 ERROR_NO_GUI = 3 NOT_SUPPORTED_BY_GUI = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ELSE. CHECK LD_RC = 1. READ TABLE LT_FILE_TAB INTO LS_FILE_LINE INDEX 1. CHECK SY-SUBRC = 0. MOVE LS_FILE_LINE-FILENAME TO p_file. ENDIF. " F4_FOR_FILESENDFORM. " SUB_FIND
一个上传EXCEL导入示例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。