X-DOC:SMW0 - Excel 导入模板的上传和下载
- 1、实现效果
- 2、模板上传
- 3、下载功能代码
做批导程序,离不开 Excel 导入模板,为了方便用户,一般会将模板文档整合到导入功能的界面上,方便用户获取模板。
1、实现效果
2、模板上传
执行事务码:SMW0
3、下载功能代码
TABLES: sscrfields.
SELECTION-SCREEN: FUNCTION KEY 1.
INITIALIZATION.
sscrfields-functxt_01 = VALUE smp_dyntxt( icon_id = '@49@' quickinfo = '模板下载' icon_text = '模板下载' ).
AT SELECTION-SCREEN.
IF sy-ucomm = 'FC01'.
DATA:lv_rc TYPE i,
lv_filename TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string,
lv_objdata TYPE wwwdatatab.
lv_filename = |ZBCB001角色批导入模板|.
cl_gui_frontend_services=>file_save_dialog(
EXPORTING
window_title = 'ZBCB001角色批导入模板'
default_extension = 'XLSX' "默认保存文件格式
default_file_name = lv_filename "默认文件名称
CHANGING
filename = lv_filename "默认文件名称
path = lv_path "文件路径
fullpath = lv_fullpath "文件路径
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4
).
CHECK lv_fullpath IS NOT INITIAL.
FREE:lv_objdata,lv_rc.
SELECT SINGLE relid objid INTO CORRESPONDING FIELDS OF lv_objdata
FROM wwwdata WHERE srtf2 = 0 AND relid = 'MI' AND objid = 'ZBCB001'.
IF sy-subrc EQ 0.
TRANSLATE lv_fullpath TO UPPER CASE.
REPLACE 'XLS' WITH 'XLSX' INTO lv_fullpath.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lv_objdata
destination = CONV localfile( lv_fullpath ) " 'C:\Temp\test************.xls' .
IMPORTING
rc = lv_rc.
IF lv_rc EQ 0.
MESSAGE '模板下载成功' TYPE if_mmpur_constants_general=>msg_success.
ELSE.
MESSAGE '模板下载失败' TYPE if_mmpur_constants_general=>msg_success DISPLAY LIKE if_mmpur_constants_general=>msg_error.
ENDIF.
ELSE.
ENDIF.
ENDIF.
原创文章,转载请注明来源-X档案