SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Fill Excel template using link_server, OAOR



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 22, 2007 7:11 pm    Post subject: Fill Excel template using link_server, OAOR Reply with quote

Code:
*&---------------------------------------------------------------------*
*& Report  YSAPRDEMOEXCELINTEGRATION                          *
*& copy of  SAPRDEMOEXCELINTEGRATION
*&---------------------------------------------------------------------*
REPORT  ysaprdemoexcelintegration MESSAGE-ID ycdg.

* Selection screen example
SELECTION-SCREEN:
SKIP 1.
PARAMETERS: sel_wbs LIKE prps-posid OBLIGATORY MEMORY ID pro.

* Set the screen that has the container with the name 'CONTAINER'
SET SCREEN 100.

TYPE-POOLS: soi.

CLASS c_oi_errors DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.

DATA: item_url(256).
DATA: ok_code LIKE sy-ucomm,
      save_ok LIKE sy-ucomm.
DATA: control TYPE REF TO i_oi_container_control.
DATA: container TYPE REF TO cl_gui_custom_container.
DATA: link_server_decl TYPE REF TO i_oi_link_server.
DATA: retcode TYPE soi_ret_string,
      document_type TYPE soi_document_type
                                        VALUE soi_doctype_excel97_sheet.
DATA: proxy TYPE REF TO i_oi_document_proxy.
DATA: bds_instance TYPE REF TO cl_bds_document_set,
      doc_uris TYPE sbdst_uri,
      wa_doc_uris LIKE LINE OF doc_uris,
      doc_components TYPE sbdst_components,
      doc_signature TYPE sbdst_signature,
      wa_doc_signature LIKE LINE OF doc_signature.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'MAIN0100'.
  SET TITLEBAR '001'.

  retcode = c_oi_errors=>ret_ok.
  IF control IS INITIAL.
    DATA: b_has_activex.

    CALL FUNCTION 'GUI_HAS_ACTIVEX'
         IMPORTING
              return = b_has_activex.
    IF b_has_activex IS INITIAL.
      MESSAGE e000 WITH 'No Windows GUI'.
    ENDIF.

    CALL METHOD c_oi_container_control_creator=>get_container_control
                    IMPORTING control = control
                              retcode = retcode.
    CALL METHOD c_oi_errors=>show_message
                                  EXPORTING type = 'E'.

    CREATE OBJECT container
              EXPORTING container_name = 'CONTAINER'.

    CALL METHOD control->init_control
                        EXPORTING r3_application_name =
                                              'Demo' "#EC NOTEXT
                                  inplace_enabled = 'X'
                                  inplace_scroll_documents = 'X'
                                  parent = container
                                  register_on_close_event = 'X'
                                  register_on_custom_event = 'X'
                        IMPORTING retcode = retcode.
    CALL METHOD c_oi_errors=>show_message
                                  EXPORTING type = 'E'.

    CALL METHOD control->get_link_server
                       IMPORTING link_server = link_server_decl
                                 retcode = retcode.
    CALL METHOD c_oi_errors=>show_message
                                  EXPORTING type = 'E'.

    CALL METHOD link_server_decl->start_link_server
                      IMPORTING retcode = retcode.
    CALL METHOD c_oi_errors=>show_message
                                  EXPORTING type = 'E'.

    PERFORM fill_fields.

* Fill the template
    IF NOT control IS INITIAL.
      CALL METHOD control->get_document_proxy
                 EXPORTING document_type = document_type
                 IMPORTING document_proxy = proxy
                           retcode = retcode.
      IF bds_instance IS INITIAL.
        CREATE OBJECT bds_instance.
      ENDIF.
      wa_doc_signature-prop_name = 'DESCRIPTION'.
* The name of the template you created using transaction OAOR
* Class = SOFFICEINTEGRATION, Type = OT
      wa_doc_signature-prop_value = 'ZDECL'.
      APPEND wa_doc_signature TO doc_signature.

      CALL METHOD bds_instance->get_with_url
                         EXPORTING classname = 'SOFFICEINTEGRATION'
                                   classtype = 'OT'
                                   object_key = 'SOFFICEINTEGRATION'
                         CHANGING uris = doc_uris
                                  signature = doc_signature.
      READ TABLE doc_uris INTO wa_doc_uris INDEX 1.
      item_url = wa_doc_uris-uri.
      IF NOT bds_instance IS INITIAL.
        FREE bds_instance.
      ENDIF.
      CALL METHOD proxy->open_document
                        EXPORTING open_inplace = 'X'
                                  document_url = item_url.
      CALL METHOD proxy->update_document_links
         IMPORTING retcode = retcode.
      CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
    ENDIF.
  ENDIF.
ENDMODULE.                             " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.

  CALL METHOD cl_gui_cfw=>dispatch.

  CASE save_ok.
    WHEN 'EXIT'.
      IF NOT proxy IS INITIAL.
        CALL METHOD proxy->close_document.
        FREE proxy.
      ENDIF.
      IF NOT link_server_decl IS INITIAL.
        CALL METHOD link_server_decl->stop_link_server
                                       IMPORTING retcode = retcode.
        FREE link_server_decl.
      ENDIF.
      IF NOT control IS INITIAL.
        CALL METHOD control->destroy_control
                                            IMPORTING retcode = retcode.
        FREE control.
      ENDIF.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                             " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Form  fill_fields
*&---------------------------------------------------------------------*
*       Filling the Excel template
*----------------------------------------------------------------------*
FORM fill_fields.
    CALL METHOD link_server_decl->add_string_item
         EXPORTING item_name   = 'Testfield'
                   item_title  = 'Testfield'
                   item_value  = 'Testing 1, 2, 3'
                   no_flush    = ' '
         IMPORTING retcode = retcode.
ENDFORM.                    " fill_fields
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.