cancel
Showing results for 
Search instead for 
Did you mean: 

ALV in WDA - Export to Excel File - How to add custom header 'on the fly'

marcin_makowski
Explorer
0 Kudos

Hello Abap Geeks,

On my current project I got following requirement. For all indicated WDA reports in my application, that provide Excel Export feature to the users, we need to add PROPRIETARY INFORMATION header to the downloaded Excel file (simple text statement) and additionally some footer information (timestamp, user ID etc.).

Is there any standard (SAP provided) way to do that in WDA ALV, or do I rather will need to code my own Excel Export functionality to cover that?

Any ideas are welcomed.

Cheers,

Marcin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Marcin,

If you want like this functionality, you have to create your custom button, and write code according this.

You have to write code manually to export data to excel. OR if you are using ALV use standard functionality.

Cheers,

Kris.

marcin_makowski
Explorer
0 Kudos

Thanks for the answers. That's what I was afraid of - it needs to be developed as an action for my custom download button. Kind of strange that this kind of functionality is not provided by standard Excel Download function.

I leave the thread open in case there's is a solution eventually.

Cheers,

Marcin

Former Member
0 Kudos

I used this as Header and footer for my excel and pdf export. Header is shown on the first page, and footer is shown only on last page.


method WDDOINIT .
  " alv data
  data lo_cmp_usage type ref to if_wd_component_usage.
  DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
  DATA lv_value TYPE ref to cl_salv_wd_config_table.
  " context data
  DATA lo_nd_alv_flights_header TYPE REF TO if_wd_context_node.
  DATA lo_el_alv_flights_header TYPE REF TO if_wd_context_element.
  DATA lo_nd_alv_flights_footer TYPE REF TO if_wd_context_node.
  DATA lo_el_alv_flights_footer TYPE REF TO if_wd_context_element.
  " alv header and footer data
  DATA lo_layout_grid TYPE ref to CL_SALV_FORM_LAYOUT_GRID.
  DATA lo_grid_cell11 TYPE ref to CL_SALV_FORM_TEXT.
  DATA lo_grid_cell12 TYPE ref to CL_SALV_FORM_TEXT.
  DATA lo_grid_cell13 TYPE ref to CL_SALV_FORM_TEXT.
  DATA lo_grid_cell21 TYPE ref to CL_SALV_FORM_TEXT.
  DATA lo_grid_cell22 TYPE ref to CL_SALV_FORM_TEXT.
  DATA lo_grid_cell31 TYPE ref to CL_SALV_FORM_TEXT.
  DATA lo_footer TYPE ref to CL_SALV_FORM_TEXT.


  "intialize component
  lo_cmp_usage =   wd_this->wd_cpuse_my_alv( ).
  if lo_cmp_usage->has_active_component( ) is initial.
    lo_cmp_usage->create_component( ).
  endif.

  "get the configuration table in order to deactivate the ALV top of list and end of list.
  lo_INTERFACECONTROLLER =   wd_this->wd_cpifc_my_alv( ).
  lv_value = lo_interfacecontroller->get_model( ).

  "default value is set to abap_true. One must always deactivate them so that
  "the neaders are not shown in the GUI, only in the excel and pdf exported files
  lv_value->IF_SALV_WD_TABLE_SETTINGS~SET_TOP_OF_LIST_VISIBLE( abap_false ).
  lv_value->IF_SALV_WD_TABLE_SETTINGS~SET_END_OF_LIST_VISIBLE( abap_false ).

  "get the context elements for alv header and footer
  lo_nd_alv_flights_header = wd_context->get_child_node( name = wd_this->wdctx_alv_flights_header ).
  lo_el_alv_flights_header = lo_nd_alv_flights_header->get_element( ).
  lo_nd_alv_flights_footer = wd_context->get_child_node( name = wd_this->wdctx_alv_flights_footer ).
  lo_el_alv_flights_footer = lo_nd_alv_flights_footer->get_element( ).

  "creating the layout grid for the alv header and the grid cell for it
  create object lo_layout_grid.
  create object lo_grid_cell11.
  create object lo_grid_cell12.
  create object lo_grid_cell13.
  create object lo_grid_cell21.
  create object lo_grid_cell22.
  create object lo_grid_cell31.
  create object lo_footer.

  "setting the grid elements with texts
  lo_grid_cell11->Set_text( 'R1C1: Header' ).
  lo_layout_grid->set_element( row = 1 column = 1 r_element = lo_grid_cell11 ).
  lo_grid_cell12->Set_text( 'R1C2: I can contain any text' ).
  lo_layout_grid->set_element( row = 1 column = 2 r_element = lo_grid_cell12 ).
  lo_grid_cell13->Set_text( 'R1C3: 2011.08.19' ).
  lo_layout_grid->set_element( row = 1 column = 3 r_element = lo_grid_cell13 ).
  lo_grid_cell21->Set_text( 'R2C1: This is the second row' ).
  lo_layout_grid->set_element( row = 2 column = 1 r_element = lo_grid_cell21 ).
  lo_grid_cell22->Set_text( 'R2C2: Row lengths can be identical or different' ).
  lo_layout_grid->set_element( row = 2 column = 2 r_element = lo_grid_cell22 ).
  lo_grid_cell31->Set_text( 'R3C1: Third row' ).
  lo_layout_grid->set_element( row = 3 column = 1 r_element = lo_grid_cell31 ).

* set the header of the ALV to the grid element
  lo_el_alv_flights_header->set_attribute(
    name =  `CONTENT`
    value = lo_layout_grid ).

* set the footer of the ALV to a simple text
  lo_footer->Set_text( 'This is the footer. I can also be replaced py a grid design.' ).
  lo_el_alv_flights_footer->set_attribute(
    name =  `CONTENT`
    value = lo_footer ).



endmethod.

To activate and deactivate in the GUI the headers and footer one has to use these lines instead of the above ones, or just leve them out because the standard parameter is abar_true


  lv_value->IF_SALV_WD_TABLE_SETTINGS~SET_TOP_OF_LIST_VISIBLE( abap_true ).
  lv_value->IF_SALV_WD_TABLE_SETTINGS~SET_END_OF_LIST_VISIBLE( abap_true ).

marcin_makowski
Explorer
0 Kudos

Thank you Smih,

That should simplify the things greatly.

Points rewarded.

Cheers,

Marcin

Former Member
0 Kudos

Helo SMH,

I would like to know how you have defined the header and footer in the context node

What is the type definition used?

Answers (1)

Answers (1)

Former Member
0 Kudos

I don't see any method in IF_SALV_WD_EXPORT_SETTINGS to handle your requirement. You may have to manually handle this by adding header and footer then downloading to excel file.