|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
ABAP操作Excel表_蓝色理想_百度空间 用户名: 密码: 登录 注册 蓝色理想专注 专业 专心 主页博客相册|个人档案 |好友
查看文章
ABAP操作Excel表2008年06月16日 星期一 14:22tables KNA1.
INCLUDE OLE2INCL.
DATA: APPLICATION TYPE OLE2_OBJECT,
WORKBOOK TYPE OLE2_OBJECT,
SHEET TYPE OLE2_OBJECT,
CELLS TYPE OLE2_OBJECT.
data vfile(128) value 'c:\test123.xls'.
data : begin of t_kna1 occurs 0 ,
kunnr like kna1-kunnr,
name1 like kna1-name1,
name2 like kna1-name2,
end of t_kna1.
CREATE OBJECT APPLICATION 'Excel.application'.
SET PROPERTY OF APPLICATION 'Visible' = 0.
* 1 display
* 宣告一EXCEL工作底槁档(WORKBOOK)
CALL METHOD OF APPLICATION 'Workbooks' = WORKBOOK.
* 增加一新的工作表(SHEET),编号是 1 号
CALL METHOD OF WORKBOOK 'Add'.
CALL METHOD OF APPLICATION 'Worksheets' = SHEET
EXPORTING #1 = 1.
* 设定此工作表开启使用
CALL METHOD OF SHEET 'Activate'.
PERFORM FILL_SHEET.
SET PROPERTY OF APPLICATION 'DisplayAlerts' = 'false'.
CALL METHOD OF SHEET 'SAVEAS'
EXPORTING
#1 = vfile
#2 = 1.
SET PROPERTY OF APPLICATION 'Visible' = 1.
*CALL METHOD OF APPLICATION 'QUIT'.
*CALL METHOD OF APPLICATION 'EXIT'.
****关闭WORKSHEET****
CALL METHOD OF SHEET 'CLOSE'.
****关闭WORKBOOK
CALL METHOD OF WORKBOOK 'CLOSE'.
****关闭EXCEL对象****
CALL METHOD OF APPLICATION 'QUIT'.
FREE OBJECT CELLS.
FREE OBJECT SHEET.
FREE OBJECT WORKBOOK.
FREE OBJECT APPLICATION.
*SET PROPERTY OF APPLICATION 'Visible' = 1.
*----------------------------------------------------------------------------------------------------------------
FORM FILL_SHEET.
DATA: ROW_MAX TYPE I VALUE 256,
ROWS TYPE I VALUE 1,
INDEX TYPE I,
pv_row TYPE I VALUE 1,
pv_col TYPE I VALUE 1.
FIELD-SYMBOLS: <NAME>.
SELECT kunnr name1 name2 into t_kna1
FROM KNA1
UP TO 100 ROWS BYPASSING BUFFER.
append t_kna1.
endselect.
* ROWS = ROWS + 1. "至第ROWS列
* INDEX = ROW_MAX * ( ROWS - 1 ) + 1.
loop at t_kna1.
CALL METHOD OF sheet 'Cells' = CELLS
EXPORTING
#1 = pv_row
#2 = 1.
SET PROPERTY OF CELLS 'Value' = t_KNA1-KUNNR.
CALL METHOD OF sheet 'Cells' = CELLS
EXPORTING
#1 = pv_row
#2 = 2.
SET PROPERTY OF CELLS 'Value' = t_KNA1-NAME1.
pv_row = pv_row + 1.
endloop.
* DO 10 TIMES. "如要每一列放入10个存格的数据
* ASSIGN COMPONENT SY-INDEX OF STRUCTURE KNA1
* TO <NAME>.
* CALL METHOD OF SHEET 'Cells' = CELLS
* EXPORTING #1 = INDEX.
* SET PROPERTY OF CELLS 'Value' = <NAME>.
* ADD 1 TO INDEX.
* ENDDO.
ENDFORM.
类别:Sap | | 添加到搜藏 | 分享到i贴吧 | 浏览(149) | 评论 (0) 上一篇:abap-文件处理的例子 下一篇:SAP
abap4实战学习总结 一 相关文章:•ABAP将数据传输到excel并保存 •EXCEL的VBA如何转成ABAP代码
•ABAP读取EXCEL的小例子 •ABAP 程序完成EXCEL文件的导入导...
•ABAP 读EXCEL 到内表
最近读者:登录后,您就出现在这里。
宋裔天07044063whzhao2000leoshone
网友评论: 发表评论:
内 容:
取消回复
©2010 Baidu
|
|