【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: / '保存成功!'.
「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论