Skip to Content
avatar image
Former Member

Excel Export ALV webdynpro Abap

Hi all,

I want to export my context data with taking into acount he type of data for example DATS DD.MM.YYYY, NUMBERS.. Like they are displayed in the ALV in my web dynpro application.

I do not want to use standars buton from the ALV. we want to export data to excel from an other button. I m using this code from the wiki http://wiki.sdn.sap.com/wiki/display/WDABAP/Downloadafileintoexcel+sheet

but it seems not work for the specific caracters as (é,à,è,$ ....). How can we solve this problem ?

Please any suggestions

Best regards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Aug 23, 2010 at 11:24 AM

    Hi,

    Here is a sample code to download the table context to excel file by clicking on button.

    method ONACTIONEXPORT_TO_EXCEL .  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_SFLIGHT.
      data LS_SFLIGHT type WD_THIS->ELEMENT_SFLIGHT.  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_SFLIGHT ).
    * 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' ).    endmethod. 
    
    

    In the above code, My Conext nodes are SFLIGHT and AIRLINE.

    Hope it helps you to resolve your issue.

    Kinldy let me know if you face any problem.

    Regards

    Amarnath S

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you for replying

      As i said i use the code from http://wiki.sdn.sap.com/wiki/display/WDABAP/Downloadafileintoexcel+sheet.

      It's the same code , what i want is to solve the problem of export in order to taking into account the specific caracters é à è $ .... and displaying the same Type of data in the excel file that are displayed in my ALV.

      Any ideas please

  • Aug 23, 2010 at 11:50 AM

    Doing such a concatenation into a string, you will lose formatting. You might be able to save non-Latin 1 characters by converting the the string to Unicode (UTF-8) when going to the binary string.

    However the larger question is, why exactly do you not want to use the built in conversion to Excel?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi community,

      Here's the way I solved the problem thanks following SDN page [http://wiki.sdn.sap.com/wiki/display/ABAP/CSVtestsofencodingandcolumnseparator].

      The problem is that your file was probably encoded in UTF-8 and not opened with the correct encoding by Excel. If you encode your file like below, then it will be opened correctly by MS Excel.

      Regards,

      Jacques Duparc

           CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
              EXPORTING
                text     = lv_excel_string
                encoding = '4103'
              IMPORTING
                buffer   = lv_excel_xstring
              EXCEPTIONS
                failed   = 1.
      
            CONCATENATE  cl_abap_char_utilities=>byte_order_mark_little  lv_excel_xstring INTO  lv_excel_xstring IN BYTE MODE.