SMW0 上传EXCEL 文件以及在系统中调用
作者:侯志宇
日期:2009-6-2
一、上传文件
1、输入SMW0,选择二进制数据
2、回车,直接执行(如有已经创建了则直接输入对象名)
3、如果已经建立了则直接选中编辑即可,如果没有则需要新建
4、输入对象名称以及描述,然后选择模版即可
二、代码调用
*---excel 下载专用
constants:
CO_OBJID type WWWDATATAB-OBJID value 'ZHRR0025'. "模板对象的ID
data
CS_PATH type STRING .
data: LW_REPID type DISEXTRACT."SY-REPID.
data: P_FILENAME type SAPB-SAPPFAD.
concatenate CS_PATH 'ZHRR0025.XLS' into CS_PATH."CS_PATH.是模版要存放的路径
perform FRM_DOWNLOAD_WORD_FROMSERVER using CO_OBJID CS_PATH.
form FRM_DOWNLOAD_WORD_FROMSERVER
using P_OBJID like WWWDATATAB-OBJID
P_DEST type STRING ."likeSAPB-SAPPFAD
data: LO_OBJDATA like WWWDATATAB,
LO_MIME like W3MIME,
LS_DESTINATION like RLGRAP-FILENAME,
LS_OBJNAM type STRING,
LI_RC like SY-SUBRC,
LS_ERRTXT type STRING.
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 '不存在,请用TCODE:SMW0 进行加载' into
LS_ERRTXT.
message E001(00) with LS_ERRTXT.
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.
endform. "FRM_DOWNLOAD_WORD_FROMSERVER
作者:侯志宇
日期:2009-6-2
一、上传文件
1、输入SMW0,选择二进制数据
2、回车,直接执行(如有已经创建了则直接输入对象名)
3、如果已经建立了则直接选中编辑即可,如果没有则需要新建
4、输入对象名称以及描述,然后选择模版即可
二、代码调用
*---excel 下载专用
constants:
CO_OBJID type WWWDATATAB-OBJID value 'ZHRR0025'. "模板对象的ID
data
CS_PATH type STRING .
data: LW_REPID type DISEXTRACT."SY-REPID.
data: P_FILENAME type SAPB-SAPPFAD.
concatenate CS_PATH 'ZHRR0025.XLS' into CS_PATH."CS_PATH.是模版要存放的路径
perform FRM_DOWNLOAD_WORD_FROMSERVER using CO_OBJID CS_PATH.
form FRM_DOWNLOAD_WORD_FROMSERVER
using P_OBJID like WWWDATATAB-OBJID
P_DEST type STRING ."likeSAPB-SAPPFAD
data: LO_OBJDATA like WWWDATATAB,
LO_MIME like W3MIME,
LS_DESTINATION like RLGRAP-FILENAME,
LS_OBJNAM type STRING,
LI_RC like SY-SUBRC,
LS_ERRTXT type STRING.
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 '不存在,请用TCODE:SMW0 进行加载' into
LS_ERRTXT.
message E001(00) with LS_ERRTXT.
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 E001(00) with LS_ERRTXT.
else.
"自动打开excel
INCLUDE OLE2INCL.
DATA: G_OBJ_EXCEL TYPE OLE2_OBJECT,
G_OBJ_BOOK TYPE OLE2_OBJECT,
G_OBJ_SHEET TYPE OLE2_OBJECT,
G_OBJ_CELL TYPE OLE2_OBJECT,
G_OBJ_FONT TYPE OLE2_OBJECT.
CREATE OBJECT G_OBJ_EXCEL 'EXCEL.APPLICATION'.
SET PROPERTY OF G_OBJ_EXCEL 'VISIBLE' = 0.
CALL METHOD OF
G_OBJ_EXCEL
'WORKBOOKS' = G_OBJ_BOOK.
CALL METHOD OF
G_OBJ_BOOK
'Open'
EXPORTING
#1 = P_DEST.
SET LANGUAGE '1'.
FREE OBJECT G_OBJ_EXCEL.
FREE OBJECT G_OBJ_BOOK.
endform. "FRM_DOWNLOAD_WORD_FROMSERVER