说道SAP里对EXCEL操作的大概就是上传,下载,显示了。。。
下载:(文档是通过SMW0上传的)注:如果下载的时候需要填充EXCEL的值,。。。请参考另一篇文档,OLE
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 =
ERROR_NO_GUI =
NOT_SUPPORTED_BY_GUI =
OTHERS = .
IF LC_FULLPATH = ''.
MESSAGE '不能打开excel' TYPE 'E'.
ENDIF.
IF SY-SUBRC = .
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 = AND RELID = 'MI' AND OBJID = P_OBJID.
IF SY-SUBRC NE 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 .
CONCATENATE '模板文件:' LS_OBJNAM '下载失败' INTO LS_ERRTXT.
MESSAGE LS_ERRTXT TYPE 'E'.
ENDIF.
ENDIF.
上传:
选择屏上加个文件路径选择:
SELECTION-SCREEN:BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-.
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 = '选择文件'()
IMPORTING
FILENAME = P_FILE
EXCEPTIONS
INV_WINSYS =
NO_BATCH =
SELECTION_CANCEL =
SELECTION_ERROR =
OTHERS = .
IF SY-SUBRC <> .
MESSAGE E100(ZDEV) WITH '选择文件出错!'().
ENDIF.
ENDFORM.
然后就是或许EXCEL内容了
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = ''
I_BEGIN_ROW = ''
I_END_COL = ''
I_END_ROW = ''
TABLES
INTERN = GT_EXCEL_T.
这时候获取的EXCEL行,列,值
数据处理
LOOP AT GT_EXCEL_T INTO GS_EXCEL_T.
AT NEW ROW.
CLEAR:GW_EXCEL.
ENDAT.
CASE GS_EXCEL_T-COL.
WHEN .
GW_EXCEL-LIFNR = GS_EXCEL_T-VALUE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GW_EXCEL-LIFNR
IMPORTING
OUTPUT = GW_EXCEL-LIFNR.
WHEN .
GW_EXCEL-MATNR = GS_EXCEL_T-VALUE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = GW_EXCEL-MATNR
IMPORTING
OUTPUT = GW_EXCEL-MATNR.
WHEN .
GW_EXCEL-EKORG = GS_EXCEL_T-VALUE.
WHEN .
GW_EXCEL-WERKS = GS_EXCEL_T-VALUE.
WHEN .
GW_EXCEL-NETPR = GS_EXCEL_T-VALUE.
WHEN .
GW_EXCEL-KPEIN = GS_EXCEL_T-VALUE.
WHEN .
GW_EXCEL-LIFAB = GS_EXCEL_T-VALUE.
WHEN .
* GW_EXCEL-NORBM = GS_EXCEL_T-VALUE.
GW_EXCEL-LIFBI = GS_EXCEL_T-VALUE.
WHEN .
GW_EXCEL-MWSKZ = GS_EXCEL_T-VALUE.
WHEN OTHERS.
ENDCASE. AT END OF ROW.
APPEND GW_EXCEL TO GT_EXCEL.
ENDAT.
ENDLOOP.
这块可以优化,按自己的实际情况来