<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create Word Document using OLE and contain table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468943#M1651108</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Pablo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears this prorgam is not using OLE. I am using OLE. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Dec 2011 15:29:04 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2011-12-09T15:29:04Z</dc:date>
    <item>
      <title>Create Word Document using OLE and contain table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468941#M1651106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have been looking at various blogs etc to get example programs to create a word document using OLE. Some of these programs have code in them to create a table on the document. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For some reason the table is not being shown on the document and I cannot figure out why. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anybody got this to work so that a table will appear on a word document .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the logic I have: -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 CALL METHOD OF gs_tables 'Add' = gs_table
  EXPORTING
  #1 = gs_range " Handle for range entity
  #2 = '3' "Number of rows
  #3 = '2'. "Number of columns

*--Setting border attribute for the table
  GET PROPERTY OF gs_table 'Borders' = gs_table_border .
  SET PROPERTY OF gs_table_border 'Enable' = '1' . "With border
*--Filling the table with dummy data
*--Reseting font attributes for table content
  SET PROPERTY OF gs_font 'Name' = 'Garamond' .
  SET PROPERTY OF gs_font 'Size' = '11' .
  SET PROPERTY OF gs_font 'Bold' = '0' . "Not bold
  SET PROPERTY OF gs_font 'Italic' = '0' . "Not Italic
  SET PROPERTY OF gs_font 'Underline' = '0' . "Not underlined
*--Getting cell coordinates
  CALL METHOD OF gs_table 'Cell' = gs_cell
  EXPORTING
  #1 = '1' "first row
  #2 = '1'. "first column

*--Getting the range handle to write the text
  GET PROPERTY OF gs_cell 'Range' = gs_range .
*--Filling the cell
  SET PROPERTY OF gs_range 'Text' = 'OLE' .
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2011 14:15:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468941#M1651106</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-12-09T14:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Create Word Document using OLE and contain table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468942#M1651107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;have a look at this report:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAPRDEMOWORD97INTEGRATION&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2011 15:09:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468942#M1651107</guid>
      <dc:creator>former_member182371</dc:creator>
      <dc:date>2011-12-09T15:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create Word Document using OLE and contain table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468943#M1651108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Pablo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears this prorgam is not using OLE. I am using OLE. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2011 15:29:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468943#M1651108</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2011-12-09T15:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Create Word Document using OLE and contain table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468944#M1651109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;maybe this wiki can help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://wiki.sdn.sap.com/wiki/display/ABAP/Download" target="test_blank"&gt;http://wiki.sdn.sap.com/wiki/display/ABAP/Download&lt;/A&gt;&lt;EM&gt;Data&lt;/EM&gt;into&lt;EM&gt;Word&lt;/EM&gt;Document&lt;EM&gt;using&lt;/EM&gt;OLE+Automation&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i´ve just slightly adapted  the above wiki and it works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT ztest1.

INCLUDE ole2incl.

*----------------------------------------------*
*   TABLES                                     *
*----------------------------------------------*

TABLES: ekpo.

*----------------------------------------------*
*   DATA DECLARATION                           *
*----------------------------------------------*

DATA: gs_word TYPE     ole2_object, "Word Object
      gs_documents TYPE ole2_object, "List of documents
      gs_document TYPE ole2_object, "Current / Active document
      gs_selection TYPE ole2_object, "Current Cursor Selection
      gs_actdoc TYPE ole2_object , "Active document
      gs_font TYPE ole2_object , "Font
      gs_parformat TYPE ole2_object , "Paragraph format
      gs_tables TYPE ole2_object , "Tables
      gs_table TYPE ole2_object,
      gs_range TYPE ole2_object,
      gs_cell TYPE ole2_object,
      gs_border TYPE ole2_object,
      gs_application TYPE ole2_object . "Application

DATA : wf_lines TYPE i,
       wf_counter TYPE i.

*----------------------------------------------*
*   Internal Tables                            *
*----------------------------------------------*

DATA : BEGIN OF tb_ekpo OCCURS 0,
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
       END OF tb_ekpo.


*----------------------------------------------------------------------*
*  Start of Selection                                                              *
*----------------------------------------------------------------------*

START-OF-SELECTION.

  SELECT
      ebeln
      ebelp
       FROM
       ekpo
       INTO TABLE tb_ekpo UP TO 10 ROWS.

END-OF-SELECTION.


  CREATE OBJECT gs_word 'WORD.APPLICATION'. "Create word object
*  Setting object's visibility property
  SET PROPERTY OF gs_word 'Visible' = 0.
*  Opening a new document
  CALL METHOD OF gs_word 'Documents' = gs_documents.
  CALL METHOD OF gs_documents 'Add' = gs_document.
*  Activating the sheet
  CALL METHOD OF gs_document 'Activate'.
* Getting active document handle
  GET PROPERTY OF gs_word 'ActiveDocument' = gs_actdoc.
*  Getting applications handle
  GET PROPERTY OF gs_actdoc 'Application' = gs_application.
* Getting handle for the selection which is here the character at the cursor position
  GET PROPERTY OF gs_application 'Selection' = gs_selection.
  GET PROPERTY OF gs_selection 'Font' = gs_font.
  GET PROPERTY OF gs_selection 'ParagraphFormat' = gs_parformat.

  SET PROPERTY OF gs_font 'Name' = 'Arial'.
  SET PROPERTY OF gs_font 'Size' = '16'.
  SET PROPERTY OF gs_font 'Bold' = '1'.
  SET PROPERTY OF gs_font 'Italic' = '1'.
  SET PROPERTY OF gs_font 'Underline' = '1'.
  SET PROPERTY OF gs_parformat 'Alignment' = '1'. " Centered

  CALL METHOD OF gs_selection 'TypeText'
    EXPORTING
    #1 = 'PO Details'.

  DESCRIBE TABLE tb_ekpo LINES wf_lines.
  wf_lines = wf_lines + 1.
  GET PROPERTY OF gs_actdoc 'Tables' = gs_tables.
  GET PROPERTY OF gs_selection 'Range' = gs_range.
  CALL METHOD OF gs_tables 'Add' = gs_table
  EXPORTING #1 = gs_range
                    #2 = wf_lines " Rows
                    #3 = '2'. "Columns
  GET PROPERTY OF gs_table 'Borders' = gs_border.
  SET PROPERTY OF gs_border 'Enable' = '1'.

  CALL METHOD OF gs_table 'Cell' = gs_cell
    EXPORTING #1 = '1'
    #2 = '1'.
  GET PROPERTY OF gs_cell 'Range' = gs_range.
  SET PROPERTY OF gs_range 'Text' = 'EBELN'.

  CALL METHOD OF gs_table 'Cell' = gs_cell
    EXPORTING #1 = '1'
    #2 = '2'.
  GET PROPERTY OF gs_cell 'Range' = gs_range.
  SET PROPERTY OF gs_range 'Text' = 'EBELP'.



  LOOP AT tb_ekpo.
    wf_counter = wf_counter + 1.
    CALL METHOD OF gs_table 'Cell' = gs_cell
      EXPORTING #1 = wf_counter
      #2 = '1'.
    GET PROPERTY OF gs_cell 'Range' = gs_range .
    SET PROPERTY OF gs_range 'Text' = tb_ekpo-ebeln.

    CALL METHOD OF gs_table 'Cell' = gs_cell
      EXPORTING #1 = wf_counter
      #2 = '2'.
    GET PROPERTY OF gs_cell 'Range' = gs_range .
    SET PROPERTY OF gs_range 'Text' = tb_ekpo-ebelp.

  ENDLOOP.

  CALL METHOD OF gs_document 'SaveAs'
    EXPORTING
    #1 = 'C:UsersxxxxxxxxDownloadsole.doc'.

  CALL METHOD OF gs_word 'Quit'.

  FREE OBJECT gs_word.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Pablo Casamayor on Dec 9, 2011 5:36 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Pablo Casamayor on Dec 9, 2011 5:38 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Dec 2011 16:00:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-word-document-using-ole-and-contain-table/m-p/8468944#M1651109</guid>
      <dc:creator>former_member182371</dc:creator>
      <dc:date>2011-12-09T16:00:09Z</dc:date>
    </item>
  </channel>
</rss>

