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

Выпадающие списки в Excel



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



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Wed Aug 20, 2008 1:43 pm    Post subject: Выпадающие списки в Excel Reply with quote

URDo wrote:
Добрый день.
У меня есть вопрос по работе с выпадающими списками в Экселе. Нужно управлять ими через средства абап. У Вас не моглибы вы чтонибудь посоветовать в духе темы http://www.sapnet.ru/viewtopic.php?t=1301


Code:
REPORT z_excel_dropdown.

INCLUDE ole2incl.

CONSTANTS:  xlValidateList         TYPE i VALUE 3,
            xlValidAlertStop       TYPE i VALUE 1,
            xlBetween              TYPE i VALUE 1.

* handles for OLE objects
DATA: h_excel TYPE ole2_object,        " Excel object
      h_mapl TYPE ole2_object,         " list of workbooks
      h_map TYPE ole2_object,          " workbook
      h_sheet TYPE ole2_object,        " sheet
      h_range TYPE ole2_object,        " range
      h_select TYPE ole2_object,       " select
      h_valid TYPE ole2_object.        " validation
DATA: p1(255) TYPE c.

*&---------------------------------------------------------------------*
*&   Event START-OF-SELECTION
*&---------------------------------------------------------------------*

START-OF-SELECTION.
* start Excel
  CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
  PERFORM err_hdl.
  SET PROPERTY OF h_excel  'Visible' = 1.
  PERFORM err_hdl.
* get list of workbooks, initially empty
  CALL METHOD OF h_excel 'Workbooks' = h_mapl.
  PERFORM err_hdl.
* add a new workbook
  CALL METHOD OF h_mapl 'Add' = h_map.
  PERFORM err_hdl.

  GET PROPERTY OF h_excel 'SHEETS' = h_sheet
                    EXPORTING #1 = 'Sheet1'.
  PERFORM err_hdl.

  CALL METHOD OF h_sheet 'ACTIVATE'.
  PERFORM err_hdl.

  p1 = 'A1'.
  CALL METHOD OF h_sheet 'RANGE' = h_range
                    EXPORTING #1 = p1.
  PERFORM err_hdl.

  CALL METHOD OF h_range 'SELECT'.
  PERFORM err_hdl.

  GET PROPERTY OF h_excel 'SELECTION' = h_select.
  PERFORM err_hdl.

  GET PROPERTY OF h_select 'VALIDATION' = h_valid.
  PERFORM err_hdl.

  CALL METHOD OF h_valid 'DELETE'.
  PERFORM err_hdl.

  CALL METHOD OF h_valid 'ADD'
         EXPORTING
                   #1 = xlValidateList
                   #2 = xlValidAlertStop
                   #3 = xlBetween
                   #4 = 'NUM1, NUM2, NUM3'
                   .
  PERFORM err_hdl.
  SET PROPERTY OF h_valid 'IgnoreBlank' = 'True'.
  SET PROPERTY OF h_valid 'InCellDropdown' = 'True'.
  SET PROPERTY OF h_valid 'ShowInput' = 'True'.
  SET PROPERTY OF h_valid 'ShowError' = 'True'.

* disconnect from Excel
  FREE OBJECT h_excel.
  PERFORM err_hdl.

************
FORM err_hdl.
  IF sy-subrc <> 0.
    WRITE: / 'OLE-Automation error:', sy-subrc.
    STOP.
  ENDIF.
ENDFORM.                    " ERR_HDL
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 -> ABAP 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.