论坛首页 综合技术论坛

DOI create excel

浏览 2374 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (3) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-07-25   最后修改:2010-07-25
REPORT  ztest_create_excel NO STANDARD PAGE HEADING.
 
DATA:
oref_container   TYPE REF TO cl_gui_custom_container,
iref_control     TYPE REF TO i_oi_container_control,
iref_document    TYPE REF TO i_oi_document_proxy,
iref_spreadsheet TYPE REF TO i_oi_spreadsheet,
iref_error       TYPE REF TO i_oi_error.
 
DATA: BEGIN OF it_spfli OCCURS 0.
       INCLUDE STRUCTURE spfli.
DATA: END OF it_spfli.
 
DATA:
v_document_url TYPE c LENGTH 256,
i_sheets TYPE soi_sheets_table,
wa_sheets TYPE soi_sheets,
i_data        TYPE soi_generic_table,
wa_data       TYPE soi_generic_item,
i_ranges      TYPE soi_range_list.
 
*PARAMETERS:
*p_file  TYPE  localfile OBLIGATORY,
*p_rows TYPE i DEFAULT 100 OBLIGATORY,   "Rows (Maximum 65536)
*p_cols TYPE i DEFAULT 10 OBLIGATORY.    "Columns (Maximum 256)
 
INITIALIZATION.
 
 CALL METHOD c_oi_container_control_creator=>get_container_control
   IMPORTING
     control = iref_control
     error   = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'E'.
 ENDIF.
 
 
 CREATE OBJECT oref_container
   EXPORTING
     container_name              = 'CONT'
   EXCEPTIONS
     cntl_error                  = 1
     cntl_system_error           = 2
     create_error                = 3
     lifetime_error              = 4
     lifetime_dynpro_dynpro_link = 5
     OTHERS                      = 6.
 IF sy-subrc <> 0.
   MESSAGE e001(00) WITH 'Error while creating container'.
 ENDIF.
 
 CALL METHOD iref_control->init_control
   EXPORTING
     inplace_enabled      = 'X'
     r3_application_name  = 'EXCEL CONTAINER'
     parent               = oref_container
   IMPORTING
     error                = iref_error
   EXCEPTIONS
*      javabeannotsupported = 1
     OTHERS               = 2.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'E'.
 ENDIF.
 
 CALL METHOD iref_control->get_document_proxy
   EXPORTING
     document_type  = soi_doctype_excel_sheet
   IMPORTING
     document_proxy = iref_document
     error          = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'E'.
 ENDIF.
 
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*
** To provide F4 help for the file
*  PERFORM sub_file_f4.
 
START-OF-SELECTION.
 
 SELECT * FROM spfli INTO TABLE it_spfli.
*  CONCATENATE 'FILE://' p_file INTO v_document_url.
 
*  CALL METHOD iref_document->open_document
*    EXPORTING
*      document_title = 'Excel'
*      document_url   = v_document_url
*      open_inplace   = 'X'
*    IMPORTING
*      error          = iref_error.
*  IF iref_error->has_failed = 'X'.
*    CALL METHOD iref_error->raise_message
*      EXPORTING
*        type = 'I'.
*    LEAVE LIST-PROCESSING.
*  ENDIF.
 
 CALL METHOD iref_document->create_document
   EXPORTING
     document_title = 'Excel'
     open_inplace   = 'X'
   IMPORTING
     error          = iref_error.
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 
 CALL METHOD iref_document->get_spreadsheet_interface
   EXPORTING
     no_flush        = ' '
   IMPORTING
     error           = iref_error
     sheet_interface = iref_spreadsheet.
 
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
   LEAVE LIST-PROCESSING.
 ENDIF.
 
 CALL METHOD iref_spreadsheet->insert_range
   EXPORTING
     name    = 'TEST'
     rows    = 20
     columns = 16
   IMPORTING
     error   = iref_error.
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 
 CALL METHOD iref_spreadsheet->insert_one_table
   EXPORTING
     ddic_name  = 'SPFLI'
     data_table = it_spfli[]
     rangename  = 'TEST'
     wholetable = 'X'
   IMPORTING
     error      = iref_error.
 
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 
 
 CALL METHOD iref_document->save_as
   EXPORTING
     file_name = 'C:\TEXT.XLS'
   IMPORTING
     error     = iref_error.
 
 IF iref_error->has_failed EQ 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
 ENDIF.
 

 CALL METHOD iref_document->close_document
   IMPORTING
     error = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
   LEAVE LIST-PROCESSING.
 ENDIF.
 
 CALL METHOD iref_document->release_document
   IMPORTING
     error = iref_error.
 IF iref_error->has_failed = 'X'.
   CALL METHOD iref_error->raise_message
     EXPORTING
       type = 'I'.
   LEAVE LIST-PROCESSING.
 ENDIF.
 
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics