SAP OLE入门

这个代码是在网上找的,自己进行了学习,入门级的吧

从别的地方COPY了 一些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录制宏来寻找相关的关键字。

插入代码 等会自己会结合SMW0在写多一个。

REPORT ZJ_TE1.

INCLUDE OLE2INCL .

DATA: GS_EXCEL          TYPE OLE2_OBJECT ,
      GS_WBOOKLIST      TYPE OLE2_OBJECT ,
      GS_APPLICATION    TYPE OLE2_OBJECT ,
      GS_WBOOK          TYPE OLE2_OBJECT ,
      GS_ACTIVESHEET    TYPE OLE2_OBJECT ,
      GS_SHEETS         TYPE OLE2_OBJECT ,
      GS_NEWSHEET       TYPE OLE2_OBJECT ,
      GS_CELL1          TYPE OLE2_OBJECT ,
      GS_CELL2          TYPE OLE2_OBJECT ,
      GS_CELLS          TYPE OLE2_OBJECT ,
      GS_RANGE          TYPE OLE2_OBJECT ,
      GS_FONT           TYPE OLE2_OBJECT ,
      GS_INTERIOR       TYPE OLE2_OBJECT ,
      GS_COLUMNS        TYPE OLE2_OBJECT ,
      GS_CHARTS         TYPE OLE2_OBJECT ,
      GS_CHART          TYPE OLE2_OBJECT ,
      GS_CHARTTITLE     TYPE OLE2_OBJECT ,
      GS_CHARTTITLECHAR TYPE OLE2_OBJECT ,
      GS_CHARTOBJECTS   TYPE OLE2_OBJECT .

DATA GV_SHEET_NAME(20) TYPE C .
DATA GV_OUTER_INDEX LIKE SY-INDEX .
DATA GV_INTEX(2) TYPE C .
DATA GV_LINE_CNTR TYPE I . "line counter
DATA GV_LINNO TYPE I . "line number
DATA GV_COLNO TYPE I . "column number
DATA GV_VALUE TYPE I . "data

PARAMETERS: P_SHEETS TYPE I .

START-OF-SELECTION.

  DO P_SHEETS TIMES .

    GV_INTEX = SY-INDEX  .
    GV_OUTER_INDEX = SY-INDEX .
    IF SY-INDEX = 1 .
      CONCATENATE ‘Excel Sheet #‘ GV_INTEX INTO GV_SHEET_NAME .
      CREATE OBJECT GS_EXCEL ‘EXCEL.APPLICATION‘ .     " 创建 XLS
      SET PROPERTY OF GS_EXCEL ‘Visible‘ = 1 .       "1前台运行。为0时表示为后台运行。
      GET PROPERTY OF GS_EXCEL ‘Workbooks‘ = GS_WBOOKLIST .
      GET PROPERTY OF GS_WBOOKLIST ‘Application‘ = GS_APPLICATION .
      SET PROPERTY OF GS_APPLICATION ‘SheetsInNewWorkbook‘ = 1 .
      CALL METHOD OF GS_WBOOKLIST ‘Add‘        = GS_WBOOK.  "创建 workbook.
      GET PROPERTY OF GS_APPLICATION ‘ActiveSheet‘ = GS_ACTIVESHEET .
      SET PROPERTY OF GS_ACTIVESHEET ‘Name‘ = GV_SHEET_NAME .
    ELSE.

      GET PROPERTY OF GS_WBOOK ‘Sheets‘ = GS_SHEETS .
      CALL METHOD OF
          GS_SHEETS
          ‘Add‘     = GS_NEWSHEET.
      SET PROPERTY OF GS_NEWSHEET ‘Name‘ = GV_SHEET_NAME .
    ENDIF.

    GV_LINE_CNTR = 1 . "line counter

*--Title
*--Selecting cell area to be merged.

    " 选中第一行第一列 到 第一行第4列
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL1
      EXPORTING
        #1       = 1
        #2       = 1.

    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL2
      EXPORTING
        #1       = 1
        #2       = 4.

    CALL METHOD OF
        GS_EXCEL
        ‘Range‘  = GS_CELLS
      EXPORTING
        #1       = GS_CELL1
        #2       = GS_CELL2.

    CALL METHOD OF GS_CELLS ‘Select‘ .  "选中

    CALL METHOD OF GS_CELLS ‘Merge‘ .  "合并

*--Setting title data
    CALL METHOD OF GS_EXCEL ‘Cells‘ = GS_CELL1   "选中行列
      EXPORTING
      #1 =  GV_LINE_CNTR
      #2 = 1.
    SET PROPERTY OF GS_CELL1 ‘Value‘ = ‘设置抬头‘ .   "设置值

*--Formatting the title
    GET PROPERTY OF GS_CELL1 ‘Font‘ = GS_FONT .
    SET PROPERTY OF GS_FONT ‘Underline‘ = 2 .
    SET PROPERTY OF GS_FONT ‘Bold‘ = 1 .
    SET PROPERTY OF GS_CELL1 ‘HorizontalAlignment‘ = -4108 .
    GET PROPERTY OF GS_CELL1 ‘Interior‘ = GS_INTERIOR .
    SET PROPERTY OF GS_INTERIOR ‘ColorIndex‘ = 15 .
    SET PROPERTY OF GS_INTERIOR ‘Pattern‘ = -4124 .
    SET PROPERTY OF GS_INTERIOR ‘PatternColorIndex‘ = -4105 .
    GV_LINE_CNTR = GV_LINE_CNTR + 1 .

*--Writing some additional data for the title
    CALL METHOD OF GS_EXCEL ‘Cells‘ = GS_CELL1   "第2行第1列
      EXPORTING
      #1 = GV_LINE_CNTR
      #2 = 1.
    SET PROPERTY OF GS_CELL1 ‘Value‘ = ‘Sheet No‘ .  "设置值
    CALL METHOD OF GS_EXCEL ‘Cells‘ = GS_CELL1   "第2行第5列
      EXPORTING
      #1 = GV_LINE_CNTR
      #2 = 5.
    SET PROPERTY OF GS_CELL1 ‘Value‘ = ‘:‘ .  "设置值
    CALL METHOD OF GS_EXCEL ‘Cells‘ = GS_CELL1  "第2行第6列
      EXPORTING
      #1 = GV_LINE_CNTR
      #2 = 6.
    SET PROPERTY OF GS_CELL1 ‘Value‘ = GV_INTEX .  "设置值

*--Formatting the area of additional data 1
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL1
      EXPORTING
        #1       = 1
        #2       = 1.
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL2
      EXPORTING
        #1       = GV_LINE_CNTR
        #2       = 5.
    CALL METHOD OF       "指定操作的单元格范围
        GS_EXCEL
        ‘Range‘  = GS_CELLS
      EXPORTING
        #1       = GS_CELL1
        #2       = GS_CELL2.

    CALL METHOD OF GS_CELLS ‘Select‘ .   "选中
    GET PROPERTY OF GS_CELLS ‘Font‘ = GS_FONT . "设置字体
    SET PROPERTY OF GS_FONT ‘Bold‘ = 1 .  "加粗

*--Formatting the area of additional data 2
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL1
      EXPORTING
        #1       = 1
        #2       = 5.
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL2
      EXPORTING
        #1       = GV_LINE_CNTR
        #2       = 5.
    CALL METHOD OF
        GS_EXCEL
        ‘Range‘  = GS_CELLS
      EXPORTING
        #1       = GS_CELL1
        #2       = GS_CELL2.
    CALL METHOD OF
        GS_CELLS
        ‘Select‘.
    GET PROPERTY OF GS_CELLS ‘Columns‘ = GS_COLUMNS .
    CALL METHOD OF
        GS_COLUMNS
        ‘AutoFit‘.

*--Bordering title data area
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL1
      EXPORTING
        #1       = 1
        #2       = 1.
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL2
      EXPORTING
        #1       = GV_LINE_CNTR
        #2       = 6.
    CALL METHOD OF
        GS_EXCEL
        ‘Range‘  = GS_CELLS
      EXPORTING
        #1       = GS_CELL1
        #2       = GS_CELL2.
    CALL METHOD OF
        GS_CELLS
        ‘Select‘.
    CALL METHOD OF GS_CELLS ‘BorderAround‘ " 边框
    EXPORTING
    #1 = 1 "continuous line
    #2 = 4. "thick

*--Putting axis labels
    GV_COLNO = 2 .
    GV_LINE_CNTR = GV_LINE_CNTR + 5 .
    GV_LINNO = GV_LINE_CNTR - 1 .
    CALL METHOD OF GS_EXCEL ‘Cells‘ = GS_CELL1  "第6行
      EXPORTING
      #1 = GV_LINNO
      #2 = 1.
    SET PROPERTY OF GS_CELL1 ‘Value‘ = ‘X‘ .
    CALL METHOD OF GS_EXCEL ‘Cells‘ = GS_CELL1  "第七行
      EXPORTING
      #1 = GV_LINE_CNTR
      #2 = 1.
    SET PROPERTY OF GS_CELL1 ‘Value‘ = ‘Y‘ .

*--Generating some data   对X 和Y 行填充值
    DO 3 TIMES .
      GV_VALUE = GV_OUTER_INDEX * SY-INDEX * 10 .
      CALL METHOD OF
          GS_EXCEL
          ‘Cells‘  = GS_CELL1
        EXPORTING
          #1       = GV_LINNO
          #2       = GV_COLNO.
      SET PROPERTY OF GS_CELL1 ‘Value‘ = SY-INDEX .
      CALL METHOD OF
          GS_EXCEL
          ‘Cells‘  = GS_CELL1
        EXPORTING
          #1       = GV_LINE_CNTR
          #2       = GV_COLNO.
      SET PROPERTY OF GS_CELL1 ‘Value‘ = GV_VALUE .
      GV_COLNO = GV_COLNO + 1 .
    ENDDO .

*--Source data area
    GV_COLNO = GV_COLNO - 1 .
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL1
      EXPORTING
        #1       = GV_LINNO
        #2       = 1.
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL2
      EXPORTING
        #1       = GV_LINE_CNTR
        #2       = GV_COLNO.
    CALL METHOD OF
        GS_EXCEL
        ‘Range‘  = GS_CELLS
      EXPORTING
        #1       = GS_CELL1
        #2       = GS_CELL2.
    CALL METHOD OF
        GS_CELLS
        ‘Select‘.

    " 插入图片   创建新SHEET
    GET PROPERTY OF GS_APPLICATION ‘Charts‘ = GS_CHARTS .
    CALL METHOD OF
        GS_CHARTS
        ‘Add‘     = GS_CHART.
    CALL METHOD OF
        GS_CHART
        ‘Activate‘.
    SET PROPERTY OF GS_CHART ‘ChartType‘ = ‘51‘ . "Vertical bar graph
    CALL METHOD OF
        GS_CHART
        ‘SetSourceData‘

      EXPORTING
        #1              = GS_CELLS
        #2              = 1.
    SET PROPERTY OF GS_CHART ‘HasTitle‘ = 1 .
    GET PROPERTY OF GS_CHART ‘ChartTitle‘ = GS_CHARTTITLE .
    GET PROPERTY OF GS_CHARTTITLE ‘Characters‘ = GS_CHARTTITLECHAR .
    SET PROPERTY OF GS_CHARTTITLECHAR ‘Text‘ = ‘Sample Graph‘ .

*--Activate current sheet  将新的SHEET 复制到原始的
    CALL METHOD OF
        GS_EXCEL
        ‘WorkSheets‘ = GS_ACTIVESHEET
      EXPORTING
        #1           = GV_SHEET_NAME.
    CALL METHOD OF
        GS_ACTIVESHEET
        ‘Activate‘.
    CALL METHOD OF
        GS_CHART
        ‘Location‘

      EXPORTING
        #1         = 2
        #2         = GV_SHEET_NAME.

*--Reposition the chart on the worksheet (cut&paste)
    CALL METHOD OF
        GS_ACTIVESHEET
        ‘ChartObjects‘ = GS_CHARTOBJECTS.
    CALL METHOD OF
        GS_CHARTOBJECTS
        ‘Select‘.
    CALL METHOD OF
        GS_CHARTOBJECTS
        ‘Cut‘.

*--Select new area
    GV_LINE_CNTR = GV_LINE_CNTR + 2 .
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL1
      EXPORTING
        #1       = GV_LINE_CNTR
        #2       = 1.
    CALL METHOD OF
        GS_EXCEL
        ‘Cells‘  = GS_CELL2
      EXPORTING
        #1       = GV_LINE_CNTR
        #2       = 1.
    CALL METHOD OF
        GS_EXCEL
        ‘Range‘  = GS_CELLS
      EXPORTING
        #1       = GS_CELL1
        #2       = GS_CELL2.
    CALL METHOD OF
        GS_CELLS
        ‘Select‘.
    CALL METHOD OF GS_ACTIVESHEET ‘Paste‘ .  "粘贴
  ENDDO.

  " 释放资源
  FREE: GS_EXCEL, GS_WBOOKLIST, GS_APPLICATION, GS_WBOOK,
  GS_ACTIVESHEET,GS_SHEETS, GS_NEWSHEET, GS_CELL1,
  GS_CELL2, GS_CELLS, GS_RANGE, GS_FONT, GS_INTERIOR,
  GS_COLUMNS, GS_CHARTS, GS_CHART, GS_CHARTTITLE,
  GS_CHARTTITLECHAR, GS_CHARTOBJECTS .
时间: 2024-10-16 04:53:14

SAP OLE入门的相关文章

sap abap入门培训

上海51sap是专业的SAP培训中心,提供专业的SAP ABAP培训,SAP开发培训培训以及SAP实施模块学习.SAP最初开发ABAP语言仅为内部使用,为应用程序员提供优化的工作环境.学习ABAP语言,就业无忧. ABAP(SAP 应用开发) 一:什么是ABAP. 定义:ABAP=Advanced business application program, 一种高级企业应用编程语言. SAP最初开发ABAP/4(高级商业应用程序设计)语言仅为内部使用,为应用程序员提供优化的工作环境.经过不断的改

[转帖]SAP一句话入门:Sales and Distribution

SAP一句话入门:Sales and Distribution http://blog.vsharing.com/MilesForce/A616565.html SD是Sales and Distribution的简称.在SAP系统中,销售与分销模块处在供应链下游,关注从客户订单到向客户收款的全过程. SD模块中的Sales好理解,而Distribution却容易被忽视.用直白的话来讲,SD模块就是解决“卖”的问题,它关注的范畴有: 1,谁来卖? 2,卖什么? 3,卖给谁? 4,什么样的价格?

[转帖]SAP一句话入门:Project System

SAP一句话入门:Project System http://blog.vsharing.com/MilesForce/A621279.html 这是SAP ERP入门的最后一篇了. 我们这些死跑龙套的最喜欢项目了,是啊,有项目就有费用啊.万恶的资本家终于舍得拿钱出来让我们过家家了,虽然其目的是想攫取更多的社会财富.不过另一方面,这叫什么来着,叫社会财富的再分配.次级分配.三级分配,给的就是围在肥得流油的资本家身边的劳苦大众们.就像我有事没事就要用公家的钱打飞的往返不同的城市,多的一个月飞五六次

[转帖]SAP一句话入门:Plant Maintenance

SAP一句话入门:Plant Maintenance http://blog.vsharing.com/MilesForce/A618273.html PM就是Plant Maintenance(本文中的PM都是这个意思,不要和Project Manager搞混了),大大小小的文档上都把它翻译成工厂维护,意译过来应该是设备维护.单单讲PM内容较少,现在比较流行EAM(Enterprise Asset Management).要说EAM的话就得把SAP里的PS.AM一起说了.IBM有套EAM系统M

SAP Payroll 入门

SAP HR中PY无疑是非常重要的一个子模块,同时也是学习难度最大的一块,在我学习和工作的过程中发现学习PY一定要重视基础知识的掌握,下面把PY的一些基础知识记录下来,供大家学习参考: Payroll说透了就是一个薪酬数据维护.薪酬计算.薪酬发放的连续性动作,那么薪酬数据维护需要告诉这些数据是具体哪个人的,薪酬数据维护时系统当然也需要有个单位吧(如日工资.小时工资),所以就向我们提出了时间数据的要求,有了所需要的数据后,使用系统的核算程序就可以进行工资的计算了,计算好的薪酬数据将被保存在数据库中

SAP PI入门

本教程的目的是让读者理解:SAP Process Intergration(以下简称SAP PI)是什么.我们不需要探究课题的本质,但是会讨论SAP PI的架构和不同特点.本文只会覆盖到PI的基本特点,而不是讨论全部. 本文链接:http://www.cnblogs.com/hhelibeb/p/7105070.html SAP ERP是什么 对于任何业务——无论是大的还是小的——都会有必须要执行的标准业务功能,比如:物料管理(MM),销售与分发(SD),财务(FI),人力资源(HR)等等.市场

[转]SAP一句话入门SD模块

SD是Sales and Distribution的简称.在SAP系统中,销售与分销模块处在供应链下游,关注从客户订单到向客户收款的全过程. SD模块中的Sales好理解,而Distribution却容易被忽视.用直白的话来讲,SD模块就是解决“卖”的问题,它关注的范畴有: 1,谁来卖? 2,卖什么? 3,卖给谁? 4,什么样的价格? 5,销售业务模式是什么? 6,货物如何到达客户? 7,钱款如何交割? 对应上述问题,我们分别引出相应的概念: 1,谁来卖? 既是执行销售动作的组织结构及此结构下的

sap bw bo

SAP BW入门知识教程: 一, sap NetWeaver 和 bi 的概述 sap NetWeaver 是 sap 退出的 soa 的一个平台,他可以集成企业需要的应用服务,提供一个开放的服务. sap NetWeaver 是所有 sap solutions 的基础. sap bw 就是该平台提供的一个核心功能.除此之外,他还提供了 EP . sap Application server 等,他可以提供 java 引擎,从而可以在上面进行 java 开发. sap bw 介绍 :sap bw

5月学习月~比拼学习 上浮力

5月学习月活动 一.活动对象 所有微职位学员 二.活动时间 2018年5月7日-2018年5月27日 (合计三周,21天) 三.活动目标 提升大家的学习能力,形成被动学习变成主动学习的好习惯.通过学习排行榜的学习时长数据排名 能激发大家学习的积极性和主动性,能更好的促进大家进行深度学习. 四.活动规则 (1)班级学习时长排行榜每周一(14.21.28日)发布:班级学习时长前10名同学 (2)学院学习时长排行总榜 (29日)发布:计算(5月7日-5月27日)每个班学员的学习时长数据,计算微职位的排