Excel文件上传
1 *&---------------------------------------------------------------------* 2 *& FORM FRM_UPDATA_EXCEL 3 *&---------------------------------------------------------------------* 4 * TEXT 5 *----------------------------------------------------------------------* 6 * --> P1 TEXT 7 * <-- P2 TEXT 8 *----------------------------------------------------------------------* 9 FORM FRM_UPDATA_EXCEL . 10 IF P_FILE IS INITIAL. 11 MESSAGE '请输入导入文件的路径' TYPE 'I'. 12 LEAVE TO TRANSACTION SY-TCODE. 13 ENDIF. 14 15 DATA: BEGIN OF I_EXCEL OCCURS 0. 16 INCLUDE STRUCTURE ALSMEX_TABLINE. 17 DATA: END OF I_EXCEL. 18 19 DATA: L_ANSWER(1) TYPE C, 20 L_COLUMN TYPE I. 21 22 FIELD-SYMBOLS: <FS>. 23 DATA: L_PATHNAME LIKE RLGRAP-FILENAME. 24 DATA: 25 C_BEGIN_ROW TYPE I VALUE 3, "Beginning row of excel file 26 C_BEGIN_COL TYPE I VALUE 1, "Beginning column of excel file 27 C_END_ROW TYPE I VALUE 10000, "Ending row of excel file 28 C_END_COL TYPE I VALUE 4. "Ending column of excel file 29 30 MOVE P_FILE TO L_PATHNAME. 31 32 CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' 33 EXPORTING 34 FILENAME = L_PATHNAME 35 I_BEGIN_COL = C_BEGIN_COL 36 I_BEGIN_ROW = C_BEGIN_ROW 37 I_END_COL = C_END_COL 38 I_END_ROW = C_END_ROW 39 TABLES 40 INTERN = I_EXCEL 41 EXCEPTIONS 42 INCONSISTENT_PARAMETERS = 1 43 UPLOAD_OLE = 2 44 OTHERS = 3. 45 IF SY-SUBRC <> 0. 46 MESSAGE '打开EXCEL文件出错!' TYPE 'E'. 47 ELSE. 48 IF I_EXCEL[] IS INITIAL. 49 CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE' 50 EXPORTING 51 DIAGNOSETEXT1 = '数据为空!' 52 TEXTLINE1 = '请检查文件是否正确' 53 TITEL = '警告' 54 IMPORTING 55 ANSWER = L_ANSWER. 56 LEAVE TO TRANSACTION SY-TCODE. 57 ELSE. 58 59 DELETE I_EXCEL WHERE ROW = '0001'. 60 SORT I_EXCEL BY ROW COL. 61 LOOP AT I_EXCEL. 62 MOVE I_EXCEL-COL TO L_COLUMN. 63 ASSIGN COMPONENT L_COLUMN OF STRUCTURE IW_ANLA TO <FS>. 64 MOVE I_EXCEL-VALUE TO <FS>. 65 AT END OF ROW. 66 APPEND IW_ANLA TO IT_ANLA. 67 CLEAR IW_ANLA. 68 ENDAT. 69 ENDLOOP. 70 ENDIF. 71 ENDIF. 72 73 ENDFORM. "FRM_UPDATA_EXCEL