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

1.ole中如何保存和退出。
call method of sheetname ‘saveas’ exporting #1 = filepath #2 =1.
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’ = 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.给单元格赋值。
CaLL METHOD OF EXCEL ‘CELLS’ = CELL
EXPORTING
#1 = 2
#2 = 2.
Set PROPERTY OF CELL ‘value’ = xxxx.
8.指定要被操作的sheet.
CALL METHOD OF applicationname ‘Worksheets’ = SHEET
EXPORTING
#1 = ‘sheet3’. 这里sheet3为要操作的sheet的名字。
call method of sheet ‘Activate ‘.
9.指定操作的单元格的范围。
CALL METHOD OF applicationname ‘Range’ = range
EXPORTING
#1 = ‘B2’
#2 = ‘c2’.
10. 如何操作范围内的单元格。
call method of range ‘select ‘. range也为已经定义好的ole2_object.
Set PROPERTY OF range ‘MergeCells’ = 0 . 合并单元格,0时不合并,1则合并。与前面一起使用
Set PROPERTY OF range ‘HorizontalAlignment’ = 10 .
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
#1 = ‘1’. 1-left 2-right 3-top 4-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
#1 = 6. “the column number
SET PROPERTY OF columnObj ‘ColumnWidth’ = 10.
SET PROPERTY OF columnObj ‘NumberFormat’ = ‘@’.
17.打开一个workbook.
call METHOD OF workbook ‘Open’ EXPORTING #1 = filename+path.
18. 所有的操作方法都可以在sell—-表 oleload 中 查询到。
19. 执行宏。
CALL METHOD OF EXCEL ‘RUN’ EXPORTING #1 = ‘ZMACRO2’.
20.清除range 内容
CALL METHOD OF EXCEL ‘Range’ = RANGE
EXPORTING
#1 = tar_cell
#2 = tar_cell.
call METHOD of RANGE ‘ClearContents’.
21.合并单元格
CALL METHOD OF EXCEL ‘Range’ = RANGE
EXPORTING
#1 = sor_cell
#2 = tar_cell.
SET PROPERTY OF RANGE ‘MergeCells’ = 1.
22.缩小字体填充
SET PROPERTY OF range ‘ShrinkToFit’ = 0 .
note: 为0时取消缩小字体填充,为1时设置缩小字体填充。
note:
1.与ole相关的关键字存储在表oleload中。
2.如果有些ole方法不熟悉,可以利用vba录制宏来寻找相关的关键字。

分享到:

发表评论

昵称

沙发空缺中,还不快抢~