SAP OLE中常用的一些方法和属性

  • 1.ole中如何保存和退出。
 call method of sheetname 'saveas' exporting # = filepath # =.
call method of applicationname 'quit'.
  • 2.给sheet重命名。

call method of sheetname 'name' = 'sheetname'.

  • 3.创建application.

call method of XXX 'excel.application'.

  • 4.设置XXX的显示模式。

set property of XXX 'visible' = . 前台运行。为0时表示为后台运行。

  • 5.创建workbook.
 CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOK .
call method of workbook 'ADD'.
  • 6.在一个workbook中添加一个worksheet.
 CALL METHOD OF applicationname 'sheets' = worksheet.
call method of worksheet 'Add' .
  • 7.给单元格赋值。
陈辉/2018-03-22/09:23:27
 CaLL METHOD OF EXCEL 'CELLS' = CELL
EXPORTING
# =
# = .
Set PROPERTY OF CELL 'value' = xxxx.
  • 8.指定要被操作的sheet.
 CALL METHOD OF applicationname 'Worksheets' = SHEET
EXPORTING
# = 'sheet3'. 这里sheet3为要操作的sheet的名字。
call method of sheet 'Activate '.
  • 9.指定操作的单元格的范围。
   CALL METHOD OF applicationname 'Range' = range
EXPORTING
# = 'B2'
# = 'c2'.
  • 10. 如何操作范围内的单元格。
   call method of range 'select '.   range也为已经定义好的ole2_object.
Set PROPERTY OF range 'MergeCells' = . 合并单元格,0时不合并,1则合并。与前面一起使用
Set PROPERTY OF range 'HorizontalAlignment' = .
Set PROPERTY OF range 'VerticalAlignment' = - .
  • 11.单元格内部属性的操作.
   call method of cell 'INTERIOR' = int.
set property of int 'ColorIndex' = color. 颜色
set property of int 'Pattern' = pattern.
  • 12.单元格内字体的操作.
   call method of CELL 'FONT' = font.
set property of font 'BOLD' = bold.
set property of font 'SIZE' = size.
  • 13.边框的操作.
   call method of CELL 'BORDERS' = BORDERS
EXPORTING
# = ''. -left -right -top -bottom
set property of borders 'Linestyle' = plinestyle .
set property of borders 'Weight' = pweight .
free object borders.
在此之前应该指定range.
  • 14.复制与粘贴.

call method of sheet 'copy'. call method of sheet 'paste'.

  • 15.一点注意。

在操作sheet时,默认为上次操作的sheet.如果想更换,参考8。

  • 16。一个问题。有时输入数据如111111111111111111,会显示为1E+17。

解决办法:

   CALL METHOD OF h_excel 'COLUMNS' = columnObj
EXPORTING
# = . "the column number
SET PROPERTY OF columnObj 'ColumnWidth' = .
SET PROPERTY OF columnObj 'NumberFormat' = '@'.
  • 17。打开一个workbook.
call METHOD OF workbook 'Open' EXPORTING # = filename+path.
  • 18.  所有的操作方法都可以在sell----表 oleload 中 查询到。
  • 19.  执行宏。
CALL METHOD OF EXCEL 'RUN' EXPORTING # = 'ZMACRO2'.
  • 20。清除range 内容
   CALL METHOD OF EXCEL 'Range' = RANGE
EXPORTING
# = tar_cell
# = tar_cell.
call METHOD of RANGE 'ClearContents'.
  • 21  合并单元格
   CALL METHOD OF EXCEL 'Range' = RANGE
EXPORTING
# = sor_cell
# = tar_cell.
SET PROPERTY OF RANGE 'MergeCells' = .
  • 22。 缩小字体填充

SET PROPERTY OF range 'ShrinkToFit' = . note: 为0时取消缩小字体填充,为1时设置缩小字体填充。

  • note:

1.与ole相关的关键字存储在表oleload中。

2.如果有些ole方法不熟悉,可以利用vba录制宏来寻找相关的关键字。+

3.可参考SAP标准事务码:OLE,SOLE,,程序:RSOLETT1。

  部分事务码可参考标准菜单S000下的  ”工具”  ->  “ABAP工作台”  ->  “开发”  ->  “编程环境”  ->   “OLE”

上一篇:Java集合类根接口:Collection 和 Map


下一篇:LearnOpenGL学习笔记(二)——着色器简单理解