资源描述:
《用oledoi实现abap导出excel表格》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、OLE导出:sap中abap导出excel的方法很多,ole是其中一种,但其导出速度比较慢,一般只应用于对excel格式有特别要求的场所REPORTYGL_MYOLE.INCLUDEOLE2INCL.*OLEOBJECTDATA:MYEXCELTYPEOLE2_OBJECT,MYSHEETTYPEOLE2_OBJECT,MYCELLTYPEOLE2_OBJECT,MYWORKBOOKTYPEOLE2_OBJECT..................................*创建excel进程CREATEOBJEC
2、TMYEXCEL'EXCEL.APPLICATION'.*创建工作表CALLMETHODOFMYEXCEL'WORKBOOKS'=MYWORKBOOK.*创建sheet并添加到工作表SETPROPERTYOFMYEXCEL'SHEETSINNEWWORKBOOK'=1.CALLMETHODOFMYWORKBOOK'ADD'.*选中excel中的cell,第一行的第二列。CALLMETHODOFMYEXCEL'CELLS'=MYCELLEXPORTING#1=1#2=2.*设置被选中的cell的值SETPROTERTYOF
3、MYCELL'VALUE'='HELLOWORD'."你要输出的内容GETPROPERTYOFMYEXCEL'ACTIVESHEET'=MYSHEET.GETPROPERTYOFMYEXCEL'ACTIVEWORKBOOK'=MYWORKBOOK.*保存文件CALLMETHODOFMYWORKBOOK'SAVEAS'EXPORTING#1='C:TMPAA.XLS'#2=1.CALLMETHODOFMYWORKBOOK'CLOSE'.*退出excelCALLMETHODOFMYEXCEL'QUIT'.*释放对象FRE
4、EOBJECTMYSHEET.FREEOBJECTMYWORKBOOK.FREEOBJECTMYEXCEL.*******************************************************************************实例:TYPE-POOLS:ole2,slis.DEFINEadd_field.wa_field-fieldname=&1.wa_field-reptext_ddic=&2.wa_field-no_zero='X'."去掉0*WA_FIELD_EIDT='X'
5、.appendwa_fieldtoit_field.END-OF-DEFINITION.*定义变量和字段组DATA:g_repidTYPEsy-repid,gs_layoutTYPEslis_layout_alv,wa_fieldTYPEslis_fieldcat_alv,it_fieldTYPEslis_t_fieldcat_alv.********************************************************************************OLEEXCEL变量DATA
6、:excelTYPEole2_object,workbookTYPEole2_object,sheetTYPEole2_object,cellTYPEole2_object.*CELL1TYPEOLE2_OBJECT,*COLUMNTYPEOLE2_OBJECT,*RANGETYPEOLE2_OBJECT,*BORDERSTYPEOLE2_OBJECT,*buttonTYPEOLE2_OBJECT,*intTYPEOLE2_OBJECT,*FONTTYPEOLE2_OBJECT.*ROWTYPEOLE2_OBJECT.*
7、填充单元格FORMfill_cellUSINGijval.*CALLMETHODOFEXCEL'COLUMNS'=COLUMN.*CALLMETHODOFCOLUMN'AUTOFIT'."导出EXCEL自动适应宽度CALLMETHODOFexcel'CELLS'=cellNOFLUSHEXPORTING#1=i#2=j.SETPROPERTYOFcell'VALUE'=valnoflush.FREEOBJECTcellNOFLUSH.*GETPROPERTYOFCELL'FONT'=FONT.*SETPROPERTYOF
8、FONT'BOLD'=BOLD.ENDFORM."FILL_CELL*处理进度条FORMp_processUSINGi_processedLIKEsy-tabixi_totalLIKEsy-tabix.DATA:i_percentTYPEi,i_text2(72)TYPEc,i_timesTYPEi,i_proc(1