Posted: Tue Oct 09, 2007 1:37 pm Post subject: Выгрузка таблицы в Excel с использованием insert_one_table
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. " параметр закрытия файла и сохранения
*&---------------------------------------------------------------------*
*& Form preparation
form preparation.
* Creating the instance i_control
call method c_oi_container_control_creator=>get_container_control
importing
control = i_control.
*&---------------------------------------------------------------------*
*& 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_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
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.