ABAP--通过OLE操作OFFICE(代码)本代码是通过OLE技术操作EXCEL,将SAP的数据填写到本地EXCEL中,Office运行在SAP的GUI界面外,注意红色代码。REPORTZRSDEMO01NOSTANDARDPAGEHEADING.*thisreportdemonstrateshowtosendsomeABAPdatatoan*EXCELsheetusingOLEautomation.*必须包含INCLUDEOLE2INCL.*handlesforOLEobjects*申明相关的OFFICE的OLE对象DATA:H_EXCELTYPEOLE2_OBJECT,ExcelobjectH_MAPLTYPEOLE2_OBJECT,listofworkbooksH_MAPTYPEOLE2_OBJECT,workbookH_ZLTYPEOLE2_OBJECT,cellH_FTYPEOLE2_OBJECT.fontTABLES:SPFLI.DATAHTYPEI.*tableofflightsDATA:IT_SPFLILIKESPFLIOCCURS10WITHHEADERLINE.*&---------------------------------------------------------------------**&EventSTART-OF-SELECTION*&---------------------------------------------------------------------*START-OF-SELECTION.*readflightsSELECT*FROMSPFLIINTOTABLEIT_SPFLIUPTO10ROWS.*telluserwhatisgoingonCALLFUNCTION'SAPGUI_PROGRESS_INDICATOR'EXPORTING*PERCENTAGE=0TEXT=TEXT-007EXCEPTIONSOTHERS=1.*startExcel(创建对象)CREATEOBJECTH_EXCEL'EXCEL.APPLICATION'.PERFORMERR_HDL.*设置office对象是否显示SETPROPERTYOFH_EXCEL'Visible'=1.PERFORMERR_HDL.*telluserwhatisgoingonCALLFUNCTION'SAPGUI_PROGRESS_INDICATOR'EXPORTING*PERCENTAGE=0TEXT=TEXT-008EXCEPTIONSOTHERS=1.*getlistofworkbooks,initiallyemptyCALLMETHODOFH_EXCEL'Workbooks'=H_MAPL.PERFORMERR_HDL.*addanewworkbookCALLMETHODOFH_MAPL'Add'=H_MAP.PERFORMERR_HDL.*telluserwhatisgoingonCALLFUNCTION'SAPGUI_PROGRESS_INDICATOR'EXPORTING*PERCENTAGE=0TEXT=TEXT-009EXCEPTIONSOTHERS=1.*outputcolumnheadingstoactiveExcelsheetPERFORMFILL_CELLUSING111'Flug'(001).PERFORMFILL_CELLUSING121'Nr'(002).PERFORMFILL_CELLUSING131'Von'(003).PERFORMFILL_CELLUSING141'Nach'(004).PERFORMFILL_CELLUSING151'Zeit'(005).LOOPATIT_SPFLI.*copyflightstoactiveEXCELsheetH=SY-TABIX+1.PERFORMFILL_CELLUSINGH10IT_SPFLI-CARRID.PERFORMFILL_CELLUSINGH20IT_SPFLI-CONNID.PERFORMFILL_CELLUSINGH30IT_SPFLI-CITYFROM.PERFORMFILL_CELLUSINGH40IT_SPFLI-CITYTO.PERFORMFILL_CELLUSINGH50IT_SPFLI-DEPTIME.ENDLOOP.*disconnectfromExcel*CALLMETHODOFH_EXCEL'QUIT'.FREEOBJECTH_EXCEL.PERFORMERR_HDL.*---------------------------------------------------------------------**FORMFILL_CELL**---------------------------------------------------------------------**setscellatcoordinatesi,jtovaluevalboldtypebold**---------------------------------------------------------------------*FORMFILL_CELLUSINGIJBOLDVAL.*getcellCALLMETHODOFH_EXCEL'Cells'=H_ZLEXPORTING#1=I#2=J.PERFORMERR_HDL.*setcellvalueSETPROPERTYOFH_ZL'Value'=VAL.PERFORMERR_HDL.*GetcellfontGETPROPERTYOFH_ZL'Font'=H_F.PERFORMERR_HDL.*setcellfontSETPROPERTYOFH_F'Bold'=BOLD.PERFORMERR_HDL.ENDFORM.*&---------------------------------------------------------------------**&FormERR_HDL*&---------------------------------------------------------------------**outputsOLEerrorifany**----------------------------------------------------------------------**--p1text*--p2text*----------------------------------------------------------------------*FORMERR_HDL.IFSY-SUBRC0.WRITE:/'FehlerbeiOLE-Automation:'(010),SY-SUBRC.STOP.ENDIF.ENDFORM.ERR_HDL相关链接:://blog.csdn.net/CompassButton/archive/2007/03/09/1524959.aspx