Download data to excle

I want download internal table to execle
please help me .
   thanks every one.

Hi friend,
try out this code, this will help you,
Reward for the same.
thankyou,
REPORT RSDEMO01 NO STANDARD PAGE HEADING.
this report demonstrates how to send some ABAP data to an
EXCEL sheet using OLE automation.
INCLUDE OLE2INCL.
handles for OLE objects
DATA: H_EXCEL TYPE OLE2_OBJECT,        " Excel object
      H_MAPL TYPE OLE2_OBJECT,         " list of workbooks
      H_MAP TYPE OLE2_OBJECT,          " workbook
      H_ZL TYPE OLE2_OBJECT,           " cell
      H_F TYPE OLE2_OBJECT.            " font
TABLES: SPFLI.
DATA  H TYPE I.
table of flights
DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
*&   Event START-OF-SELECTION
START-OF-SELECTION.
read flights
  SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
display header
  ULINE (61).
  WRITE: /     SY-VLINE NO-GAP,
          (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
          (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
          (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
          (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
          (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
  ULINE (61).
display flights
  LOOP AT IT_SPFLI.
  WRITE: / SY-VLINE NO-GAP,
           IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
           IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
           IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
           IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
           IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
  ENDLOOP.
  ULINE (61).
tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
          PERCENTAGE = 0
           TEXT       = TEXT-007
       EXCEPTIONS
            OTHERS     = 1.
start Excel
  CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
  PERFORM ERR_HDL.
  SET PROPERTY OF H_EXCEL  'Visible' = 1.
  PERFORM ERR_HDL.
tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
          PERCENTAGE = 0
           TEXT       = TEXT-008
       EXCEPTIONS
            OTHERS     = 1.
get list of workbooks, initially empty
  CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
  PERFORM ERR_HDL.
add a new workbook
  CALL METHOD OF H_MAPL 'Add' = H_MAP.
  PERFORM ERR_HDL.
tell user what is going on
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
          PERCENTAGE = 0
           TEXT       = TEXT-009
       EXCEPTIONS
            OTHERS     = 1.
output column headings to active Excel sheet
  PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
  PERFORM FILL_CELL USING 1 2 1 'Nr'(002).
  PERFORM FILL_CELL USING 1 3 1 'Von'(003).
  PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
  PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
  LOOP AT IT_SPFLI.
copy flights to active EXCEL sheet
    H = SY-TABIX + 1.
    PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
    PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
    PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
    PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
    PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
  ENDLOOP.
disconnect from Excel
  FREE OBJECT H_EXCEL.
  PERFORM ERR_HDL.
      FORM FILL_CELL                                                *
      sets cell at coordinates i,j to value val boldtype bold       *
FORM FILL_CELL USING I J BOLD VAL.
  CALL METHOD OF H_EXCEL 'Cells' = H_ZL EXPORTING #1 = I #2 = J.
  PERFORM ERR_HDL.
  SET PROPERTY OF H_ZL 'Value' = VAL .
  PERFORM ERR_HDL.
  GET PROPERTY OF H_ZL 'Font' = H_F.
  PERFORM ERR_HDL.
  SET PROPERTY OF H_F 'Bold' = BOLD .
  PERFORM ERR_HDL.
ENDFORM.
*&      Form  ERR_HDL
      outputs OLE error if any                                      
-->  p1        text
<--  p2        text
FORM ERR_HDL.
IF SY-SUBRC <> 0.
  WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
  STOP.
ENDIF.
ENDFORM.                    " ERR_HDL

Similar Messages

  • Downloading data from internal table to xls file leading zeros are not disp

    Hai abap gurus,
    when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
    Ex:
    <b>ECC Code.</b>
    045234
      88567
    098456 
    but output is giving like this:
    45234
    88567
    98456
    how to get the actual values.....
    plz help me in this matter.

    Dear Kiran,
    Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
    Then use the function module to download the content of the internal table to the excel file.
    Regards,
    Abir
    Don't forget to Reward Points  *

  • Downloading data in excel sheet

    Hi All,
        I want to download data in excel sheet. My requirment is to use the same excle sheet to fill data.
    The next data should be entered in the column of the excel sheet. Is there a possible to write data in excel sheet at a particular row/column.
       Please let me know if this can be achevied?
    For Ex:
    Data: 10, 20, 30
    Excel sheet:
    10
    20
    30
    Data: 40, 50, 60
    Excel sheet:
    10          40
    20          50
    30          60
    Thanks & Regards,
    Rupali Ray

    Hi,
    This should be possible by OLE concept.
    Have a look at report RSDEMO01
    Regards

  • Downloading data to excel

    Hi all,
    I am downloading data to excel by using OLE2 type pool in an ABAP program.
    My requirement is to make some of the columns of the excel sheet bold.
    is it possible? if so please guide me.
    LOOP AT IT_FINAL1 INTO WA_FINAL1.
        R_IND = 1 + R_IND.
        INDEX  = 1 +  SY-TABIX  .
        CLEAR IND.
        DO.
          ASSIGN COMPONENT SY-INDEX OF STRUCTURE  WA_FINAL1 TO <I_OUTPUT>.
          IF SY-SUBRC NE 0.
            EXIT.
          ENDIF.
          IND =  SY-INDEX.
          CALL METHOD OF SHEET 'Cells' = CELLS EXPORTING #1 = INDEX
            #2 = IND.  "1
          SET PROPERTY OF CELLS 'Value' = <I_OUTPUT>.
        ENDDO.
        CALL METHOD OF APPLICATION 'Cells' = CELL1
          EXPORTING #1 = 1
          #2 = 7.
        CALL METHOD OF APPLICATION 'Cells' = CELL2
           EXPORTING
             #1 = INDEX     "down
             #2 = 7.       "across
      ENDLOOP.
    I have used the above code.
    here 7th column, 10th column, 13th column  has to be made bold and so on.
    regards,
    samarendra.
    Edited by: samarendra penugonda on May 26, 2009 12:57 PM

    Hello,
    Check this standard program it is printing some values in bold.
    RSDEMO01
    Example
      SET PROPERTY OF H_F 'Bold' = BOLD .

  • Download data from ALV to excel issue

    Hi All,
    Could you please tell me if there has any restriction on ALV grid data download to excel? I've a report contains 68 columns and about 500 rows, I want to download the data using the standard menu list->export->save to local file. but after I download them, I found the first 65 columns display in one line and the rest columns display in next line, just like ALV do not allow too many characters in one row and have to switch to new line. I can hide some columns but it's very strange that even after i hide 3 columns to fit the 500 rows download, then if the rows increase, the same problem occurs.
    I searched the forum and in the thread Re: Export ALV in EXCEL Issue Mr. Suvajit provided a solution by using menu List->export->spreadsheet, it looks very good. But I still want to know how this happen and is there a standard way to download data with more than 65 columns to local file with extension .xls so that user can open it directly?
    PS: I'm using FM REUSE_ALV_GRID_DISPLAY and the SAP version is SAP ECC6 with kernal package SAPKB70103.
    Thank you very much.
    Best Regards,
    Jeff
    Edited by: Jeff_liu_2010 on Mar 10, 2011 7:21 AM

    Hi Jeff,
    Please check if following analysis is helpful to you.
    Analysis/Solution:
    When we export ALV data to excel worksheet, as sap notes say the maximum lenght allowed is 1023 charaters and the max no of columns supported is 90.
    (I never faced any issue related to no of columns as it worked fine for columns >90 too)
    Issue occured when row size of exported data gets more than 1023 character.
    Therefore the row data must not exceed 1023 character, otherwise column splits and moves to next row.
    One additional aspect generally missed is that:
    When data in any particular column changes it's length, alv header also changes its lengh (short text, medium text, long text; depending on the length of of the longest cell in the column)
    therefore even if you have total length of row less than 1023 character, there might be cases when your ALV header size exceeds this length.
    Reducing the header size (by forcing to use short text or specifying own header names) should resolve the issue.
    Regards,
    Parveen

  • Problem in downloading data from application server

    Hi,
    I tried the following code for downloading data to PC in background:
    PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.
    OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc = 0.
        LOOP AT itab INTO istab.
          TRANSFER istab TO p_file.
        ENDLOOP.
    ENDIF.
    Here, the contents are not getting transferred to the p_file. I give the path of the file while executing the program.
    First of all, the file is not getting created in PC. And the statement 'OPEN DATASET p_file FOR INPUT IN TEXT MODE ENCODING DEFAULT'. is working but unable to read after that using READ DATASET statement.

    HI,
    You can use this code .............
    OPEN DATASET gv_dataset for input in text mode encoding default.
      IF sy-subrc = 0.
        DO.
          clear gv_rec.
          READ DATASET gv_dataset INTO gv_rec.
          if sy-subrc <> 0.
            append gv_rec to gt_raw.
            exit.
          endif.
          append gv_rec to gt_raw.
        ENDDO.
        CLOSE DATASET gv_dataset.
      ELSE.
        gv_retcode = 1.
      ENDIF.
    Regards,
    jayan

  • How to download data into one cell of excel in different lines

    Hi All,
    My Report downloads data from R/3 to excel. Now one particular field contains multiple lines, which i needs to download into different lines into that particular cell(of excel). how can i do this.
    I found one method for this and that is cl_abap_char_utilities=>newline.But this is in abap version 6.0.
    But i am working in version 4.6c. do we have any method or anything that meets my requirement in 4.6c.
    Please let me know.
    Thanx in Advance
    Subhani.

    why do you split them to the internal table ,then download it?
    Is you special field long text?
    If is ,you can use FM READ_TEXT to put it into an internal table ,then download it.

  • Download data from interactive report

    Hi all. I'm on apex 3.1.1.00.09.
    I have this problem: when I download data from interactive report I can download only in CSV and PDF. If I try to download into pdf it creates a file of only 1 KB.
    I would know if I must configure my apex in order to download correctly in pdf and if I must configure it in order to download in doc and xls format.
    Thanks all for collaboration,
    Fabrizio

    Thank you for your reply.
    I am able to download the csv file, but my problem is: I don't want the column headings to show.
    Is it possible to download only the data, not the column headings?

  • Download Data is not working in Dashboard Report??

    I tried to Download Data in Report and it gives me error message.Does any one faced this issue before.I tried this forum but coudn't get the enough information.Your help is appreciated.

    hi,
    sorry for the previus post....sleepingg...
    try to think...
    1.this happenig with all the reports???
    try to download a simple one,without charts...
    2.have you tried to log in as other user,
    which is the result??
    3.check in the analytics,the security...
    Does it have the user log on,
    available priviledges???
    end,get firebug,and check the appropriate css
    http://obiee101.blogspot.com/2009/07/obiee-dashboard-default-controls.html
    hope i helped....
    http://greekoraclebi.blogspot.com/
    ///////////////////////////////////////

  • How to download data into  two different columns 2003 excel format in ole

    Hi ALL
    when we download data into excel using ole with delimiter it works fine in 2007 but when we check this with 2003 format
    both fields come in only one column .Can any one suggest  
      CONCATENATE WA_ALL-PERNR LV_ICNUM INTO WA_PERNR SEPARATED BY W_DELI   IN CHARACTER MODE.

    If you're already using OLE, you can fill in value for each cell separately instead of using a delimiter. Something like this fragment:
    FORM fill_cell USING p_row p_col p_value.
      CALL METHOD OF obj_excel 'CELLS' = obj_cell
        EXPORTING
        #1 = p_row
        #2 = p_col.
      SET PROPERTY OF obj_cell 'VALUE' = p_value.
    ENDFORM.                    "fill_cell

  • How to download data from a an external hard drive ?j

    How to download data from an external hd ?

    You need to copy the data onto your computer and transfer it via that (either via iTunes, or if the app that you want to transfer the data to supports, via wifi). Like the previous reply said, you can't do it directly without a computer being involved.

  • Error while downloading data from internal table into XML file

    hi all,
    i developed a program to download data from into internal table to xml file like this.
    tables: mara.
    parameters: p_matnr like mara-matnr.
    data: begin of itab_mara occurs 0,
                matnr like mara-matnr,
                ernam like mara-ernam,
                aenam like mara-aenam,
                vpsta like mara-vpsta,
          end of itab_mara.
    data: lv_field_seperator type c,     " value 'X',
          lv_xml_doc_name(30) type c,    " string value ‘my xml file’,
          lv_result type i.
          lv_field_seperator = 'x'.
          lv_xml_doc_name = 'my xml file'.
    types: begin of truxs_xml_line,
              data(256) type x,
          end of truxs_xml_line.
    types:truxs_xml_table type table of truxs_xml_line.
    data:lv_tab_converted_data type truxs_xml_line,
         lt_tab_converted_data type truxs_xml_table.
    data: lv_xml_file type rlgrap-filename value 'c:\simp.xml'.
    select matnr ernam aenam vpsta from mara into table itab_mara up to 5
           rows where matnr = p_matnr.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    EXPORTING
       I_FIELD_SEPERATOR          = lv_field_seperator
      I_LINE_HEADER              =
      I_FILENAME                 =
      I_APPL_KEEP                = ' '
       I_XML_DOC_NAME             = lv_xml_doc_name
    IMPORTING
       PE_BIN_FILESIZE            = lv_result
      TABLES
        I_TAB_SAP_DATA             = itab_mara
    CHANGING
       I_TAB_CONVERTED_DATA       = lt_tab_converted_data
    EXCEPTIONS
      CONVERSION_FAILED          = 1
      OTHERS                     = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    open dataset lv_xml_file for output in binary mode.
    loop at lt_tab_converted_data into lv_tab_converted_data.
    transfer lv_tab_converted_data to lv_xml_file.
    endloop.
    close dataset lv_xml_file.
    this program is syntactically correct and getting executed, but when i open the target xml file it is showing the following error.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'file:///C:/simp.xml'.
    will anyone show me the possible solution to rectify this error
    thanks and regards,
    anil.

    Hi,
    Here is a small sample program to convert data in an internal table into XML format and display it.
    DATA: itab  TYPE TABLE OF spfli,
          l_xml TYPE REF TO cl_xml_document.
    * Read data into a ITAB
    SELECT * FROM spfli INTO TABLE itab.
    * Create the XML Object
    CREATE OBJECT l_xml.
    * Convert data in ITAB to XML
    CALL METHOD l_xml->create_with_data( name = 'Test1'
                                         dataobject = t_goal[] ).
    * Display XML Document
    CALL METHOD l_xml->display.
    Here are some other sample SAP programs to handle XML in ABAP:
    BCCIIXMLT1, BCCIIXMLT2, and BCCIIXMLT3.
    Hope this helps,
    Sumant.

  • Error in background job of downloading data to  PC

    Hi Gurus,
       I hv created a report for downloading data to PC using
    GUI_DOWNLOAD FM when scheduling  job in background
    job is getting canceled...................
    give me some solution....

    thnaks friend.i hv used DATASET as u said...............
    But I M getting dump
    FILE IS NOT OPEN
    this is my code
    TYPES:BEGIN OF T_MARD,
            MATNR LIKE MARD-MATNR,
            WERKS LIKE MARD-WERKS,
            LGORT LIKE MARD-LGORT,
            LABST LIKE MARD-LABST,
            MAKTX LIKE MAKT-MAKTX,
         END OF T_MARD.
    ***********WORK AREAS**********
    DATA: WA_MARD TYPE T_MARD,
          WA_MARD1 TYPE T_MARD.
    DATA:BEGIN OF IT_MARD1 OCCURS 0,
            MATNR(18),
            WERKS(4),
            LGORT(4),
            LABST(13),
            MAKTX(40),
         END OF IT_MARD1.
    TYPES : BEGIN OF TY_BAT,
              LINE(100) TYPE C,
            END OF TY_BAT.
    *********INTERNAL TABLES*******
    DATA:IT_MARD TYPE STANDARD TABLE OF T_MARD INITIAL SIZE 0 WITH HEADER LINE .
    types: BEGIN OF ITAB1,
                FIELD(100),
          END   OF ITAB1.
    DATA : IT_BAT TYPE TABLE OF TY_BAT,
           WA_BAT TYPE TY_BAT,
           wa_itab1 type itab1.
    data : it_tab type table of ALSMEX_TABLINE with header line.
    *DATA: FILENAME1 TYPE STRING valu.
    *DATA: FILENAME1(500).
    DATA: FILENAME1 TYPE RLGRAP-FILENAME .
    LOOP AT IT_MARD1.
          CONCATENATE IT_MARD1-MATNR IT_MARD1-LABST IT_MARD1-MAKTX
                      INTO wa_ITAB1    SEPARATED BY ' '.
          APPEND wa_itab1 to IT_tab.
          CLEAR wa_ITAB1.
        CLEAR WA_MARD.
      ENDLOOP.
      CONCATENATE 'D:\STOCKINH\'  SY-DATUM '.TXT' INTO FILENAME1.
    open dataset filename1 for output in binary mode." ENCODING DEFAULT.
    IF sy-subrc = 0.
    EXIT.
    ENDIF.
    LOOP AT it_tab into wa_itab1.
    TRANSFER wa_itab1 TO filename1.
    CLEAR wa_itab1.
    ENDLOOP.
    close dataset filename1.
      MESSAGE S001(38) WITH 'Files Generated'.
      WA_BAT = 'ftp -s:d:\ftp\ftp_upload.txt'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR FILENAME1.
       FILENAME1 = 'D:\STOCKINH\ftp_upload.BAT'.
    open dataset filename1 for output in binary mode." ENCODING DEFAULT.
    IF sy-subrc = 0.
    EXIT.
    ENDIF.
    LOOP AT it_bat INTO wa_bat.
    TRANSFER wa_bat TO filename1.
    CLEAR wa_bat.
    ENDLOOP.
    close dataset filename1.
      CLEAR:  IT_BAT.
      REFRESH IT_BAT.
      WA_BAT-LINE = 'open 10.100.103.199'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'epossync'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'sync@1234'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'lcd D:\STOCKINH\20080201.TXT'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'cd /home/epossync/AMIT'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'binary'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'hash'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'put D:\STOCKINH\20080201.txt'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = ' '.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
      WA_BAT-LINE = 'bye'.
      APPEND WA_BAT TO IT_BAT.
      CLEAR WA_BAT.
    CLEAR FILENAME1.
    FILENAME1 = 'D:\STOCKINH\ftp_upload.txt'.
    open dataset filename1 for output in binary mode." ENCODING DEFAULT.
    IF sy-subrc  = 0.
    EXIT.
    ENDIF.
    LOOP AT it_bat INTO wa_bat.
    TRANSFER wa_bat TO filename1.
    CLEAR wa_bat.
    ENDLOOP.
    close dataset filename1.

  • Error while downloading data into excel file.

    Hi,
        I have a requirement to download data available in xstring to excel file.
    I have a RFC which has export parameter 'file_data' of type xstring. When i call RFC
    from web dynpro abap application it gives data out pout in xstring format.
    I am opening excel file using that xstring data as below
    cl_wd_runtime_services=>attach_file_to_response(
    i_filename = 'file.xls'
    i_content = ls_data_source-data_source   ***[xstring data from RFC]
    i_mime_type = 'x-excel/application'
    i_in_new_window = abap_true ).
    But excel file not coming in correct format. its  giving an error while download
    excel file
    Error is
          " the file you are trying to open , 'file[1].xls', is in a different format than
    specified by the file extension. Verify that the file is not corrupted and is from
    a trusted source before opening the file. Do you want to open the file now? "
    If i click on 'YES' button file opening but not in proper excel format. Data is coming
    in tab delimiter format in excel file.
    Please suggest any solution for this problem.
    Thanks,
    Venkat.

    Hi Thomas,
    Following is the logic implemented in RFC which is giving XSTRING as export parameter
    STEP1      create a dynamic internal table
               Create field catalog for the table   using LVC_FIELDCATALOG_MERGE
                   CALL METHOD cl_alv_table_create=>create_dynamic_table
                        EXPORTING
                           it_fieldcatalog = it_fieldcat
                         IMPORTING
                           ep_table        = dyn_table.
                  CREATE  EXCEL SHEET BY SENDING FIELD CATALOG AND DATA TAB
    STEP2 # Convert text table to xstring.
            CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'
              IMPORTING
                buffer   = l_content
              TABLES
                text_tab = lt_data_tab
              EXCEPTIONS
                failed   = 1
                OTHERS   = 2.
    STEP3  *# Psss Data to Netweaver
              PERFORM pass_data_to_nw USING is_import
                                      CHANGING es_attachment_metadata.

  • How to download  data into XLSX file in ABAP ECC 6.0 using FM: GUI_DOWNLOAD or any other FunctionModules

    Hi ABAP Exterts,
    Any one help on this , there is a requirement to download the data into XLSX file only.
    I am able to to download the data into XLS file using the FM: GUI_DOWNLOAD in SAP ECC 6.0and also opening the file . But when i download the data into XLSX file . I am able to download the data into GUI_DOWNLOAD. But while opening the file i am getting the below mentioned error.
    'Excel cannot open the file 'filename.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file'
    Ok buttom is coming not able to open the file.
    When i use the FM: SAP_CONVERT_TO_XLS_FORMAT to download the XLS it self it is going abap DUMP that file type error.
    Any one help  any Function Module or how to download data through abap programing into XLSX file.
    Thanks.
    Murali.
    Message was edited by: Matthew Billingham - adjusted wording...

    If you want to download your ALV to an .XLXS format file, with all the formatting intact, please try the following code. I have tried to create a custom Function module Z_EXCEL_DOWNLOAD_TEST wherein I pass all the callback variables, the final ALV internal table and all the ALV details like field catalog, sort, layout, event list and so on, along with the concatenated file path and file name in I_FILE. I have used a custom class ZCL_SALVEXPORT_XML which is a copy of the standard class CL_SALV_EXPORT_XML_DIALOG, with few modifications in Method: EXECUTE and Method: DOWNLOAD. The methods where I have modified the code are also shown at the end.
    ****************Global declarations***********************
    TYPE-POOLS: slis,
    kkblo.
    TYPES: t_fccls(1) TYPE c OCCURS 0.
    TYPES: BEGIN OF ty_nosum,
    fieldname     TYPE kkblo_fieldname,           "Field name
    tabname       TYPE kkblo_tabname,             "Table name
    fieldname_dep TYPE kkblo_fieldname,           "Field name
    tabname_dep   TYPE kkblo_tabname,             "Table name
    index         TYPE sy-index,                  "Index
    END OF ty_nosum.
    TYPES: t_nosum TYPE TABLE OF ty_nosum INITIAL SIZE 0 WITH NON-UNIQUE DEFAULT KEY.
    TYPES: BEGIN OF ty_dep_field,
    s_dep_fieldcat TYPE kkblo_fieldcat,            "Field cat
    t_ref_fieldcat TYPE kkblo_t_fieldcat,          "Field cat
    END OF ty_dep_field.
    TYPES: BEGIN OF ty_ref_field,
    s_ref_fieldcat TYPE kkblo_fieldcat,           "Field cat
    s_dep_fieldcat TYPE kkblo_fieldcat,           "Field cat
    END OF ty_ref_field.
    TYPES: t_dep_field TYPE ty_dep_field OCCURS 0.        "
    TYPES: t_ref_field TYPE ty_ref_field OCCURS 0.
    TYPES: BEGIN OF ty_memory,
    object(20)  TYPE c,                        "Object
    memcount(4) TYPE c,                        "count
    END OF ty_memory.
    *ALV Customer Wrapper
    TYPES: BEGIN OF ty_type_header_info,
    tabname   TYPE kkblo_tabname,            "Table name
    fieldname TYPE kkblo_fieldname,          "Field name
    sequence  TYPE i,                        "Sequence
    field     TYPE char80,                    "Field
    pagno     TYPE sypagno,                   "Page num
    linno     TYPE sy-linno,                  "Current Line in List
    colno     TYPE sy-colno,                  "Current List Column
    END   OF ty_type_header_info,
    t_type_header_info TYPE SORTED TABLE OF ty_type_header_info
    WITH UNIQUE KEY tabname fieldname.
    TYPES: BEGIN OF ty_type_row_info,
    tabname   TYPE kkblo_tabname,            "Table name
    tabindex  TYPE syindex,                  "Index
    field     TYPE char80,                   "Field name
    pagno     TYPE sypagno,                  "Page num
    linno     TYPE sy-linno,                 "Current Line in List
    colno     TYPE sy-colno,                 "Current List Column
    END   OF ty_type_row_info,
    t_type_row_info TYPE SORTED TABLE OF ty_type_row_info
    WITH UNIQUE KEY tabname tabindex.
    TYPES: BEGIN OF ty_type_sel_header,
    tabname   TYPE kkblo_tabname,           "table name
    fieldname TYPE kkblo_fieldname,         "field name
    END   OF ty_type_sel_header,
    t_type_sel_header TYPE SORTED TABLE OF ty_type_sel_header
    WITH UNIQUE KEY tabname fieldname.
    TYPES: BEGIN OF ty_type_sel_row,
    tabname   TYPE kkblo_tabname,
    tabindex  TYPE syindex,
    END   OF ty_type_sel_row,
    t_type_sel_row TYPE SORTED TABLE OF ty_type_sel_row
    WITH UNIQUE KEY tabname tabindex.
    TYPES: BEGIN OF ty_type_sel_cell,
    tabname   TYPE kkblo_tabname,
    tabindex  TYPE syindex,
    fieldname TYPE kkblo_fieldname,
    END   OF ty_type_sel_cell.
    TYPES: BEGIN OF ty_type_selections,
    t_row_info         TYPE t_type_row_info,
    t_header_info      TYPE t_type_header_info,
    t_selected_headers TYPE t_type_sel_header,
    t_selected_rows    TYPE t_type_sel_row,
    s_current_cell     TYPE ty_type_sel_cell,
    set_headers        TYPE sap_bool,
    set_rows           TYPE sap_bool,
    set_current_cell   TYPE sap_bool,
    END   OF ty_type_selections.
    TYPES: BEGIN OF ty_stack3,
    r_grid         TYPE REF TO cl_gui_alv_grid,        "Y6DK050176
    r_salv_adapter TYPE REF TO if_salv_adapter,
    s_selections   TYPE ty_type_selections,
    r_print_state  TYPE REF TO if_alv_print_parameter_proxy, "Y6DK075821
    suppress_empty_data TYPE abap_bool,
    END OF ty_stack3.
    TYPES: t_stack3 TYPE ty_stack3 OCCURS 0.
    TYPES: BEGIN OF ty_stack,
    i_callback_program       TYPE sy-repid,
    i_callback_user_command  TYPE kkblo_formname,
    i_callback_top_of_page   TYPE kkblo_formname,
    i_callback_top_of_list   TYPE kkblo_formname,
    i_callback_end_of_page   TYPE kkblo_formname,
    i_callback_end_of_list   TYPE kkblo_formname,
    i_callback_pf_status_set TYPE kkblo_formname,
    i_callback_fieldcat_save TYPE kkblo_formname,
    i_callback_layout_save   TYPE kkblo_formname,
    i_tabname                TYPE kkblo_tabname,
    i_tabname_slave          TYPE kkblo_tabname,
    is_keyinfo               TYPE kkblo_keyinfo,
    is_layout                TYPE kkblo_layout,
    it_fieldcat              TYPE kkblo_t_fieldcat,
    i_fctype(1)              TYPE c,
    it_excluding             TYPE kkblo_t_extab,
    it_special_groups        TYPE kkblo_t_sp_group,
    it_sort                  TYPE kkblo_t_sortinfo,
    it_except_qinfo          TYPE kkblo_t_qinfo,
    is_sel_hide              TYPE kkblo_sel_hide,
    t_columns                TYPE kkblo_t_columns,
    t_filter                 TYPE kkblo_t_filter,
    s_lprint                 TYPE kkblo_lprint,
    print_line_break         TYPE char1,
    t_isetab                 TYPE kkblo_seldis,
    t_fccls                  TYPE t_fccls,
    t_sfinfo                 TYPE kkblo_t_sfinfo,
    t_ref_field              TYPE t_ref_field,
    t_dep_field              TYPE t_dep_field,
    flg_default_status(1)    TYPE c,
    flg_selections           TYPE char1,
    flg_allow_no_selection   TYPE char1,
    flg_input                TYPE char1,
    flg_called               TYPE char1,
    flg_popup                TYPE char1,
    flg_endlist              TYPE char1,
    listtype                 TYPE char1,
    actcols                  TYPE i,
    is_list                  TYPE char1,
    END OF ty_stack.
    TYPES: t_stack TYPE ty_stack OCCURS 0.
    TYPES: BEGIN OF ty_stack2,
    button_col1(20)                TYPE c,
    button_col2(20)                TYPE c,
    button_col3(20)                TYPE c,
    button_col4(20)                TYPE c,
    button_col5(20)                TYPE c,
    s_header                       TYPE kkblo_header,
    t_sfinfo_slave                 TYPE kkblo_t_sfinfo,
    t_suminfo                      TYPE kkblo_t_sfinfo,
    t_sfsave                       TYPE kkblo_t_sfinfo,
    t_nosum                        TYPE t_nosum,
    window_title                   TYPE rsmpe-tittext,  " Item_selection
    flg_scroll_to_line(1)          TYPE c, " Item_selection
    flg_top_of_page(1)             TYPE c,
    flg_subtot(1)                  TYPE c,
    flg_output_in_progress(1)      TYPE c,
    flg_grouplevels(1)             TYPE c,
    flg_groupedit(1)               TYPE c,
    flg_calculate_totals(1)        TYPE c,
    sumlevel                       TYPE sy-tabix,
    memory_stack1                  TYPE ty_memory,
    memory_stack2                  TYPE ty_memory,
    memory_outtab                  TYPE ty_memory,
    t_colmark                      TYPE kkblo_t_colmark,
    t_rowmark                      TYPE kkblo_t_rowmark,
    it_event_exit                  TYPE kkblo_t_event_exit,
    t_groups                       TYPE kkblo_t_grouplevels,
    t_filter_groups                TYPE kkblo_t_grouplevels,
    s_subtot_options               TYPE kkblo_subtot_options,
    flg_append_mode(1)             TYPE c,
    is_reprep_id                   TYPE kkblo_reprep_id,
    i_callback_before_line_output  TYPE kkblo_formname,
    i_callback_after_line_output   TYPE kkblo_formname,
    i_callback_foreign_top_of_page TYPE kkblo_formname,
    i_callback_foreign_end_of_page TYPE kkblo_formname,
    i_callback_list_modify         TYPE kkblo_formname,
    i_callback_top_of_coverpage    TYPE kkblo_formname,
    i_callback_end_of_coverpage    TYPE kkblo_formname,
    i_callback_grouplevel_change   TYPE kkblo_formname,
    i_callback_item_data_expand    TYPE kkblo_formname,
    i_callback_header_transport    TYPE kkblo_formname,
    i_callback_reprep_sel_modify   TYPE kkblo_formname,
    i_callback_subtotal_text       TYPE kkblo_formname,
    END OF ty_stack2.
    TYPES: t_stack2 TYPE TABLE OF ty_stack2 INITIAL SIZE 0.
    ** *--- iTables
    DATA: it_stack  TYPE t_stack WITH HEADER LINE.
    DATA: it_stack2 TYPE t_stack2 WITH HEADER LINE.
    ***ALV Customer Wrapper
    DATA: it_stack3 TYPE t_stack3 WITH HEADER LINE.
    CONSTANTS: BEGIN OF c_con_listtype,
    simple(1)    TYPE c VALUE 'S',
    hier_sequ(1) TYPE c VALUE 'H',
    matrix(1)    TYPE c VALUE 'M',
    END OF c_con_listtype.
    DATA:   gv_callback_program1      TYPE sy-repid,
    gv_callback_user_command1 TYPE kkblo_formname,
    gv_callback_top_of_page1  TYPE kkblo_formname,
    gv_callback_top_of_list1  TYPE kkblo_formname,
    gv_callback_end_of_page1  TYPE kkblo_formname,
    gv_callback_end_of_list1   TYPE kkblo_formname,
    gv_callback_pf_status_set1  TYPE kkblo_formname,
    gv_callback_layout_save1    TYPE kkblo_formname,
    gv_callback_fieldcat_save1  TYPE kkblo_formname,
    gv_callback_grouplevel_change1  TYPE kkblo_formname,
    gv_callback_before_line_otput1  TYPE kkblo_formname,
    gv_callback_after_line_otput1  TYPE kkblo_formname,
    gv_callback_foreign_top_of_pg1  TYPE kkblo_formname,
    gv_callback_foreign_end_of_pg1  TYPE kkblo_formname,
    gv_callback_list_modify1          TYPE kkblo_formname,
    gv_callback_top_of_coverpge1     TYPE kkblo_formname,
    gv_callback_end_of_coverpge1     TYPE kkblo_formname,
    gv_callback_item_data_expand1     TYPE kkblo_formname,
    gv_callback_header_transport1     TYPE kkblo_formname,
    gv_callback_reprep_sel_modify1    TYPE kkblo_formname,
    gv_callback_subtotal_text1       TYPE kkblo_formname,
    gv_layout1   TYPE  kkblo_layout,
    gv_fieldcat1  TYPE  kkblo_t_fieldcat,
    gv_fctype1  TYPE c,
    gv_event_exit1  TYPE  kkblo_t_event_exit,
    gv_excluding1   TYPE  kkblo_t_extab,
    gv_special_groups1  TYPE  kkblo_t_sp_group,
    gv_sort1  TYPE  kkblo_t_sortinfo,
    gv_filter1  TYPE  kkblo_t_filter,
    gv_except_qinfo1  TYPE  slis_t_qinfo_alv,
    gv_sel_hide1  TYPE  slis_sel_hide_alv,
    gv_reprep_id1   TYPE  slis_reprep_id,
    gv_screen_start_column1  TYPE i,
    gv_salv_adapter1   TYPE REF TO if_salv_adapter,
    gv_suppress_empty_data1  TYPE  sap_bool.
    FUNCTION z_excel_download_test.
    *"*"Local Interface:
    *"  IMPORTING
    *"     REFERENCE(I_BYPASSING_BUFFER) TYPE  CHAR01 OPTIONAL
    *"     REFERENCE(I_BUFFER_ACTIVE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_PROGRAM) TYPE  SY-REPID OPTIONAL
    *"     REFERENCE(I_CALLBACK_USER_COMMAND) OPTIONAL
    *"     REFERENCE(I_CALLBACK_TOP_OF_PAGE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_TOP_OF_LIST) OPTIONAL
    *"     REFERENCE(I_CALLBACK_END_OF_PAGE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_END_OF_LIST) OPTIONAL
    *"     REFERENCE(I_CALLBACK_PF_STATUS_SET) OPTIONAL
    *"     REFERENCE(I_CALLBACK_LAYOUT_SAVE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_FIELDCAT_SAVE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_GROUPLEVEL_CHANGE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_BEFORE_LINE_OUTPUT) OPTIONAL
    *"     REFERENCE(I_CALLBACK_AFTER_LINE_OUTPUT) OPTIONAL
    *"     REFERENCE(I_CALLBACK_FOREIGN_TOP_OF_PAGE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_FOREIGN_END_OF_PAGE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_LIST_MODIFY) OPTIONAL
    *"     REFERENCE(I_CALLBACK_TOP_OF_COVERPAGE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_ITEM_DATA_EXPAND) OPTIONAL
    *"     REFERENCE(I_CALLBACK_END_OF_COVERPAGE) OPTIONAL
    *"     REFERENCE(I_CALLBACK_HEADER_TRANSPORT) OPTIONAL
    *"     REFERENCE(I_CALLBACK_REPREP_SEL_MODIFY) OPTIONAL
    *"     REFERENCE(I_CALLBACK_SUBTOTAL_TEXT) OPTIONAL
    *"     REFERENCE(I_TABNAME) TYPE  SLIS_TABNAME OPTIONAL
    *"     REFERENCE(I_FCTYPE) DEFAULT 'R'
    *"     REFERENCE(IT_EXCEPT_QINFO) TYPE  SLIS_T_QINFO_ALV OPTIONAL
    *"     REFERENCE(IS_SEL_HIDE) TYPE  SLIS_SEL_HIDE_ALV OPTIONAL
    *"     REFERENCE(IS_REPREP_ID) TYPE  SLIS_REPREP_ID OPTIONAL
    *"     REFERENCE(I_SCREEN_START_COLUMN) DEFAULT 0
    *"     REFERENCE(I_OO_ALV) OPTIONAL
    *"     REFERENCE(IR_SALV_ADAPTER) TYPE REF TO  IF_SALV_ADAPTER OPTIONAL
    *"     REFERENCE(I_SUPPRESS_EMPTY_DATA) TYPE  SAP_BOOL DEFAULT
    *"       ABAP_FALSE
    *"     REFERENCE(I_FILE) TYPE  STRING OPTIONAL
    *"     REFERENCE(IT_FIELDCAT) TYPE  SLIS_T_FIELDCAT_ALV OPTIONAL
    *"     REFERENCE(IS_LAYOUT) TYPE  SLIS_LAYOUT_ALV OPTIONAL
    *"     REFERENCE(IT_SORT) TYPE  SLIS_T_SORTINFO_ALV OPTIONAL
    *"     REFERENCE(IT_FILTER) TYPE  SLIS_T_FILTER_ALV OPTIONAL
    *"     REFERENCE(IT_EXCLUDING) TYPE  SLIS_T_EXTAB OPTIONAL
    *"     REFERENCE(IT_SPECIAL_GROUPS) TYPE  SLIS_T_SP_GROUP_ALV OPTIONAL
    *"     REFERENCE(IS_KEYINFO) TYPE  SLIS_KEYINFO_ALV OPTIONAL
    *"     REFERENCE(IT_EVENT_EXIT) TYPE  SLIS_T_EVENT_EXIT OPTIONAL
    *"     REFERENCE(IS_LIST_SCROLL) TYPE  SLIS_LIST_SCROLL OPTIONAL
    *"     REFERENCE(IS_PRINT) TYPE  SLIS_PRINT_ALV OPTIONAL
    *"     REFERENCE(IS_LINEINFO) TYPE  SLIS_LINEINFO OPTIONAL
    *"     REFERENCE(I_REPID) TYPE  SYREPID OPTIONAL
    *"  TABLES
    *"      T_OUTTAB TYPE  STANDARD TABLE OPTIONAL
    *********** Local data declarations******************
    DATA: gv_list TYPE char1.
    DATA: gv_fcat_complete TYPE sap_bool.
    DATA: gv_buffer_active TYPE char01,
    wa_variant TYPE disvariant.
    DATA: gv_controller TYPE REF TO cl_salv_export_c8r.
    DATA: gv_xml           TYPE xstring.
    DATA: gv_s_xml_choice TYPE if_salv_bs_xml=>s_type_xml_choice.
    DATA: gv_t_xml_choice TYPE if_salv_bs_xml=>t_type_xml_choice.
    DATA: gv_param_lvc TYPE if_salv_export=>s_type_param_lvc.
    DATA: gv_data       TYPE REF TO data.
    DATA: gv_result_data TYPE REF TO cl_salv_ex_result_data_table.
    DATA: gv_flavour TYPE string.
    DATA: gv_version TYPE string.
    DATA:

Maybe you are looking for