type-pools:soi,sbdst.
*&---------------------------------------------------------------------** class cl_doi definition
*&---------------------------------------------------------------------*
class cl_doi definition.
public section.
"constructor to receive parameters of template
methods: constructor
importing iv_container_name type c
iv_app_name type string optional
iv_classname type sbdst_classname
iv_classtype type sbdst_classtype
iv_object_key type sbdst_object_key
iv_doc_name type string
iv_sheet_name type c optional.
"set current sheet name of excel layout
methods: set_sheet
importing iv_sheet_name type c.
"execute macro function from excel layout
methods: execute_macro
importing iv_macro_string type c
iv_param_count type i
iv_param1 type any optional
iv_param2 type any optional
iv_param3 type any optional
iv_param4 type any optional
iv_param5 type any optional
iv_param6 type any optional
iv_param7 type any optional
iv_param8 type any optional
iv_param9 type any optional
iv_param10 type any optional
iv_param11 type any optional
iv_param12 type any optional.
"fill single cell data
methods: fill_cell
importing iv_row type i
iv_col type i
iv_value type string.
"set range into class range itab
methods: set_range
importing
iv_top type i
iv_left type i
iv_rows type i
iv_cols type i.
"add value into class content itab
methods: set_value
importing iv_row type i
iv_col type i
iv_value type string
iv_col_count type i.
"fill class content itab to content range itab
methods: fill_range_value.
"fill a table range data
methods: fill_table
importing iv_begin_row type i
iv_begin_col type i
iv_row_count type i optional
iv_col_count type i optional
it_out type standard table.
private section.
data: go_document type ref to i_oi_document_proxy,
go_spreadsheet type ref to i_oi_spreadsheet,
go_error type ref to i_oi_error,
gt_range type soi_range_list,
gs_range like line of gt_range,
gt_content type soi_generic_table,
gs_content like line of gt_content.
"handle error
methods: handle_error.
endclass. "cl_doi definition
*----------------------------------------------------------------------*
* class cl_doi implementation
*----------------------------------------------------------------------*
class cl_doi implementation.
method constructor.
data: lv_app_name(200) value 'Data from Excel report',
lo_bds type ref to cl_bds_document_set,
lt_doc_uris type sbdst_uri,
ls_doc_uris like line of lt_doc_uris,
lo_container type ref to cl_gui_custom_container,
lo_control type ref to i_oi_container_control,
lv_sheet_name(30) type c value 'Sheet1',
lt_doc_signature type sbdst_signature,
ls_doc_signature like line of lt_doc_signature,
lv_has_activex.
if iv_app_name is supplied.
lv_app_name = iv_app_name.
endif.
if iv_sheet_name is supplied.
lv_sheet_name = iv_sheet_name.
endif.
ls_doc_signature-prop_name = 'DESCRIPTION'.
ls_doc_signature-prop_value = iv_doc_name.
append ls_doc_signature to lt_doc_signature.
call function 'GUI_HAS_ACTIVEX'
importing
return = lv_has_activex.
if lv_has_activex is initial.
message 'ActiveX controls are not supported' type 'E'.
leave to screen 0.
endif.
"create container
create object lo_container
exporting
container_name = iv_container_name.
"create i_oi_container_control object
call method
c_oi_container_control_creator=>get_container_control
importing
control = lo_control
error = go_error.
me->handle_error( ).
call method lo_control->init_control
exporting
r3_application_name = lv_app_name
inplace_enabled = 'X'
inplace_scroll_documents = 'X'
parent = lo_container
register_on_close_event = 'X'
register_on_custom_event = 'X'
no_flush = 'X'
importing
error = go_error.
me->handle_error( ).
"get uri of the template
create object lo_bds.
call method lo_bds->get_with_url
exporting
classname = iv_classname
classtype = iv_classtype
object_key = iv_object_key
changing
signature = lt_doc_signature
uris = lt_doc_uris.
if sy-subrc <> 0.
message 'specified template not found!' type 'E'.
leave to screen 0.
endif.
read table lt_doc_uris into ls_doc_uris index 1.
free lo_bds.
"get spreadsheet object
call method lo_control->get_document_proxy
exporting
document_type = 'Excel.Sheet'
no_flush = 'X'
importing
document_proxy = go_document
error = go_error.
me->handle_error( ).
call method go_document->open_document
exporting
open_inplace = 'X'
document_url = ls_doc_uris-uri
importing
error = go_error.
if go_error->error_code eq 'OPEN_DOCUMENT_FAILED'.
message 'Spreadsheet is locked,load template error!' type 'E'.
leave to screen 0.
endif.
me->handle_error( ).
call method go_document->get_spreadsheet_interface
exporting
no_flush = ' '
importing
sheet_interface = go_spreadsheet
error = go_error.
me->handle_error( ).
"set sheet name
me->set_sheet(
exporting
iv_sheet_name = lv_sheet_name
).
endmethod. "CONSTRUCTOR
method set_sheet.
go_spreadsheet->select_sheet(
exporting
name = iv_sheet_name
importing
error = go_error
).
me->handle_error( ).
endmethod. "set_sheet
method execute_macro.
go_document->execute_macro(
exporting
macro_string = iv_macro_string
param1 = iv_param1
param10 = iv_param10
param11 = iv_param11
param12 = iv_param12
param2 = iv_param2
param3 = iv_param3
param4 = iv_param4
param5 = iv_param5
param6 = iv_param6
param7 = iv_param7
param8 = iv_param8
param9 = iv_param9
param_count = iv_param_count
importing
error = go_error
).
me->handle_error( ).
endmethod. "execute_macro
method fill_cell.
"set range
call method go_spreadsheet->set_selection
exporting
top = iv_row
left = iv_col
rows = 1
columns = 1
importing
error = go_error.
me->handle_error( ).
call method go_spreadsheet->insert_range
exporting
name = 'CELL'
rows = 1
columns = 1
no_flush = ''
importing
error = go_error.
me->handle_error( ).
gs_range-name = 'CELL'.
gs_range-rows = 1.
gs_range-columns = 1.
append gs_range to gt_range.
gs_content-row = iv_row.
gs_content-column = iv_col.
gs_content-value = iv_value.
append gs_content to gt_content.
"set content
call method go_spreadsheet->set_ranges_data
exporting
ranges = gt_range
contents = gt_content
importing
error = go_error.
me->handle_error( ).
clear: gt_range,gt_content.
endmethod. "fill_cell
method fill_table.
data: lv_rows type i,
lv_cols type i,
lt_ftab type table of rfc_fields.
if iv_row_count is supplied.
lv_rows = iv_row_count.
else.
describe table it_out lines lv_rows.
endif.
check lv_rows gt 0.
call function 'DP_GET_FIELDS_FROM_TABLE'
tables
data = it_out
fields = lt_ftab.
if iv_col_count is supplied.
lv_cols = iv_col_count.
else.
describe table lt_ftab lines lv_cols.
endif.
"set range
call method go_spreadsheet->insert_range_dim
exporting
name = 'TABLE'
no_flush = ' '
top = iv_begin_row
left = iv_begin_col
rows = lv_rows
columns = lv_cols
importing
error = go_error.
me->handle_error( ).
"set data
call method go_spreadsheet->insert_one_table
exporting
data_table = it_out
fields_table = lt_ftab
rangename = 'TABLE'
no_flush = ' '
importing
error = go_error.
me->handle_error( ).
endmethod. "fill_items
method handle_error.
check go_error->has_succeeded ne 'X'.
go_error->raise_message(
exporting
type = 'E'
).
endmethod. "raise_message
method fill_range_value.
call method go_spreadsheet->set_ranges_data
exporting
ranges = gt_range
contents = gt_content
importing
error = go_error.
me->handle_error( ).
clear: gt_range,gt_content.
endmethod. "fill_range_value
method set_range.
data lv_ctr type i.
"set position and range
call method go_spreadsheet->set_selection
exporting
top = iv_top
left = iv_left
rows = 1
columns = 1
importing
error = go_error.
me->handle_error( ).
call method go_spreadsheet->insert_range
exporting
name = 'CELL'
rows = iv_rows
columns = iv_cols
no_flush = ' '
importing
error = go_error.
me->handle_error( ).
gs_range-name = 'CELL'.
gs_range-rows = iv_rows.
gs_range-columns = iv_cols.
append gs_range to gt_range.
do iv_rows times.
lv_ctr = sy-index.
do iv_cols times.
gs_content-row = lv_ctr.
gs_content-column = sy-index.
gs_content-value = ''.
append gs_content to gt_content.
enddo.
enddo.
endmethod. "FILL_CELL
method set_value.
data lv_index type i.
gs_content-row = iv_row.
gs_content-column = iv_col.
gs_content-value = iv_value.
lv_index = ( iv_row - 1 ) * iv_col_count + iv_col.
modify gt_content from gs_content index lv_index.
endmethod. "set_value
endclass. "cl_doi implementation