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

读立写生 2018-03-22

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

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

  • 3.创建application.

1 call method of XXX 'excel.application'.

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

1 set property of XXX 'visible' = 1. 前台运行。为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. 如何操作范围内的单元格。
1   call method of range 'select '.   range也为已经定义好的ole2_object.
2   Set PROPERTY OF range  'MergeCells' = 0 .  合并单元格,0时不合并,1则合并。与前面一起使用
3   Set PROPERTY OF range  'HorizontalAlignment' = 10 .
4   Set PROPERTY OF range  'VerticalAlignment' = -4108  .
  • 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.复制与粘贴.

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

  • 15.一点注意。

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

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

解决办法:

1   CALL METHOD OF h_excel 'COLUMNS' = columnObj
2     EXPORTING
3       #1 = 6.  "the column number
4   SET PROPERTY OF columnObj 'ColumnWidth' = 10.
5   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。 缩小字体填充

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

  • note:

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

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

相关推荐