SAP ABAP如何将内表的数据导出到EXCEL

 我来答
泰融桖9K
推荐于2016-04-28 · TA获得超过349个赞
知道答主
回答量:159
采纳率:100%
帮助的人:64.8万
展开全部
SORT IT_DATA BY BNAME. INCLUDE OLE2INCL. "定义OLE变量DATA: EXCEL TYPE OLE2_OBJECT, SHEET TYPE OLE2_OBJECT, CELL TYPE OLE2_OBJECT, WORKBOOK TYPE OLE2_OBJECT, XLSNAME TYPE STRING VALUE 'C:\sap_usr02.xls', LINE TYPE I VALUE 0. "行号CREATE OBJECT EXCEL 'EXCEL.APPLICATION'."启动ExcelIF SY-SUBRC NE 0. WRITE: / '启动Excel失败。'. STOP.ENDIF.CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOK.SET PROPERTY OF EXCEL 'VISIBLE' = 1. "使excel 可视SET PROPERTY OF EXCEL 'SHEETSINNEWWORKBOOK' = 1. "如果是读取excel文件中的内容 则是直接打开工作簿第一页CALL METHOD OF WORKBOOK 'ADD'. "例如:CALL METHOD OF EXCEL 'WORKSHEETS' = SHEET EXPORTING #1 = 1.LOOP AT IT_DATA INTO MY_DATA. LINE = LINE + 1. "Excel 中行号从1开始 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 1. "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-MANDT. "写入值 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 2. "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-BNAME. "写入值 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 3. "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-ERDAT. "写入值 CALL METHOD OF EXCEL 'CELLS' = CELL EXPORTING #1 = LINE #2 = 4. "指定单元格, SET PROPERTY OF CELL 'VALUE' = MY_DATA-LTIME. "写入值ENDLOOP.GET PROPERTY OF EXCEL 'ACTIVESHEET' = SHEET. "激活工作簿GET PROPERTY OF EXCEL 'ACTIVEWORKBOOK' = WORKBOOK. "激活工作区CALL METHOD OF WORKBOOK 'SAVEAS' EXPORTING #1 = XLSNAME #2 = 1. "将excel文件保存CALL METHOD OF WORKBOOK 'CLOSE'. "关闭工作区CALL METHOD OF EXCEL 'QUIT'. "退出excel*WRITE:/ XLSNAME,'DONE'. "退出成功,输出doneFREE OBJECT SHEET. "释放操作FREE OBJECT WORKBOOK.FREE OBJECT EXCEL.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式