主要实现代码:
FM:Z_USE_OLE的介绍。
"---------------------------------------------------------------------- ""本地接口: " IMPORTING
" VALUE(I_OBJECT_ID) " VALUE(I_TITLE) OPTIONAL
" TABLES " T_HEADER OPTIONAL
*" T_ITEM OPTIONAL
目前只支持两种模式 word 和 excle如果是PDF的话PC端要安装 adobe reader
*"----------------------------------------------------------------------IF I_OBJECT_ID IS INITIAL.
RAISE OBJECT_ID_ERROR.
ENDIF.
PERFORM INIT_FACTORY USING I_TITLE.
PERFORM OPEN_DOC TABLES T_HEADERT_ITEM USING I_OBJECT_ID.
ENDFUNCTION.
&---------------------------------------------------------------------
& Form INIT_FACTORY &---------------------------------------------------------------------*
FORM INIT_FACTORY USING P_TITLE.
IF FACTORY IS INITIAL.
CALL METHOD C_OI_FACTORY_CREATOR=>GET_DOCUMENT_FACTORY
IMPORTING
FACTORY = FACTORY
RETCODE = RETCODE.
IF RETCODE NE C_OI_ERRORS=>RET_OK.
EXIT.
ENDIF.
CALL METHOD FACTORY->START_FACTORY
EXPORTING
R3_APPLICATION_NAME = P_TITLE
IMPORTING
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
CALL METHOD FACTORY->GET_LINK_SERVER
IMPORTING
LINK_SERVER = LINK_SERVER
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
CALL METHOD LINK_SERVER->START_LINK_SERVER
EXPORTING
LINK_SERVER_MODE = 3
IMPORTING
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
ENDIF. "factory IS INITIAL.
ENDFORM. " INIT_FACTORY
&---------------------------------------------------------------------
& Form OPEN_DOC &---------------------------------------------------------------------*
FORM OPEN_DOC TABLES HEADER
ITEM
USING P_OBJECT_ID.
DATA : a(8) TYPE C.
DEFINE M_LINK_TAB.
CALL METHOD link_server->add_table_item2
EXPORTING
item_name = &1
IMPORTING
retcode = retcode
CHANGING
data_table = &2.
CALL METHOD c_oi_errors=>show_message
EXPORTING
TYPE = 'E'.
END-OF-DEFINITION.
IF NOT LINK_SERVER IS INITIAL.
M_LINK_TAB 'HEADER' HEADER[].
M_LINK_TAB 'ITEM' ITEM[].
ENDIF.
- SAP ### ## EXCEL ## OPEN
CALL FUNCTION 'SAP_OI_LOAD_MIME_DATA'
EXPORTING
OBJECT_ID = P_OBJECT_ID
IMPORTING
DATA_SIZE = DOC_SIZE
DOCUMENT_FORMAT = DOC_FORMAT
DOCUMENT_TYPE = DOC_TYPE
TABLES
DATA_TABLE = DOC_TABLE
EXCEPTIONS
OBJECT_NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
SELECT SINGLE VALUE INTO @DAta(lv_TYPE) FROM WWWPARAMS WHERE OBJID = @P_OBJECT_ID AND NAME = 'mimetype'.
CASE lv_TYPE.
WHEN 'PDF'.
DOC_TYPE = 'AcroExch.acrobatsecuritysettings.1'.
WHEN 'WORD'.
DOC_TYPE = 'Word.Document.12'.
WHEN OTHERS.
ENDCASE.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF DOC_SIZE NE 0.
CALL METHOD FACTORY->GET_DOCUMENT_PROXY
EXPORTING
DOCUMENT_TYPE = DOC_TYPE
IMPORTING
DOCUMENT_PROXY = DOCUMENT
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
Document# Protected Mode# Open## #### ###.
CALL METHOD DOCUMENT->OPEN_DOCUMENT_FROM_TABLE
EXPORTINGDOCUMENT_TABLE = DOC_TABLE[] DOCUMENT_SIZE = DOC_SIZE
IMPORTING
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTINGTYPE = 'E'.
ENDIF.
ENDFORM. " OPEN_DOC
&---------------------------------------------------------------------
& Form MACRO &---------------------------------------------------------------------
FORM MACRO .
CALL METHOD DOCUMENT->EXECUTE_MACRO
EXPORTING
MACRO_STRING = 'R3_MACRO1'
IMPORTING
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
ENDFORM. " MACRO &--------------------------------------------------------------------- & Form CLOSE_DOC
&---------------------------------------------------------------------
FORM CLOSE_DOC .
IF NOT DOCUMENT IS INITIAL.
CALL FUNCTION 'WS_FILE_DELETE'
EXPORTING
FILE = 'C:\PIC.JPG'.
CALL METHOD DOCUMENT->IS_DESTROYED
IMPORTING
RET_VALUE = IS_CLOSED.
IF IS_CLOSED IS INITIAL.
CALL METHOD DOCUMENT->CLOSE_DOCUMENT
EXPORTING
DO_SAVE = 'X'
IMPORTING
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
ENDIF.
CALL METHOD DOCUMENT->RELEASE_DOCUMENT
IMPORTING
RETCODE = RETCODE.
CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
EXPORTING
TYPE = 'E'.
FREE DOCUMENT.
ENDIF.
ENDFORM. " CLOSE_DOC
&---------------------------------------------------------------------
& Form CLOSE_FACTORY &---------------------------------------------------------------------*
FORM CLOSE_FACTORY .
IF NOT LINK_SERVER IS INITIAL.
CALL METHOD LINK_SERVER->STOP_LINK_SERVER
IMPORTING
RETCODE = RETCODE.
FREE LINK_SERVER.
ENDIF.
IF NOT FACTORY IS INITIAL.
CALL METHOD FACTORY->STOP_FACTORY
IMPORTING
RETCODE = RETCODE.
FREE FACTORY.
ENDIF.
ENDFORM. " CLOSE_FACTORY