【ABAP】OLE WORD

*&---------------------------------------------------------------------*
*& Report ZLJH102902
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLJH102902.
INCLUDE ole2incl.

TABLES: v_username.

DATA: w_word            TYPE ole2_object,
      w_document        TYPE ole2_object,
      w_selection       TYPE ole2_object,
      w_font            TYPE ole2_object,
      w_paragraphformat TYPE ole2_object,
      w_system(10),
      w_line(80).

DATA: BEGIN OF itab OCCURS 0.
        INCLUDE STRUCTURE v_username.
DATA: END OF itab.

START-OF-SELECTION.

  REFRESH itab.
  SELECT * FROM v_username INTO TABLE itab ORDER BY bname.

* 创建 OLE automation object of type Word.Application.
  CREATE OBJECT w_word 'Word.Application'.

* 执行程序时显示MS-Word
  SET PROPERTY OF w_word 'Visible' = 1.

* 添加一个新的空白文档
  CALL METHOD OF w_word 'Documents' = w_document.
  CALL METHOD OF w_document 'Add'.

* 将数据添加到新的MS-Word文档
  CALL METHOD OF w_word 'Selection' = w_selection.
  CALL METHOD OF w_selection 'ParagraphFormat' = w_paragraphformat.
  CALL METHOD OF w_selection 'Font' = w_font.

* 使用粗体,加粗,标题居中
  SET PROPERTY OF w_paragraphformat 'Alignment' = 1.
  SET PROPERTY OF w_font 'Size' = 16.
  SET PROPERTY OF w_font 'Bold' = 1.

  CONCATENATE syst-sysid '(' syst-mandt ')' INTO w_system.
  CONCATENATE 'world 测试' w_system
              INTO w_line SEPARATED BY space.

* 导出标题到Word文档
  CALL METHOD OF w_selection 'TypeText'
                             EXPORTING #1 = w_line.
  CALL METHOD OF w_selection 'TypeParagraph'.
  CALL METHOD OF w_selection 'TypeParagraph'.

  SET PROPERTY OF w_paragraphformat 'Alignment' = 0.
  SET PROPERTY OF w_font 'Size' = 10.

  LOOP AT itab.
    SET PROPERTY OF w_font 'Bold' = 1.
    SET PROPERTY OF w_font 'Italic' = 0.

    CALL METHOD OF w_selection 'TypeText'
                               EXPORTING #1 = itab-bname.

    CONCATENATE space itab-name_text INTO w_line SEPARATED BY space.
    SET PROPERTY OF w_font 'Bold' = 0.
    SET PROPERTY OF w_font 'Italic' = 1.

* 导出用户名和全名到Word文档
    CALL METHOD OF w_selection 'TypeText'
                               EXPORTING #1 = w_line.

    CALL METHOD OF w_selection 'TypeParagraph'.
  ENDLOOP.

  SET PROPERTY OF w_word 'Visible' = 1.
   WRITE: / '保存成功!'.

人已赞赏
ABAPSAP

【ABAP】ABAP技术总结一

2019-11-5 11:35:17

ABAPSAP

【ABAP】SE80拉到最左边拉不回来了解决办法

2019-11-21 16:10:10

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索