cancel
Showing results for 
Search instead for 
Did you mean: 

Add Caption in Exported internal table data To Excel

former_member192434
Active Contributor
0 Kudos

Hi Experts,

Kindly help to achieve the export to excel functionality.

I’m able to export the internal data into excel using below code, but i need to add the CAPTION for every column in excel base on Internal table data.

if anyone can help out it would be greatly appreciated.

data LO_ND_SFLIGHT type ref to IF_WD_CONTEXT_NODE.
  data LO_EL_SFLIGHT type ref to IF_WD_CONTEXT_ELEMENT.
  data LT_SFLIGHT type WD_THIS->elements_sflight1.
  data LS_SFLIGHT type WD_THIS->element_sflight1.
  data TEXT  type STRING.
  data XTEXT  type XSTRING.

* navigate from <CONTEXT> to <SFLIGHT> via lead selection
  LO_ND_SFLIGHT = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->wdctx_sflight1 ).
* get all declared attributes
  LO_ND_SFLIGHT->GET_STATIC_ATTRIBUTES_TABLE(
    importing
      TABLE = LT_SFLIGHT ).

  loop at LT_SFLIGHT into LS_SFLIGHT.
        concatenate TEXT
                      LS_SFLIGHT-CARRID
                      LS_SFLIGHT-CONNID
                      LS_SFLIGHT-FLDATE
                      LS_SFLIGHT-CURRENCY
                      LS_SFLIGHT-PLANETYPE
                      CL_ABAP_CHAR_UTILITIES=>NEWLINE into TEXT separated by
                      CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

ENDLOOP.


call function 'SCMS_STRING_TO_XSTRING'
    exporting
      TEXT  = TEXT
    importing
      BUFFER = XTEXT.
WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
**path to the word file
    I_FILENAME = 'WDP.xls'
* String Variable
    I_CONTENT =  XTEXT
* File Type
    I_MIME_TYPE = 'EXCEL' ).

Thanks

AB

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Anup,

     before you loop lt_sflight table you can add the column headings to the variable TEXT where each column text is separated by tab. After the above step, go ahead with looping the table and add the table content to TEXT variable.

Hope this helps,

~Athreya

former_member192434
Active Contributor
0 Kudos

Thanks

Answers (2)

Answers (2)

former_member184578
Active Contributor
0 Kudos

Hi,

Check this document http://scn.sap.com/docs/DOC-25024

Hope this helps u.,

Regards,

Kiran

former_member213217
Participant
0 Kudos

Hi Anup,

You would have to do something similar to what you are already doing to be able to download the column headers. Concatenate the desired column headers separated by horizontal tabs into a string variable say STR1. Now once you finish with your LOOP...ENDLOOP logic and arrive at the actual data in TEXT you can do another concatenate statement saying:

CONCATENATE STR1

                             TEXT into TEXT separated by CL_ABAP_CHAR_UTILITIES=>NEWLINE.

Then proceed with your calls to 'SCMS_STRING_TO_XSTRING' & ATTACH_FILE_TO_RESPONSE. Another word of advice here... You are not supposed to use any classes that start with WDR*. You should instead use: CL_WD_RUNTIME_SERVICES=> ATTACH_FILE_TO_RESPONSE.

Regards,

Uday