CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
DEFAULT_EXTENSION = ‘xlsx‘
DEFAULT_FILE_NAME = LC_FILENAME
CHANGING
FILENAME = LC_FILENAME
PATH = LC_PATH
FULLPATH = LC_FULLPATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF LC_FULLPATH = ‘‘.
MESSAGE ‘不能打开excel‘ TYPE ‘E‘.
ENDIF.
IF SY-SUBRC = 0.
P_DEST = LC_FULLPATH.
* concatenate p_objid ‘.XLS‘ into ls_objnam.
CONDENSE LS_OBJNAM NO-GAPS.
SELECT SINGLE RELID OBJID FROM WWWDATA INTO CORRESPONDING FIELDS OF LO_OBJDATA
WHERE SRTF2 = 0 AND RELID = ‘MI‘ AND OBJID = P_OBJID.
IF SY-SUBRC NE 0 OR LO_OBJDATA-OBJID EQ SPACE.
CONCATENATE ‘模板文件‘ LS_OBJNAM ‘不存在‘ INTO LS_ERRTXT.
MESSAGE LS_ERRTXT TYPE ‘I‘.
ENDIF.
LS_DESTINATION = P_DEST.
CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT‘
EXPORTING
KEY = LO_OBJDATA
DESTINATION = LS_DESTINATION
IMPORTING
RC = LI_RC.
IF LI_RC NE 0.
CONCATENATE ‘模板文件:‘ LS_OBJNAM ‘下载失败‘ INTO LS_ERRTXT.
MESSAGE LS_ERRTXT TYPE ‘E‘.
ENDIF.
ENDIF.
SELECTION-SCREEN:BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-001.
PARAMETERS:P_FILE LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK BLK01.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FRM_GET_FILEPATH.
FORM FRM_GET_FILEPATH .
CALL FUNCTION ‘WS_FILENAME_GET‘
EXPORTING
MASK = ‘,Excel(*.xls),*.XLS,*.XLSX,‘
TITLE = ‘选择文件‘(100)
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE E100(ZDEV) WITH ‘选择文件出错!‘(007).
ENDIF.
ENDFORM.
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE‘
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = ‘1‘
I_BEGIN_ROW = ‘2‘
I_END_COL = ‘300‘
I_END_ROW = ‘50000‘
TABLES
INTERN = GT_EXCEL_T.
LOOP AT GT_EXCEL_T INTO GS_EXCEL_T.
AT NEW ROW.
CLEAR:GW_EXCEL.
ENDAT.
CASE GS_EXCEL_T-COL.
WHEN 1.
GW_EXCEL-LIFNR = GS_EXCEL_T-VALUE.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = GW_EXCEL-LIFNR
IMPORTING
OUTPUT = GW_EXCEL-LIFNR.
WHEN 2.
GW_EXCEL-MATNR = GS_EXCEL_T-VALUE.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = GW_EXCEL-MATNR
IMPORTING
OUTPUT = GW_EXCEL-MATNR.
WHEN 3.
GW_EXCEL-EKORG = GS_EXCEL_T-VALUE.
WHEN 4.
GW_EXCEL-WERKS = GS_EXCEL_T-VALUE.
WHEN 5.
GW_EXCEL-NETPR = GS_EXCEL_T-VALUE.
WHEN 6.
GW_EXCEL-KPEIN = GS_EXCEL_T-VALUE.
WHEN 7.
GW_EXCEL-LIFAB = GS_EXCEL_T-VALUE.
WHEN 8.
* GW_EXCEL-NORBM = GS_EXCEL_T-VALUE.
GW_EXCEL-LIFBI = GS_EXCEL_T-VALUE.
WHEN 9.
GW_EXCEL-MWSKZ = GS_EXCEL_T-VALUE.
WHEN OTHERS.
ENDCASE.
AT END OF ROW.
APPEND GW_EXCEL TO GT_EXCEL.
ENDAT.
ENDLOOP.