*&---------------------------------------------------------------------*
*& Report ZDEMO_EXCEL36
REPORT zdemo_excel36.
DATA: lo_excel TYPE REF TO zcl_excel,
lo_worksheet TYPE REF TO zcl_excel_worksheet,
column_dimension TYPE REF TO zcl_excel_worksheet_columndime,
col type i.
DATA: guid_arial20 TYPE zexcel_cell_style,
gui_times11 TYPE zexcel_cell_style,
gui_cambria8red TYPE zexcel_cell_style.
CONSTANTS: gc_save_file_name TYPE string VALUE '36_DefaultStyles.xlsx'.
INCLUDE zdemo_excel_outputopt_incl.
START-OF-SELECTION.
" Creates active sheet
CREATE OBJECT lo_excel.
guid_arial20 = lo_excel->build_style( ip_font_name = zcl_excel_style_font=>c_name_arial
ip_font_scheme = zcl_excel_style_font=>c_scheme_none
ip_font_size = 20 ).
gui_times11 = lo_excel->build_style( ip_font_name = zcl_excel_style_font=>c_name_roman
ip_font_scheme = zcl_excel_style_font=>c_scheme_none
ip_font_size = 11 ).
gui_cambria8red = lo_excel->build_style( ip_font_name = zcl_excel_style_font=>C_NAME_CAMBRIA
ip_font_scheme = zcl_excel_style_font=>c_scheme_none
ip_font_size = 8
ip_font_color_rgb = zcl_excel_style_color=>c_red ).
lo_excel->set_default_style( guid_arial20 ). " Default for all new worksheets
* 1st sheet - do not change anything --> defaultstyle from lo_excel should apply
lo_worksheet = lo_excel->get_active_worksheet( ).
lo_worksheet->set_title( 'Style for complete document' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'All cells in this sheet are set to font Arial, fontsize 20' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 5 ip_value = 'because no separate style was passed for this sheet' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 6 ip_value = 'but a default style was set for the complete instance of zcl_excel' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that
* 2nd sheet - defaultstyle for this sheet set explicitly ( set to Times New Roman 11 )
lo_worksheet = lo_excel->add_new_worksheet( ).
lo_worksheet->set_title( 'Style for this sheet' ).
lo_worksheet->zif_excel_sheet_properties~set_style( gui_times11 ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'All cells in this sheet are set to font Times New Roman, fontsize 11' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 5 ip_value = 'because this style was passed for this sheet' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 6 ip_value = 'thus the default style from zcl_excel does not apply to this sheet' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that
* 3rd sheet - defaultstyle for columns ( set to Times New Roman 11 )
lo_worksheet = lo_excel->add_new_worksheet( ).
lo_worksheet->set_title( 'Style for 3 columns' ).
column_dimension = lo_worksheet->get_column_dimension( 'B' ).
column_dimension->set_column_style_by_guid( ip_style_guid = gui_times11 ).
column_dimension = lo_worksheet->get_column_dimension( 'C' ).
column_dimension->set_column_style_by_guid( ip_style_guid = gui_times11 ).
column_dimension = lo_worksheet->get_column_dimension( 'F' ).
column_dimension->set_column_style_by_guid( ip_style_guid = gui_times11 ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 4 ip_value = 'The columns B,C and F are set to Times New Roman' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 10 ip_value = 'All other cells in this sheet are set to font Arial, fontsize 20' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 11 ip_value = 'because no separate style was passed for this sheet' ).
lo_worksheet->set_cell( ip_column = 2 ip_row = 12 ip_value = 'but a default style was set for the complete instance of zcl_excel' ).
lo_worksheet->set_cell( ip_column = 8 ip_row = 1 ip_value = 'Of course' ip_style = gui_cambria8red ).
lo_worksheet->set_cell( ip_column = 8 ip_row = 2 ip_value = 'setting a specific style to a cell' ip_style = gui_cambria8red ).
lo_worksheet->set_cell( ip_column = 8 ip_row = 3 ip_value = 'takes precedence over all defaults' ip_style = gui_cambria8red ).
lo_worksheet->set_cell( ip_column = 8 ip_row = 4 ip_value = 'Here: Cambria 8 in red' ip_style = gui_cambria8red ).
* Set entry into each of the first 10 columns
DO 20 TIMES.
col = sy-index.
CASE col.
WHEN 2 " B
OR 3 " C
OR 6." F
lo_worksheet->set_cell( ip_column = col ip_row = 6 ip_value = 'Times 11' ).
WHEN OTHERS.
lo_worksheet->set_cell( ip_column = col ip_row = 6 ip_value = 'Arial 20' ).
ENDCASE.
ENDDO.
lo_worksheet->set_cell( ip_column = 2 ip_row = 1 ip_value = space ). " Missing feature "set active cell - use this to simulate that
lo_excel->set_active_sheet_index( 1 ).
*** Create output
lcl_output=>output( lo_excel ).