- 1.ole中如何保存和退出。
1 call method of sheetname 'saveas' exporting #1 = filepath #2 =1. 2 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.
1 CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOK . 2 call method of workbook 'ADD'.
- 6.在一个workbook中添加一个worksheet.
1 CALL METHOD OF applicationname 'sheets' = worksheet. 2 call method of worksheet 'Add' .
- 7.给单元格赋值。
陈辉/2018-03-22/09:23:27
1 CaLL METHOD OF EXCEL 'CELLS' = CELL 2 EXPORTING 3 #1 = 2 4 #2 = 2. 5 Set PROPERTY OF CELL 'value' = xxxx.
- 8.指定要被操作的sheet.
1 CALL METHOD OF applicationname 'Worksheets' = SHEET 2 EXPORTING 3 #1 = 'sheet3'. 这里sheet3为要操作的sheet的名字。 4 call method of sheet 'Activate '.
- 9.指定操作的单元格的范围。
1 CALL METHOD OF applicationname 'Range' = range 2 EXPORTING 3 #1 = 'B2' 4 #2 = '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.单元格内部属性的操作.
1 call method of cell 'INTERIOR' = int. 2 set property of int 'ColorIndex' = color. 颜色 3 set property of int 'Pattern' = pattern.
- 12.单元格内字体的操作.
1 call method of CELL 'FONT' = font. 2 set property of font 'BOLD' = bold. 3 set property of font 'SIZE' = size.
- 13.边框的操作.
1 call method of CELL 'BORDERS' = BORDERS 2 EXPORTING 3 #1 = '1'. 1-left 2-right 3-top 4-bottom 4 set property of borders 'Linestyle' = plinestyle . 5 set property of borders 'Weight' = pweight . 6 free object borders. 7 在此之前应该指定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 #1 = filename+path.
- 18. 所有的操作方法都可以在sell----表 oleload 中 查询到。
- 19. 执行宏。
CALL METHOD OF EXCEL 'RUN' EXPORTING #1 = 'ZMACRO2'.
- 20。清除range 内容
1 CALL METHOD OF EXCEL 'Range' = RANGE 2 EXPORTING 3 #1 = tar_cell 4 #2 = tar_cell. 5 call METHOD of RANGE 'ClearContents'.
- 21 合并单元格
1 CALL METHOD OF EXCEL 'Range' = RANGE 2 EXPORTING 3 #1 = sor_cell 4 #2 = tar_cell. 5 SET PROPERTY OF RANGE 'MergeCells' = 1.
- 22。 缩小字体填充
1 SET PROPERTY OF range 'ShrinkToFit' = 0 . 2 note: 为0时取消缩小字体填充,为1时设置缩小字体填充。
- note:
1.与ole相关的关键字存储在表oleload中。
2.如果有些ole方法不熟悉,可以利用vba录制宏来寻找相关的关键字。+
3.可参考SAP标准事务码:OLE,SOLE,,程序:RSOLETT1。
部分事务码可参考标准菜单S000下的 ”工具” -> “ABAP工作台” -> “开发” -> “编程环境” -> “OLE”
本文来自博客园,作者:Lovemywx2,转载请注明原文链接:https://www.cnblogs.com/1187163927ch/p/8621556.html