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 с использованием insert_one_table



 
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: Tue Oct 09, 2007 1:37 pm    Post subject: Выгрузка таблицы в Excel с использованием insert_one_table Reply with quote

Code:

* -- field catalog for range
  CALL FUNCTION 'DP_GET_FIELDS_FROM_TABLE'
    TABLES
      data   = it_excel
      fields = fields_table.
  DESCRIBE TABLE fields_table LINES columns_number.

...

  DESCRIBE TABLE p_excel LINES rows_number.
* -- create an excel range for our data
  CALL METHOD spreadsheet->insert_range_dim
    EXPORTING
      name     = p_rname         " это имя должно совпадать с именем в insert_one_table
      top      = p_y                   " координата y левого верхнего угла
      left     = p_x                    " координата х левого верхнего угла
      rows     = rows_number   " количество строк в вашей таблице
      no_flush = 'X'
      columns  = columns_number " столбцов в вашей таблице
    IMPORTING
      error    = error.

* -- transfer R/3 table data into excel range
  CALL METHOD spreadsheet->insert_one_table
    EXPORTING
      data_table   = p_excel[]
      rangename    = p_rname
      fields_table = fields_table
      no_flush     = 'X'
      wholetable   = 'X'
    IMPORTING
      error        = error.


Автор: Simmike
Code:
report z_doi_example.
data: i_control  type ref to i_oi_container_control.
data: i_document type ref to i_oi_document_proxy.
data: gr_container type ref to cl_gui_custom_container.

data: begin of gt_test occurs 0,
  st1(132),  st2(132),  st3(132),  st4(132),  st5(132),  st6(132),
  st7(132),  st8(132),  st9(132),  st0(132),
end of gt_test.

data: kk(2). " счетчик листов

data: name_old(20).
data: name_new(20).

parameter: f_name(30) default 'c:/my_excel.xls'. " имя файлика
parameter: n_list(15) default 'Мой Лист №'. " название листа (ов)
parameter: k_list(2) type n default 1. " kol-во листов

parameter: save as checkbox. " параметр сохранения файла
parameter: close as checkbox. " параметр закрытия файла и сохранения

*&---------------------------------------------------------------------*
start-of-selection.
 perform preparation.
 perform excel_processing.

*&---------------------------------------------------------------------*
*&      Form  preparation
form preparation.
* Creating the instance i_control
  call method c_oi_container_control_creator=>get_container_control
    importing
      control = i_control.

* Initializing control
  call method i_control->init_control
    exporting
      r3_application_name = 'R/3 application'
      parent              = gr_container
      inplace_enabled     = ' '
      no_flush            = ' '.
endform.                    "preparation

* тупо заполняю внутр табличку....
form full_int_tab.
 do 10 times.
  gt_test-st1 = 'abcdefg'.  gt_test-st2 = '10.07'.  gt_test-st3 = '11,01'.
  gt_test-s4 = '1.03'.  gt_test-st5 = 'hij6'.  gt_test-st6 = 'hijklmn12318'.
  gt_test-st7 = 'hijklmn65'.  gt_test-st8 = 'hijklmn'.  gt_test-st9 = 'hijk2'. 
  gt_test-st0 = 'hijklmer676n'.  append gt_test.
 enddo.

 clear gt_test.
 do 10 times.  append gt_test.  enddo.

 do 10 times.
  gt_test-st1 = 'abcdefg'.  gt_test-st3 = 'hijklmn3'.  gt_test-st6 = 'hi488'.
  gt_test-st8 = 'hiваывn'.  gt_test-st0 = 'hijk76n'.  append gt_test.
 enddo.
endform.

*&---------------------------------------------------------------------*
*&      Form  excel_processing
form excel_processing.
  data i_spreadsheet type ref to i_oi_spreadsheet.
  data gt_ftab type soi_fields_table with header line.
  data: error(1).

  call method i_control->get_document_proxy
    exporting
      document_type      = 'Excel.Sheet.8'
      register_container = 'X'
    importing
      document_proxy     = i_document.

  call method i_document->create_document
    exporting
      document_title = 'выгрузке из SAP'
      open_inplace = ' '.

  call method i_document->get_spreadsheet_interface
    importing
      sheet_interface = i_spreadsheet.

*** заполняем внутр табл
  refresh gt_test.  perform full_int_tab.
****

  call function 'DP_GET_FIELDS_FROM_TABLE'
    tables
      data   = gt_test[]
      fields = gt_ftab[].

* первый лист
  call method i_spreadsheet->insert_range_dim
    exporting
      no_flush = 'X'
      name     = 'tab1'
      left     = 1
      top      = 1
      rows     = 2
      columns  = 1.

 call method i_spreadsheet->GET_ACTIVE_SHEET
  importing
     SHEETNAME = name_old.

 kk = '01'. concatenate n_list kk into name_new.

 call method i_spreadsheet->set_sheet_name
  exporting
   oldname = name_old
   newname = name_new.

  call method i_spreadsheet->insert_one_table
    exporting
      data_table   = gt_test[]
      fields_table = gt_ftab[]
      rangename    = 'tab1'
      wholetable   = 'X'       " Х - чтобы количество сторок не огранич
      no_flush     = 'X'.

  k_list = k_list - 1.  if k_list < 0. k_list = 0. endif.
** 2ой и последующие листы....
  do k_list times.
    perform full_int_tab.
    kk = kk + 1.
    concatenate n_list kk into name_new.

    call method i_spreadsheet->add_sheet
     exporting
      no_flush = 'X'
      name     = name_new.

    call function 'DP_GET_FIELDS_FROM_TABLE'
     tables
       data   = gt_test[]
       fields = gt_ftab[].

    call method i_spreadsheet->insert_range_dim
     exporting
       no_flush = 'X'
       name     = 'ta1'
       left     = 1
       top      = 1
       rows     = 2
       columns  = 1.

    call method i_spreadsheet->insert_one_table
      exporting
       data_table   = gt_test[]
       fields_table = gt_ftab[]
       rangename    = 'ta1'
       wholetable   = 'X'  " Х - чтобы количество сторок не огранич
       no_flush     = 'X'.
  enddo.
  if save = 'X'.
    call method i_document->save_as
      exporting
        file_name = f_name.
  endif.
  if close = 'X'.
    call method i_document->save_as
      exporting
        file_name = f_name.

    call method i_document->close_document
      exporting
       do_save = 'X'
       no_flush = 'X'.
  endif.
  WRITE 'Excel document has been created...'.
endform.                    "excel_processing
 
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.