sap中Excel的模版上传和下载
一:事物码smw0
二:上传步骤
注:“包”为项目的包的名称。
三:下载代码
"-----------------------------------------@斌将军--------------------------------------------
*&---------------------------------------------------------------------* * 初始化 *&---------------------------------------------------------------------* SELECTION-SCREEN: FUNCTION KEY 1."定义按钮1 *&---------------------------------------------------------------------* * INITIALIZATION:启动程序开始执行,初始话数据 *&---------------------------------------------------------------------* INITIALIZATION. SSCRFIELDS-FUNCTXT_01 = '下载配置导入模板'. AT SELECTION-SCREEN. "下载模板 CASE SSCRFIELDS-UCOMM. WHEN 'FC01'. PERFORM FRM_DOWNLAOD_EXCEL." 下载模板 WHEN OTHERS. ENDCASE.
"-----------------------------------------@斌将军--------------------------------------------
"-----------------------------------------@斌将军--------------------------------------------
*&---------------------------------------------------------------------* *& Form FRM_DOWNLAOD_EXCEL *&---------------------------------------------------------------------* * 下载模板 *----------------------------------------------------------------------* FORM FRM_DOWNLAOD_EXCEL. DATA:LV_FNAME TYPE STRING, LV_INIT_PATH TYPE STRING, LV_TITLE TYPE STRING, LV_PATH TYPE STRING," VALUE 'D:/', LV_FPATH TYPE STRING," VALUE 'D:/', LV_FILE TYPE RLGRAP-FILENAME. DATA:LV_OBJID TYPE CHAR20, LS_WDATB LIKE WWWDATATAB, LV_SUBRC TYPE SY-SUBRC, LV_MSG TYPE STRING. LV_OBJID = 'ZRMM492'. LV_FNAME = '配置设计确认导入模板'. CONCATENATE LV_FNAME '下载' INTO LV_TITLE. "获取桌面路径 CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_DESKTOP_DIRECTORY CHANGING DESKTOP_DIRECTORY = LV_INIT_PATH EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 NOT_SUPPORTED_BY_GUI = 3 OTHERS = 4. IF SY-SUBRC <> 0. EXIT. ENDIF. "保存文件 CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG EXPORTING WINDOW_TITLE = LV_TITLE DEFAULT_EXTENSION = 'xls' DEFAULT_FILE_NAME = LV_FNAME INITIAL_DIRECTORY = LV_INIT_PATH FILE_FILTER = 'EXCEL文件(*.xls)||全部文件(*.*)||' PROMPT_ON_OVERWRITE = 'X' CHANGING FILENAME = LV_FNAME PATH = LV_PATH FULLPATH = LV_FPATH EXCEPTIONS CNTL_ERROR = 1 ERROR_NO_GUI = 2 NOT_SUPPORTED_BY_GUI = 3 OTHERS = 4. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ELSE. CLEAR:LV_FILE. LV_FILE = LV_FPATH. IF LV_FILE IS NOT INITIAL. "判断文件模板是否存在 SELECT SINGLE RELID OBJID FROM WWWDATA INTO CORRESPONDING FIELDS OF LS_WDATB WHERE SRTF2 = 0 AND RELID = 'MI' AND OBJID = LV_OBJID. IF LS_WDATB IS INITIAL. MESSAGE '模板不存在' TYPE 'E'. ELSE. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' EXPORTING KEY = LS_WDATB DESTINATION = LV_FILE IMPORTING RC = LV_SUBRC. IF LV_SUBRC <> 0. MESSAGE '模板下载失败' TYPE 'E'. ELSE. CLEAR:LV_MSG. CONCATENATE '模板下载到本地文件' LV_FILE INTO LV_MSG. MESSAGE LV_MSG TYPE 'S'. ENDIF. ENDIF. ELSE. MESSAGE '用户取消操作' TYPE 'S' . RETURN. ENDIF. ENDIF. ENDFORM. "FRM_DOWNLAOD_EXCEL
"-----------------------------------------@斌将军--------------------------------------------